Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Complete disable `gradient_checkpointing` for vision when `use_gradient_checkpointing=False`
Duc-Viet Hoang432864cb25f1
diff --git a/unsloth/models/rl.py b/unsloth/models/rl.pyindex e945a80354d..9ec4d76ed33 100644--- a/unsloth/models/rl.py+++ b/unsloth/models/rl.py@@ -264,17 +264,19 @@ def prepare_for_training_mode(f):def wrapper(self, *args, **kwargs):# Enable training mode_was_training = None+ # Get gradient checkpointing setting from training arguments+ use_gc = getattr(self.args, 'gradient_checkpointing', True)if hasattr(self, 'model') and hasattr(self.model, "training"):_was_training = self.model.trainingif hasattr(self, 'model') and hasattr(self.model, "for_training"):- self.model.for_training()+ self.model.for_training(use_gradient_checkpointing=use_gc)output = f(self, *args, **kwargs)# Restore previous mode when possibleif hasattr(self, 'model') and hasattr(self.model, "for_inference"):if _was_training is False:self.model.for_inference()elif _was_training is True and hasattr(self.model, "for_training"):- self.model.for_training()+ self.model.for_training(use_gradient_checkpointing=use_gc)# Reset gradient checkpointing buffers to free memory while staying ready for next runtry:reset_unsloth_gradient_checkpointing_buffers()diff --git a/unsloth/models/vision.py b/unsloth/models/vision.pyindex 6de942d7d23..4e03e0a1689 100644--- a/unsloth/models/vision.py+++ b/unsloth/models/vision.py@@ -1273,7 +1273,7 @@ class FastBaseModel:# Since transformers 4.53, must turn on explicitlyfor module in model.modules():if hasattr(module, "gradient_checkpointing"):- module.gradient_checkpointing = True+ module.gradient_checkpointing = use_gradient_checkpointing# Also re-enable training for embeddings for NEFTuneif hasattr(model, "get_input_embeddings"):