fix for intel devices torch compile configs by leizhenyuan · Pull Request #3952 · unslothai/unsloth · GitHub
Skip to content

fix for intel devices torch compile configs - #3952

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
leizhenyuan:zhenyuan_fix_intel_devices
Feb 3, 2026
Merged

fix for intel devices torch compile configs#3952
danielhanchen merged 3 commits into
unslothai:mainfrom
leizhenyuan:zhenyuan_fix_intel_devices

Conversation

@leizhenyuan

Copy link
Copy Markdown
Contributor

fix for intel devices torch compile configs

@gemini-code-assist

Copy link
Copy Markdown
Contributor

@leizhenyuan

Copy link
Copy Markdown
Contributor Author

Pls note, this pr rely on unslothai/unsloth-zoo#451

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces fixes for torch.compile configurations on Intel devices (XPU) by making the options device-specific. The changes correctly abstract away device-specific calls like torch.cuda.synchronize() to a generic device_synchronize() function. My main feedback is to refactor a small piece of duplicated code where compile options for 'xpu' and the default case are identical. Consolidating this will improve code clarity and maintainability. Otherwise, the changes look good.

Comment thread unsloth/models/rl.py Outdated
Comment on lines +1110 to +1125
elif DEVICE_TYPE == "xpu":
# XPU-specific torch_compile_options (disable CUDA-specific options)
new_options = """torch_compile_options = {
"epilogue_fusion" : True,
"max_autotune" : False,
"shape_padding" : True,
"trace.enabled" : False,
}"""
else:
# Default options for other device types (hip, etc.)
new_options = """torch_compile_options = {
"epilogue_fusion" : True,
"max_autotune" : False,
"shape_padding" : True,
"trace.enabled" : False,
}"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The torch_compile_options for xpu and the default else case are identical. You can combine these blocks to reduce code duplication and improve maintainability.

        else:
            # Default options for other device types (xpu, hip, etc.)
            new_options = """torch_compile_options = {
            "epilogue_fusion"   : True,
            "max_autotune"      : False,
            "shape_padding"     : True,
            "trace.enabled"     : False,
        }"""

Comment thread unsloth/models/rl.py Outdated

if RLTrainer_name == "GRPOTrainer":
new_options = """torch_compile_options = {
# Generate torch_compile_options based on device type

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Isn't it simpler if we have base compile_options and then add on top of them?
Because I see all the 3 backends have same configs.

danielhanchen and others added 2 commits February 3, 2026 05:09
…ic extensions

- Extract common options into base_options shared by all device types
- CUDA devices get additional CUDA-specific options
- XPU, HIP, and other devices use base options only
- Reduces code duplication and improves maintainability
@danielhanchen

Copy link
Copy Markdown
Member

@danielhanchen
danielhanchen merged commit 8f33ec5 into unslothai:main Feb 3, 2026
1 check passed
abiswas-realadvice pushed a commit to abiswas-realadvice/unsloth that referenced this pull request May 14, 2026
* fix for intel devices

* Refactor torch_compile_options to use base options with device-specific extensions

- Extract common options into base_options shared by all device types
- CUDA devices get additional CUDA-specific options
- XPU, HIP, and other devices use base options only
- Reduces code duplication and improves maintainability

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: danielhanchen <danielhanchen@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants