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
Update llama.py
Daniel Han643637dd5ef9
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.pyindex fe0627f8d7e..7070919903e 100644--- a/unsloth/models/llama.py+++ b/unsloth/models/llama.py@@ -18,6 +18,7 @@ import mathfrom functools import partialfrom typing import Optional, Tuple, List, Unionfrom ._utils import *+from ._utils import patch_unsloth_smart_gradient_checkpointingfrom ._utils import __version__from torch.nn.functional import scaled_dot_product_attentionfrom transformers import __version__ as transformers_version@@ -850,27 +851,14 @@ def LlamaModel_fast_forward(mask = self. GA_mask if use_static_mask else dynamic_GA_maskpass- if offloaded_gradient_checkpointing:- hidden_states = Unsloth_Offloaded_Gradient_Checkpointer.apply(- decoder_layer,- hidden_states,- mask,- attention_mask,- position_ids,- past_key_values,- output_attentions,- use_cache,- None,- position_embeddings,- )[0]-- elif gradient_checkpointing:+ if gradient_checkpointing:def create_custom_forward(module):def custom_forward(*inputs):return module(*inputs, past_key_value, output_attentions, padding_mask = padding_mask, position_embeddings = position_embeddings)return custom_forwardpass+ print(torch.utils.checkpoint.checkpoint)layer_outputs = torch.utils.checkpoint.checkpoint(create_custom_forward(decoder_layer),hidden_states,@@ -2034,6 +2022,9 @@ class FastLlamaModel:):transformers_set_seed(random_state)+ if use_gradient_checkpointing == "unsloth":+ patch_unsloth_smart_gradient_checkpointing(dtype = model.get_input_embeddings().weight.dtype)+if type(r) is not int:raise TypeError(f"Unsloth: Rank of {str(r)} must be an integer.")if r <= 0: