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
Do not print the 16bit LoRA notice when a quantization_config still quantizes (#12848)
Daniel Han333ad5c9a2ae
diff --git a/tests/test_qlora_notice_with_quantization_config.py b/tests/test_qlora_notice_with_quantization_config.pynew file mode 100644index 00000000000..3e5b0bdf60f--- /dev/null+++ b/tests/test_qlora_notice_with_quantization_config.py@@ -0,0 +1,60 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.++"""FastModel passes load_in_4bit = False with a quantization_config that still quantizes: no 16bit notice then."""++import subprocess+import sys+import textwrap++import pytest+import torch++pytestmark = pytest.mark.skipif(not torch.cuda.is_available(), reason = "bitsandbytes needs a GPU")++NOTICE = "Switching to 16bit LoRA"++SCRIPT = textwrap.dedent(+ """+ import sys+ from unsloth import FastModel+ import bitsandbytes as bnb+ import torch+ from transformers import BitsAndBytesConfig++ kwargs = dict(max_seq_length = 128, load_in_4bit = False)+ if sys.argv[1] == "config":+ kwargs["quantization_config"] = BitsAndBytesConfig(+ load_in_4bit = True,+ bnb_4bit_quant_type = "nf4",+ bnb_4bit_compute_dtype = torch.bfloat16,+ )+ model, _ = FastModel.from_pretrained("trl-internal-testing/tiny-Qwen3ForCausalLM", **kwargs)+ n = sum(isinstance(m, bnb.nn.Linear4bit) for m in model.modules())+ print("LINEAR4BIT", n)+ """+)+++def _load(mode):+ out = subprocess.run(+ [sys.executable, "-c", SCRIPT, mode],+ capture_output = True,+ text = True,+ timeout = 900,+ )+ assert out.returncode == 0, out.stdout[-2000:] + out.stderr[-4000:]+ count = int(out.stdout.split("LINEAR4BIT")[-1].split()[0])+ return out.stdout + out.stderr, count+++def test_an_explicit_4bit_config_loads_4bit_without_the_16bit_notice():+ log, n_4bit = _load("config")+ assert n_4bit > 0+ assert NOTICE not in log+++def test_a_plain_16bit_load_still_prints_the_notice():+ log, n_4bit = _load("plain")+ assert n_4bit == 0+ assert NOTICE in logdiff --git a/unsloth/models/vision.py b/unsloth/models/vision.pyindex 712061be3f3..2f3082321c9 100644--- a/unsloth/models/vision.py+++ b/unsloth/models/vision.py@@ -3377,7 +3377,11 @@ class FastBaseModel:elif load_in_16bit:bnb_config = Noneelif not load_in_4bit and not load_in_8bit and not full_finetuning:- print("Unsloth: QLoRA and full finetuning all not selected. Switching to 16bit LoRA.")+ # FastModel passes load_in_4bit = False with a quantization_config, which still quantizes.+ if user_quantization_config is None:+ print(+ "Unsloth: QLoRA and full finetuning all not selected. Switching to 16bit LoRA."+ )if full_finetuning:os.environ["UNSLOTH_ENABLE_FULL_FINETUNING"] = "1"