Skip to content

Fix cutlass inductor options for PyTorch < 2.8.0#3988

Merged
danielhanchen merged 1 commit into
mainfrom
fix/pytorch-version-guard-cutlass-options
Feb 5, 2026
Merged

Fix cutlass inductor options for PyTorch < 2.8.0#3988
danielhanchen merged 1 commit into
mainfrom
fix/pytorch-version-guard-cutlass-options

Conversation

@danielhanchen
Copy link
Copy Markdown
Member

Summary

  • Add PyTorch version detection to guard cutlass-specific inductor config options
  • The cuda.cutlass_epilogue_fusion_enabled and cuda.cutlass_tma_only options were added in PyTorch 2.8.0
  • Without this fix, GRPOTrainer fails to initialize on PyTorch < 2.8.0 with: RuntimeError: Unexpected optimization option cuda.cutlass_epilogue_fusion_enabled

Changes

  • Added torch_version variable for PyTorch version detection
  • Wrapped cutlass options in a version check (torch_version >= Version("2.8.0"))

Test plan

  • Test GRPO notebook on Colab with PyTorch < 2.8.0
  • Test GRPO notebook on environment with PyTorch >= 2.8.0

The cuda.cutlass_epilogue_fusion_enabled and cuda.cutlass_tma_only
inductor config options were added in PyTorch 2.8.0. Using these
options on older PyTorch versions causes a RuntimeError during
GRPOTrainer initialization.

This fix adds a version check to only include these options when
running PyTorch 2.8.0 or later, allowing GRPO training to work on
older PyTorch versions (e.g., Colab environments with PyTorch 2.5-2.7).
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @danielhanchen, 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 addresses a critical compatibility issue preventing GRPOTrainer from initializing correctly on PyTorch versions prior to 2.8.0. By introducing PyTorch version detection, it ensures that specific cutlass inductor configuration options, which were added in PyTorch 2.8.0, are only enabled when running on compatible PyTorch versions. This change prevents runtime errors and enhances the robustness of the training setup across different PyTorch environments.

Highlights

  • PyTorch Version Detection: Implemented logic to detect the installed PyTorch version, parsing it from torch.__version__ to enable feature-specific checks.
  • Conditional Cutlass Inductor Options: Wrapped cuda.cutlass_epilogue_fusion_enabled and cuda.cutlass_tma_only inductor options within a version check, ensuring they are only applied when PyTorch is version 2.8.0 or newer.
  • GRPOTrainer Compatibility Fix: Resolved an issue where GRPOTrainer would fail to initialize on PyTorch versions older than 2.8.0 due to unrecognized cutlass options, improving backward compatibility.

🧠 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.

Changelog
  • unsloth/models/rl.py
    • Added a torch_version variable to parse and store the current PyTorch version, handling various version string formats.
    • Modified the _patch_trl_rl_trainers function to conditionally include cuda.cutlass_epilogue_fusion_enabled and cuda.cutlass_tma_only options only if the detected torch_version is 2.8.0 or greater.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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.

@danielhanchen danielhanchen merged commit 43ae494 into main Feb 5, 2026
4 checks passed
@danielhanchen danielhanchen deleted the fix/pytorch-version-guard-cutlass-options branch February 5, 2026 14:40
Copy link
Copy Markdown
Contributor

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

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 correctly adds a version check for PyTorch to conditionally include cutlass-specific inductor options, which is a great fix to support older PyTorch versions. I've identified a couple of areas for improvement. Firstly, the PyTorch version parsing could be made more robust to handle different version string formats. Secondly, there's a critical bug in how the cuda_options string is constructed, which would lead to a SyntaxError. My review includes suggestions to address both of these points.

Comment thread unsloth/models/rl.py
Comment on lines +1135 to 1145
cuda_options = """
"triton.enable_persistent_tma_matmul": torch.cuda.get_device_capability()[0] >= 9,"""
# cutlass options were added in PyTorch 2.8.0
if torch_version >= Version("2.8.0"):
cuda_options += """
"cuda.cutlass_epilogue_fusion_enabled": torch.cuda.get_device_capability()[0] >= 9,
"cuda.cutlass_tma_only": torch.cuda.get_device_capability()[0] >= 9,
"cuda.cutlass_tma_only": torch.cuda.get_device_capability()[0] >= 9,"""
cuda_options += """
"cuda.compile_opt_level" : "-O2",
"cuda.enable_cuda_lto" : True,
}"""
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.

critical

The way the cuda_options string is constructed introduces a syntax error. There's a trailing comma after "cuda.enable_cuda_lto": True, which is the last item in the dictionary being constructed. This will cause a SyntaxError when the string is evaluated as Python code.

I've provided a suggestion that fixes this bug by removing the comma and also makes the string construction slightly more readable by combining the unconditional string additions.

Suggested change
cuda_options = """
"triton.enable_persistent_tma_matmul": torch.cuda.get_device_capability()[0] >= 9,"""
# cutlass options were added in PyTorch 2.8.0
if torch_version >= Version("2.8.0"):
cuda_options += """
"cuda.cutlass_epilogue_fusion_enabled": torch.cuda.get_device_capability()[0] >= 9,
"cuda.cutlass_tma_only": torch.cuda.get_device_capability()[0] >= 9,
"cuda.cutlass_tma_only": torch.cuda.get_device_capability()[0] >= 9,"""
cuda_options += """
"cuda.compile_opt_level" : "-O2",
"cuda.enable_cuda_lto" : True,
}"""
cuda_options = '''
"triton.enable_persistent_tma_matmul": torch.cuda.get_device_capability()[0] >= 9,'''
# cutlass options were added in PyTorch 2.8.0
if torch_version >= Version("2.8.0"):
cuda_options += '''
"cuda.cutlass_epilogue_fusion_enabled": torch.cuda.get_device_capability()[0] >= 9,
"cuda.cutlass_tma_only": torch.cuda.get_device_capability()[0] >= 9,'''
cuda_options += '''
"cuda.compile_opt_level" : "-O2",
"cuda.enable_cuda_lto" : True
}'''

Comment thread unsloth/models/rl.py

# Get PyTorch version for feature detection
try:
torch_version = Version(torch.__version__.split("+")[0].split("a")[0].split("b")[0])
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 current method of parsing the PyTorch version string is a bit fragile. It handles a and b for alpha/beta releases, but it doesn't handle dev releases correctly. For example, a version like 2.8.0.dev20240715 would not be stripped down, and Version('2.8.0.dev...') is considered less than Version('2.8.0'), which might not be the intended behavior if dev releases should already include the new features.

A more robust approach would be to use a regular expression to extract just the base X.Y.Z version string. This would handle a wider variety of version formats gracefully.

Suggested change
torch_version = Version(torch.__version__.split("+")[0].split("a")[0].split("b")[0])
torch_version = Version(re.match(r"^\d+\.\d+\.\d+", torch.__version__).group(0))

abiswas-realadvice pushed a commit to abiswas-realadvice/unsloth that referenced this pull request May 14, 2026
The cuda.cutlass_epilogue_fusion_enabled and cuda.cutlass_tma_only
inductor config options were added in PyTorch 2.8.0. Using these
options on older PyTorch versions causes a RuntimeError during
GRPOTrainer initialization.

This fix adds a version check to only include these options when
running PyTorch 2.8.0 or later, allowing GRPO training to work on
older PyTorch versions (e.g., Colab environments with PyTorch 2.5-2.7).

Co-authored-by: Daniel Hanchen <danielhanchen@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.

1 participant