From 1cc2948425c3cc46d536041b51c224f6097a3aa0 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Thu, 5 Feb 2026 06:40:11 -0800 Subject: [PATCH] Fix cutlass inductor options for PyTorch < 2.8.0 (#3988) 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 --- unsloth/models/rl.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index eacfecc6c3..7d512bff1a 100755 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -70,6 +70,12 @@ except Exception: except Exception: trl_version = Version("0.0.0") +# Get PyTorch version for feature detection +try: + torch_version = Version(torch.__version__.split("+")[0].split("a")[0].split("b")[0]) +except Exception: + torch_version = Version("0.0.0") + def vLLMSamplingParams(**kwargs): from vllm import SamplingParams @@ -1126,16 +1132,18 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"): # Generate torch_compile_options based on device type if DEVICE_TYPE == "cuda": # CUDA-specific options (added to base options) - new_options = ( - base_options - + """ - "triton.enable_persistent_tma_matmul": torch.cuda.get_device_capability()[0] >= 9, + 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, }""" - ) + new_options = base_options + cuda_options else: # XPU, HIP, and other device types use base options only new_options = (