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

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

Summary of Changes

Hello @leizhenyuan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the hardware compatibility and performance of Unsloth's reinforcement learning trainers. By introducing device-aware torch_compile_options and generalizing device synchronization, it ensures that the training process can leverage optimal configurations on various devices, including Intel XPUs, without being tied to CUDA-specific implementations.

Highlights

  • Device-Agnostic Torch Compile Options: The torch_compile_options for GRPOTrainer are now dynamically set based on the detected DEVICE_TYPE, allowing for optimized configurations across different hardware.
  • Intel XPU Support: Specific torch_compile_options have been introduced for Intel XPU devices, disabling CUDA-specific settings and ensuring proper compilation on these platforms.
  • Generalized Device Synchronization: The torch.cuda.synchronize() call has been replaced with a device-agnostic device_synchronize() function, improving compatibility beyond CUDA-only environments.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@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
Contributor

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

Thanks so much!

@danielhanchen
danielhanchen merged commit 8f33ec5 into unslothai:main Feb 3, 2026
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 <[email protected]>
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