Skip to content

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.

Honor explicit load_in_16bit for local -bf16 directories (#6726)

Daniel Han95a73f0f5159
diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py
index 2818b6ee80d..9ce74c4d027 100644
--- a/unsloth/models/loader.py
+++ b/unsloth/models/loader.py
@@ -466,8 +466,10 @@ class FastLanguageModel(FastLlamaModel):
("-unsloth-bnb-4bit", "-bnb-4bit")
):
model_name = _strip_unsloth_bnb_4bit_suffix(model_name)
- # Change -BF16 to all False for 4bit, 8bit etc
- if model_name.lower().endswith("-bf16"):
+ # '-bf16' hub repos load bf16; a local dir keeps the requested quant unless 16bit is set
+ if model_name.lower().endswith("-bf16") and (
+ load_in_16bit or not os.path.isdir(os.path.expanduser(model_name))
+ ):
load_in_4bit = False
load_in_8bit = False
load_in_fp8 = False
@@ -625,8 +627,10 @@ class FastLanguageModel(FastLlamaModel):
("-unsloth-bnb-4bit", "-bnb-4bit")
):
model_name = _strip_unsloth_bnb_4bit_suffix(model_name)
- # Change -BF16 to all False for 4bit, 8bit etc
- if model_name.lower().endswith("-bf16"):
+ # '-bf16' hub repos load bf16; a local dir keeps the requested quant unless 16bit is set
+ if model_name.lower().endswith("-bf16") and (
+ load_in_16bit or not os.path.isdir(os.path.expanduser(model_name))
+ ):
load_in_4bit = False
load_in_8bit = False
load_in_fp8 = False
@@ -1145,8 +1149,10 @@ class FastModel(FastBaseModel):
("-unsloth-bnb-4bit", "-bnb-4bit")
):
model_name = _strip_unsloth_bnb_4bit_suffix(model_name)
- # Change -BF16 to all False for 4bit, 8bit etc
- if model_name.lower().endswith("-bf16"):
+ # '-bf16' hub repos load bf16; a local dir keeps the requested quant unless 16bit is set
+ if model_name.lower().endswith("-bf16") and (
+ load_in_16bit or not os.path.isdir(os.path.expanduser(model_name))
+ ):
load_in_4bit = False
load_in_8bit = False
load_in_fp8 = False
@@ -1503,8 +1509,10 @@ class FastModel(FastBaseModel):
("-unsloth-bnb-4bit", "-bnb-4bit")
):
model_name = _strip_unsloth_bnb_4bit_suffix(model_name)
- # Change -BF16 to all False for 4bit, 8bit etc
- if model_name.lower().endswith("-bf16"):
+ # '-bf16' hub repos load bf16; a local dir keeps the requested quant unless 16bit is set
+ if model_name.lower().endswith("-bf16") and (
+ load_in_16bit or not os.path.isdir(os.path.expanduser(model_name))
+ ):
load_in_4bit = False
load_in_8bit = False
load_in_fp8 = False