You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Unsloth Studio: Local safetensors model loads in full precision (high VRAM) instead of 4-bit QLoRA, but loading via GGUF ID works correctly #5344
Describe the bug
When I load a local safetensors model directly from disk using QLoRA (4-bit) method in Unsloth Studio, the model appears to load in full BF16/FP16 precision, consuming ~15.7 GB VRAM (near the original model size). This prevents training due to OOM. However, previously when I specified a GGUF model ID (e.g., from Hugging Face), Unsloth Studio automatically downloaded the corresponding safetensors and loaded it in 4‑bit correctly (low VRAM).
To Reproduce
Have a local folder containing a complete safetensors model (sharded .safetensors files, config.json, tokenizer files, etc.).
Open Unsloth Studio.
In the model selection, choose Local Model and point to that folder.
Set Method to QLoRA (4-bit).
Observe GPU memory usage after loading (e.g., via Task Manager or nvidia-smi).
Expected behavior
The model should be loaded in 4‑bit quantized form, using significantly less VRAM (like ~5-6 GB for a 7B model), allowing training with QLoRA.
Actual behavior
VRAM usage is ~15.7 GB (close to the BF16 model size), indicating 4‑bit loading did not take effect.
Installation method: (e.g., direct download / winget / source)
Possible cause
When a GGUF ID is used, Unsloth Studio internally triggers a proper 4‑bit loading pipeline (e.g., load_in_4bit=True). When a local path is given, it may fall back to a simple from_pretrained without the 4‑bit flag.
Request
Please advise if there is a configuration file change or a hidden option to force 4‑bit loading for local safetensors, or fix this behavior so that QLoRA (4-bit) method always respects 4‑bit loading regardless of model source (local vs HF ID).
@tiegangwang what is the model if you don't mind or what is the base model in this case? (llama3.2 ? gemma3? etc)
also GGUF cannot be trained so that is not relevant here.
Hi, I've been having a similar issue for the last few days on a similar setup - maybe I can post it here.
I've been unable to load the full version of gemma-4-e2b in Unsloth Studio (2026.5.2 version as well), Windows 11 on my RTX 4060 (8GB VRAM) despite the tooltip suggesting only 6 GB should be enough for just loading the full model to chat - see the screen attached:
🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
W0509 13:46:51.803000 17412 Lib\site-packages\torch\distributed\elastic\multiprocessing\redirects.py:29] NOTE: Redirects are currently not supported in Windows or MacOs.
Unsloth: Your Flash Attention 2 installation seems to be broken. Using Xformers instead. No performance changes will be seen.
🦥 Unsloth Zoo will now patch everything to make training faster!
==((====))== Unsloth 2026.5.2: Fast Gemma4 patching. Transformers: 5.5.0.
\\ /| NVIDIA GeForce RTX 4060 Laptop GPU. Num GPUs = 1. Max memory: 7.996 GB. Platform: Windows.
O^O/ \_/ \ Torch: 2.10.0+cu130. CUDA: 8.9. CUDA Toolkit: 13.0. Triton: 3.6.0
\ / Bfloat16 = TRUE. FA [Xformers = None. FA2 = False]
"-____-" Free license: http://github.com/unslothai/unsloth
Unsloth: Fast downloading is enabled - ignore downloading bars which are red colored!
Loading weights: 100%|███████████████████████████████████████████████████████████████████████| 2011/2011 [00:07<00:00, 270.66it/s]
generation_config.json: 100%|████████████████████████████████████████████████████████████████████| 203/203 [00:00<00:00, 1.14MB/s]
processor_config.json: 1.69kB [00:00, 7.45MB/s]
chat_template.jinja: 16.8kB [00:00, 41.4MB/s]
tokenizer_config.json: 19.9kB [00:00, 30.4MB/s]
tokenizer.json: 100%|████████████████████████████████████████████████████████████████████████| 32.2M/32.2M [00:02<00:00, 10.7MB/s]
Model loaded successfully!
It ran fine once when I trained it on a small dataset (yahma/alpaca-cleaned), when I try any bigger dataset around 1 GB - e.g. unsloth/LaTeX_OCR it gets over system RAM(?) and crashes with no specific error/no info in logs - see the screen below:
I've had a similar issue, but with the regular unsloth python api inside Jupyter notebooks. I am specifying to load in 4 bit with gemma-4-26B-A4B results in 50gb of vram usage which is eerily similar to the full precision model size which is 51gb. (It should be using ~16-20 gb in 4 bit), I specify to load in 4 bit and or 8 bit and it still uses 50gb of vram. This seems like a underlying issue where it is ignoring when you specify load in 4 bit / 8 bit. I'm currently experimenting with passing pre-quantized models to see if the issue resolves.
If your wondering what I'm under its
NVIDIA-SMI 595.58.03 Driver Version: 595.58.03 CUDA Version: 13.2
Ubuntu 25
torch 2.11.0
unsloth 2026.5.2
unsloth-zoo 2026.5.1
With dual blackwell gpus.
Edit: Using a pre-quantized model doesn't seem to fix the full precision loading issue.
Thanks all for the reports. Some notes after digging into this, plus two PRs.
What I found
The thread bundles two different mechanisms that happen to look the same on a VRAM meter.
Mechanism A: Gemma-4 MoE fused experts are not bitsandbytes-quantizable.
Reproduced on unsloth/gemma-4-26B-A4B-it (B200, transformers 5.5.0, torch 2.9.1, single GPU): load_in_4bit=True yields ~46 GB resident VRAM. Walking named_parameters() after the load shows the runtime BitsAndBytesConfig IS being applied to every nn.Linear (attention + MLP gates), but ~36 GB of expert weight lives in two fused 3D nn.Parameter tensors on each Gemma4TextExperts:
That layout exists so torch._grouped_mm can dispatch one grouped matmul per layer. bitsandbytes.replace_with_bnb_linear only swaps nn.Linear instances, so the fused expert weights stay BF16 and dominate the footprint. This explains @DevInsilicon's "50 GB at 4-bit on dual Blackwell" report exactly.
Mechanism B: CPU spillover via device_map="sequential" on tight-VRAM Windows.
For @Michal-Zablocki (gemma-4-e2b-it on RTX 4060 Laptop 8 GB) and the original Studio report on RTX 4060 Ti 8 GB, I could not reproduce on Linux + B200 against byte-identical PyPI unsloth==2026.5.2 code (md5-verified). The reporter's "15.7 GB" is reading total system VRAM including Windows shared system memory (dedicated 7.2/8.0 GB already saturated matches that), and @Michal-Zablocki's explicit device_map="cuda:0" workaround is exactly the signature of accelerate auto-CPU-offloading a 4-bit model that does not fit in 8 GB dedicated VRAM. That is a separate class from Mechanism A.
PRs
#5430 adds a post-load guardrail in FastBaseModel.from_pretrained and FastLlamaModel.from_pretrained that catches both Mechanism A (partial bypass: bnb quantized nn.Linear but a large fraction of weight bytes live in non-nn.Linear Parameters outside the skip list) and the total-bypass class (no Linear4bit modules at all). Emits warnings.warn rather than raising so CPU / MLX / AMD-without-bnb backends are not broken. On 26B-A4B without the swap below, it prints:
Unsloth: load_in_4bit=True is partially applied. bitsandbytes quantized
~0.77 GB of nn.Linear weights, but ~42.54 GB of non-nn.Linear floating
Parameters were left unquantized (e.g. fused MoE expert tensors, custom
Linear-like wrappers). Examples: model.language_model.layers.0.experts.
gate_up_proj (torch.bfloat16, (128, 1408, 2816)), ...
7 unit tests cover both branches plus the skip-list, full-finetuning, and no-quant cases.
#5432 is the actual fix for Mechanism A. Opt-in via UNSLOTH_GEMMA4_MOE_4BIT=1. After the model loads, it walks every Gemma4TextExperts, slices each fused (num_experts, out, in) Parameter into num_experts individual bnb.nn.Linear4bit modules, and patches forward to dispatch per-expert. Trade-off is the loss of torch._grouped_mm throughput in exchange for the VRAM win:
mode
resident VRAM
Linear4bit count
forward fidelity
BF16 (full_finetuning=True)
48.08 GB
0
reference
load_in_4bit=True, no swap
~46 GB
206
partial-quant
load_in_4bit=True, swap on
14.27 GB
7,886
cosine 0.994 vs BF16
Default off until the matching per-expert LoRA path lands; that is the gating concern for flipping it on (training, not inference). The swap renames gate_up_proj to gate_up_proj_4bit to avoid colliding with the existing unsloth_zoo grouped-mm LoRA extractor.
What is NOT in these PRs
Mechanism B (Windows + 8 GB + accelerate CPU spillover) is not addressed. The right fix there is probably a Studio-side default of device_map="cuda:0" on single-GPU + low-VRAM, or a clearer error when accelerate would auto-CPU-offload a bnb-4bit model. Happy to take that as a separate issue if either of the original reporters can confirm that is what they hit; running print([type(m).__name__ for m in model.model.layers[0].modules()]) after load and checking whether Linear4bit is present will distinguish A from B quickly.
Fixed! Sorry on the delay. Gemma-4 MoE models like 26B-A4B kept their expert weights in 16-bit because bitsandbytes only quantized regular linear layers; unslothai/unsloth-zoo#659 now quantizes the experts too, so gemma-4-26B-A4B-it with load_in_4bit=True loads at about 14 GB instead of about 46 GB (from a local folder or the Hub ID) and QLoRA trains. Local safetensors folders were already loaded in 4-bit the same way as Hub IDs; the high usage on 8 GB cards came from the model not fitting in dedicated VRAM and spilling over, which now raises a clear error pointing to offload_layers = "auto" instead of the transformers CPU offload message (#13052).
To update: uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir (if it's not in the current release yet it'll be in the next one). Unsloth Desktop will have an update banner. For Studio, use unsloth studio update. For Docker, use docker exec <container> unsloth-studio-update. Reopen if it still happens.
Activity
rolandtannous commentedon May 9, 2026
@tiegangwang what is the model if you don't mind or what is the base model in this case? (llama3.2 ? gemma3? etc)
also GGUF cannot be trained so that is not relevant here.
Michal-Zablocki commentedon May 9, 2026
Hi, I've been having a similar issue for the last few days on a similar setup - maybe I can post it here.
I've been unable to load the full version of gemma-4-e2b in Unsloth Studio (2026.5.2 version as well), Windows 11 on my RTX 4060 (8GB VRAM) despite the tooltip suggesting only 6 GB should be enough for just loading the full model to chat - see the screen attached:
I've been obtaining the error:
It took me a while to figure out what, well, essentially is written in the message; this is the code where I succeeded in running the model locally:
dump from the output:
nvidia-smi:
In Cloud, I've been running into issues trying to fine-tune gemma-4-e4b version on this notebook - https://colab.research.google.com/github/unslothai/unsloth/blob/main/studio/Unsloth_Studio_Colab.ipynb
It ran fine once when I trained it on a small dataset (yahma/alpaca-cleaned), when I try any bigger dataset around 1 GB - e.g. unsloth/LaTeX_OCR it gets over system RAM(?) and crashes with no specific error/no info in logs - see the screen below:
Thanks for your help
tiegangwang commentedon May 10, 2026
@Michal-Zablocki thanks, i will try.
DevInsilicon commentedon May 13, 2026
I've had a similar issue, but with the regular unsloth python api inside Jupyter notebooks. I am specifying to load in 4 bit with gemma-4-26B-A4B results in 50gb of vram usage which is eerily similar to the full precision model size which is 51gb. (It should be using ~16-20 gb in 4 bit), I specify to load in 4 bit and or 8 bit and it still uses 50gb of vram. This seems like a underlying issue where it is ignoring when you specify load in 4 bit / 8 bit. I'm currently experimenting with passing pre-quantized models to see if the issue resolves.
If your wondering what I'm under its
NVIDIA-SMI 595.58.03 Driver Version: 595.58.03 CUDA Version: 13.2
Ubuntu 25
torch 2.11.0
unsloth 2026.5.2
unsloth-zoo 2026.5.1
With dual blackwell gpus.
Edit: Using a pre-quantized model doesn't seem to fix the full precision loading issue.
danielhanchen commentedon May 15, 2026
Thanks all for the reports. Some notes after digging into this, plus two PRs.
What I found
The thread bundles two different mechanisms that happen to look the same on a VRAM meter.
Mechanism A: Gemma-4 MoE fused experts are not bitsandbytes-quantizable.
Reproduced on
unsloth/gemma-4-26B-A4B-it(B200, transformers 5.5.0, torch 2.9.1, single GPU):load_in_4bit=Trueyields ~46 GB resident VRAM. Walkingnamed_parameters()after the load shows the runtimeBitsAndBytesConfigIS being applied to everynn.Linear(attention + MLP gates), but ~36 GB of expert weight lives in two fused 3Dnn.Parametertensors on eachGemma4TextExperts:That layout exists so
torch._grouped_mmcan dispatch one grouped matmul per layer.bitsandbytes.replace_with_bnb_linearonly swapsnn.Linearinstances, so the fused expert weights stay BF16 and dominate the footprint. This explains @DevInsilicon's "50 GB at 4-bit on dual Blackwell" report exactly.Mechanism B: CPU spillover via
device_map="sequential"on tight-VRAM Windows.For @Michal-Zablocki (gemma-4-e2b-it on RTX 4060 Laptop 8 GB) and the original Studio report on RTX 4060 Ti 8 GB, I could not reproduce on Linux + B200 against byte-identical PyPI
unsloth==2026.5.2code (md5-verified). The reporter's "15.7 GB" is reading total system VRAM including Windows shared system memory (dedicated 7.2/8.0 GB already saturatedmatches that), and @Michal-Zablocki's explicitdevice_map="cuda:0"workaround is exactly the signature of accelerate auto-CPU-offloading a 4-bit model that does not fit in 8 GB dedicated VRAM. That is a separate class from Mechanism A.PRs
#5430 adds a post-load guardrail in
FastBaseModel.from_pretrainedandFastLlamaModel.from_pretrainedthat catches both Mechanism A (partial bypass: bnb quantizednn.Linearbut a large fraction of weight bytes live in non-nn.LinearParameters outside the skip list) and the total-bypass class (noLinear4bitmodules at all). Emitswarnings.warnrather than raising so CPU / MLX / AMD-without-bnb backends are not broken. On 26B-A4B without the swap below, it prints:7 unit tests cover both branches plus the skip-list, full-finetuning, and no-quant cases.
#5432 is the actual fix for Mechanism A. Opt-in via
UNSLOTH_GEMMA4_MOE_4BIT=1. After the model loads, it walks everyGemma4TextExperts, slices each fused(num_experts, out, in)Parameter intonum_expertsindividualbnb.nn.Linear4bitmodules, and patchesforwardto dispatch per-expert. Trade-off is the loss oftorch._grouped_mmthroughput in exchange for the VRAM win:full_finetuning=True)load_in_4bit=True, no swapload_in_4bit=True, swap onDefault off until the matching per-expert LoRA path lands; that is the gating concern for flipping it on (training, not inference). The swap renames
gate_up_projtogate_up_proj_4bitto avoid colliding with the existingunsloth_zoogrouped-mm LoRA extractor.What is NOT in these PRs
Mechanism B (Windows + 8 GB + accelerate CPU spillover) is not addressed. The right fix there is probably a Studio-side default of
device_map="cuda:0"on single-GPU + low-VRAM, or a clearer error when accelerate would auto-CPU-offload a bnb-4bit model. Happy to take that as a separate issue if either of the original reporters can confirm that is what they hit; runningprint([type(m).__name__ for m in model.model.layers[0].modules()])after load and checking whetherLinear4bitis present will distinguish A from B quickly.texastoland commentedon Aug 29, 2026
is this the same issue? I couldn't find it searching
quantized image model:danielhanchen commentedon Oct 11, 2026
Fixed! Sorry on the delay. Gemma-4 MoE models like 26B-A4B kept their expert weights in 16-bit because bitsandbytes only quantized regular linear layers; unslothai/unsloth-zoo#659 now quantizes the experts too, so
gemma-4-26B-A4B-itwithload_in_4bit=Trueloads at about 14 GB instead of about 46 GB (from a local folder or the Hub ID) and QLoRA trains. Local safetensors folders were already loaded in 4-bit the same way as Hub IDs; the high usage on 8 GB cards came from the model not fitting in dedicated VRAM and spilling over, which now raises a clear error pointing tooffload_layers = "auto"instead of the transformers CPU offload message (#13052).To update:
uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir(if it's not in the current release yet it'll be in the next one). Unsloth Desktop will have an update banner. For Studio, useunsloth studio update. For Docker, usedocker exec <container> unsloth-studio-update. Reopen if it still happens.