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
improve qat (#3446)
Etherll3d73aebec8df
diff --git a/unsloth/models/vision.py b/unsloth/models/vision.pyindex a5296052cf9..20531d152c4 100644--- a/unsloth/models/vision.py+++ b/unsloth/models/vision.py@@ -28,7 +28,7 @@ passfrom ..kernels import (post_patch_loss_function,)-from ._utils import __version__, importlib_version+from ._utils import __version__, importlib_version, _prepare_model_for_qatfrom ._utils import *from ..save import patch_saving_functionsfrom peft import LoraConfig, TaskType, get_peft_model as _get_peft_model@@ -796,6 +796,7 @@ class FastBaseModel:loftq_config = {},task_type = TaskType.CAUSAL_LM,temporary_location = "_unsloth_temporary_saved_buffers",+ qat_scheme = None,**kwargs):if os.environ.get("UNSLOTH_ENABLE_FULL_FINETUNING", "0") == "1":@@ -871,6 +872,11 @@ class FastBaseModel:use_gradient_checkpointing = use_gradient_checkpointing,)model = _get_peft_model(model, lora_config)+ # Apply QAT + LoRA if specified+ if qat_scheme is not None:+ print("Unsloth: Applying QAT to mitigate quantization degradation")+ model = _prepare_model_for_qat(model, qat_scheme)+ pass# Fix LoraConfig.auto_mapping is Nonefix_lora_auto_mapping(model)# Enable gradients on modules which are trainablediff --git a/unsloth/save.py b/unsloth/save.pyindex b148608f6d5..aeac2bab711 100644--- a/unsloth/save.py+++ b/unsloth/save.py@@ -44,6 +44,7 @@ except:passpassfrom pathlib import Path+from peft import PeftModelForCausalLM, PeftModel__all__ = ["print_quantization_methods",@@ -2522,7 +2523,12 @@ def unsloth_save_pretrained_torchao(arguments["save_method"] = "merged_16bit" # Must be 16bitdel arguments["self"]del arguments["torchao_config"]- unsloth_generic_save(**arguments)++ if not isinstance(self, PeftModelForCausalLM) and not isinstance(self, PeftModel):+ self.save_pretrained(save_directory)+ tokenizer.save_pretrained(save_directory)+ else:+ unsloth_generic_save(**arguments)for _ in range(3):gc.collect()