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
Torch dtype (#314)
Daniel Han6a53964f6b23
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.pyindex 876ccb25a4c..0b8092eaaca 100644--- a/unsloth/models/llama.py+++ b/unsloth/models/llama.py@@ -1702,6 +1702,11 @@ class FastLlamaModel:lm_head = internal_model.lm_head.weightdevice_type = lm_head.device.typedtype = model.config.torch_dtype++ if type(dtype) is str:+ if dtype == "float16": dtype = torch.float16+ elif dtype == "bfloat16": dtype = torch.bfloat16+ pass# Wrap model.generatemodel._unwrapped_old_generate = model.generatediff --git a/unsloth/save.py b/unsloth/save.pyindex d1cd7d6361f..d0010321b11 100644--- a/unsloth/save.py+++ b/unsloth/save.py@@ -183,7 +183,7 @@ def unsloth_save_model():if token is None and "HF_TOKEN" in os.environ:token = os.environ["HF_TOKEN"]-+if token is None and "HUGGINGFACE_TOKEN" in os.environ:token = os.environ["HUGGINGFACE_TOKEN"]@@ -489,7 +489,12 @@ def unsloth_save_model(from collections import OrderedDictstate_dict = OrderedDict()- torch_dtype = model.config.torch_dtype+ torch_dtype = internal_model.config.torch_dtype+ if type(torch_dtype) is str:+ if torch_dtype == "float16": torch_dtype = torch.float16+ elif torch_dtype == "bfloat16": torch_dtype = torch.bfloat16+ pass+# Check modules to save float32 dtypestate_dict["model.embed_tokens.weight"] = internal_model.model.embed_tokens.weight.data.to(torch_dtype)