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
ValueError: Some modules are dispatched on the CPU or the disk #1629
When I am trying to fine tune large models in Kaggle, which are most models over 8B parameters in 4-bit precision, I get the following error:
ValueError: Some modules are dispatched on the CPU or the disk. Make sure you have enough GPU RAM to fit the quantized model. If you want to dispatch the model on the CPU or the disk while keeping these modules in 32-bit, you need to set `llm_int8_enable_fp32_cpu_offload=True` and pass a custom `device_map` to `from_pretrained`. Check https://huggingface.co/docs/transformers/main/en/main_classes/quantization#offload-between-cpu-and-gpu for more details.
I have got this error when I try to fine tune any model on my local hardware, which is less powerful than what is offered on google colab, or kaggle, but my hardware is "free-er" than what they provide.
I was wondering if this was a bug, or a feature for the basic free tier of Unsloth, and only paid users can actually use a larger LLM than what can be held in GPU memory.
I am observing this error with Mistral Small 3/3.1/3.2 (24B) even though I should have plenty of memory to load the model in 4-bit, having a 24GB GPU. This occurs with minimal code like below:
NVidia-smi output just before running the short script shows I indeed have enough VRAM:
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 570.169 Driver Version: 570.169 CUDA Version: 12.8 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce RTX 3090 On | 00000000:01:00.0 Off | N/A |
| 0% 45C P8 21W / 370W | 16MiB / 24576MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 1752 G /usr/bin/Xorg.bin 4MiB |
+-----------------------------------------------------------------------------------------+
Traceback:
Traceback (most recent call last):
File "/home/user/test/code/loadtest.py", line 5, in <module>
model, tokenizer = FastModel.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/bin/anaconda3/envs/unsloth_env/lib/python3.11/site-packages/unsloth/models/loader.py", line 747, in from_pretrained
model, tokenizer = FastBaseModel.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/bin/anaconda3/envs/unsloth_env/lib/python3.11/site-packages/unsloth/models/vision.py", line 393, in from_pretrained
model = auto_model.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/bin/anaconda3/envs/unsloth_env/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py", line 571, in from_pretrained
return model_class.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/bin/anaconda3/envs/unsloth_env/lib/python3.11/site-packages/transformers/modeling_utils.py", line 309, in _wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/user/bin/anaconda3/envs/unsloth_env/lib/python3.11/site-packages/transformers/modeling_utils.py", line 4555, in from_pretrained
device_map = _get_device_map(model, device_map, max_memory, hf_quantizer, torch_dtype, keep_in_fp32_regex)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/bin/anaconda3/envs/unsloth_env/lib/python3.11/site-packages/transformers/modeling_utils.py", line 1344, in _get_device_map
hf_quantizer.validate_environment(device_map=device_map)
File "/home/user/bin/anaconda3/envs/unsloth_env/lib/python3.11/site-packages/transformers/quantizers/quantizer_bnb_4bit.py", line 104, in validate_environment
raise ValueError(
ValueError: Some modules are dispatched on the CPU or the disk. Make sure you have enough GPU RAM to fit the quantized model. If you want to dispatch the model on the CPU or the disk while keeping these modules in 32-bit, you need to set `llm_int8_enable_fp32_cpu_offload=True` and pass a custom `device_map` to `from_pretrained`. Check https://huggingface.co/docs/transformers/main/en/main_classes/quantization#offload-between-cpu-and-gpu for more details.
Still observing this with tiny Gemma 4 E4B at bnb 4-bit QLoRA training in the latest Unsloth Studio, I have 12 GB of VRAM which should theoretically suffice...
Fixed! Sorry on the delay. The 24 GB (Mistral Small 24B) and 12 GB (Gemma 4 E4B) cases above already load and train in 4-bit on current Unsloth. For a model that really does not fit on the GPU, the confusing transformers error is now replaced by an Unsloth message that says how much GPU memory is free and suggests offload_layers = "auto", which keeps the decoder layers the GPU cannot hold in system RAM and streams them in during training (slower, and it needs that much free system RAM), or a smaller model. Fixed in #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). Reopen if it still happens.
Activity
danielhanchen commentedon Feb 10, 2025
Sorry sadly this means the model is overflowing from GPU memory onto CPU memory - you most likely have too less VRAM sorry
BugReporterZ commentedon Jun 22, 2025
I am observing this error with Mistral Small 3/3.1/3.2 (24B) even though I should have plenty of memory to load the model in 4-bit, having a 24GB GPU. This occurs with minimal code like below:
NVidia-smi output just before running the short script shows I indeed have enough VRAM:
Traceback:
Libraries:
BugReporterZ commentedon Jun 22, 2025
Might be related to #2504
There, an example was shown of a 30B parameter model requiring 43GB of memory while the shards were being loaded, and 16.8GB after loading.
mags0ft commentedon May 4, 2026
Still observing this with tiny Gemma 4 E4B at bnb 4-bit QLoRA training in the latest Unsloth Studio, I have 12 GB of VRAM which should theoretically suffice...
danielhanchen commentedon Oct 9, 2026
Fixed! Sorry on the delay. The 24 GB (Mistral Small 24B) and 12 GB (Gemma 4 E4B) cases above already load and train in 4-bit on current Unsloth. For a model that really does not fit on the GPU, the confusing transformers error is now replaced by an Unsloth message that says how much GPU memory is free and suggests
offload_layers = "auto", which keeps the decoder layers the GPU cannot hold in system RAM and streams them in during training (slower, and it needs that much free system RAM), or a smaller model. Fixed in #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). Reopen if it still happens.