From 356538d760e916261763be1aed37beaa54fd071f Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Mon, 16 Mar 2026 10:17:15 +0000 Subject: [PATCH] Apply use_reentrant removal to all TRL trainer configs, not just GRPO The existing fix that removes use_reentrant=False from gradient_checkpointing_kwargs was gated behind RLConfig_name == "GRPOConfig", so only GRPOConfig was protected. SFTConfig, DPOConfig, KTOConfig, CPOConfig, ORPOConfig etc. were all still affected. Remove the GRPOConfig guard so the fix applies to all compiled trainer configs when TRL >= 0.27.0. This is defense-in-depth alongside the unsloth_zoo fix that forces use_reentrant=True in unsloth_checkpoint() itself. --- unsloth/models/rl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index 30546a048d..5c61a6eae2 100755 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -1232,7 +1232,7 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"): # Unsloth gradient checkpointing requires use_reentrant=True, so we remove # the setting after super().__init__() when it gets auto-applied. RLConfig_post = "" - if trl_version >= Version("0.27.0") and RLConfig_name == "GRPOConfig": + if trl_version >= Version("0.27.0"): RLConfig_post = ( " # Unsloth: Remove use_reentrant=False forced by TRL 0.27.0+\n" " if getattr(self, 'gradient_checkpointing_kwargs', None) is not None:\n"