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
Forward hook
Daniel Hana184f38f7ab6
diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.pyindex 22aa4d3d807..72994fa623b 100644--- a/unsloth/models/_utils.py+++ b/unsloth/models/_utils.py@@ -467,13 +467,13 @@ def prepare_model_for_kbit_training(pass# If use_reentrant = True which is the Pytorch default, we just make the input requires_grad.- if use_reentrant:- if hasattr(model, "enable_input_require_grads"):- model.enable_input_require_grads()- else:- def make_inputs_require_grad(module, input, output):- output.requires_grad_(True)- model.get_input_embeddings().register_forward_hook(make_inputs_require_grad)+ # if use_reentrant:+ # if hasattr(model, "enable_input_require_grads"):+ # model.enable_input_require_grads()+ # else:+ # def make_inputs_require_grad(module, input, output):+ # output.requires_grad_(True)+ # model.get_input_embeddings().register_forward_hook(make_inputs_require_grad)return modelpassdiff --git a/unsloth/models/llama.py b/unsloth/models/llama.pyindex c8bf5f8894a..61857431b9c 100644--- a/unsloth/models/llama.py+++ b/unsloth/models/llama.py@@ -606,6 +606,7 @@ def LlamaModel_fast_forward(# Embed positionsif inputs_embeds is None:inputs_embeds = self.embed_tokens(input_ids)+ inputs_embeds.requires_grad_(True)# inputs_embeds = inputs_embeds.to(self.config.torch_dtype)torch_dtype = __DTYPE_MAP.get(self.config.torch_dtype, None)