Skip to content

ValueError: Some modules are dispatched on the CPU or the disk #1629

Closed

Description

@Sweaterdog

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.

Cheers!

Activity

  1. danielhanchen commented on Feb 10, 2025

    @danielhanchen
    Member

    Sorry sadly this means the model is overflowing from GPU memory onto CPU memory - you most likely have too less VRAM sorry

  2. BugReporterZ commented on Jun 22, 2025

    @BugReporterZ

    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:

    from unsloth import FastModel
    
    max_seq_length = 2048
    
    model, tokenizer = FastModel.from_pretrained(
        model_name = "/home/user/LLM/Mistral-Small-3.2-24B-Instruct-2506",
        max_seq_length = max_seq_length,
        dtype = None,
        load_in_4bit = True,
        load_in_8bit = False,
        full_finetuning = False,
    )

    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. 
    

    Libraries:

    Package                  Version
    ------------------------ -----------
    absl-py                  2.3.0
    accelerate               1.7.0
    aiohappyeyeballs         2.6.1
    aiohttp                  3.12.13
    aiosignal                1.3.2
    annotated-types          0.7.0
    attrs                    25.3.0
    bitsandbytes             0.46.0
    certifi                  2025.6.15
    charset-normalizer       3.4.2
    click                    8.2.1
    cut-cross-entropy        25.1.1
    datasets                 3.6.0
    diffusers                0.33.1
    dill                     0.3.8
    docker-pycreds           0.4.0
    docstring_parser         0.16
    filelock                 3.18.0
    frozenlist               1.7.0
    fsspec                   2025.3.0
    gitdb                    4.0.12
    GitPython                3.1.44
    gmpy2                    2.2.1
    grpcio                   1.71.0
    hf_transfer              0.1.9
    hf-xet                   1.1.4
    huggingface-hub          0.33.0
    idna                     3.10
    importlib_metadata       8.7.0
    Jinja2                   3.1.6
    Markdown                 3.8
    markdown-it-py           3.0.0
    MarkupSafe               3.0.2
    mdurl                    0.1.2
    mpmath                   1.3.0
    msgspec                  0.19.0
    multidict                6.5.0
    multiprocess             0.70.16
    networkx                 3.5
    numpy                    2.3.0
    nvidia-cublas-cu12       12.6.4.1
    nvidia-cuda-cupti-cu12   12.6.80
    nvidia-cuda-nvrtc-cu12   12.6.77
    nvidia-cuda-runtime-cu12 12.6.77
    nvidia-cudnn-cu12        9.5.1.17
    nvidia-cufft-cu12        11.3.0.4
    nvidia-cufile-cu12       1.11.1.6
    nvidia-curand-cu12       10.3.7.77
    nvidia-cusolver-cu12     11.7.1.2
    nvidia-cusparse-cu12     12.5.4.2
    nvidia-cusparselt-cu12   0.6.3
    nvidia-nccl-cu12         2.26.2
    nvidia-nvjitlink-cu12    12.6.85
    nvidia-nvtx-cu12         12.6.77
    packaging                25.0
    pandas                   2.3.0
    peft                     0.15.2
    pillow                   11.2.1
    pip                      25.1
    platformdirs             4.3.8
    propcache                0.3.2
    protobuf                 3.20.3
    psutil                   7.0.0
    pyarrow                  20.0.0
    pydantic                 2.11.5
    pydantic_core            2.33.2
    Pygments                 2.19.1
    python-dateutil          2.9.0.post0
    pytz                     2025.2
    PyYAML                   6.0.2
    regex                    2024.11.6
    requests                 2.32.4
    rich                     14.0.0
    safetensors              0.5.3
    sentencepiece            0.2.0
    sentry-sdk               2.29.1
    setproctitle             1.3.6
    setuptools               80.9.0
    shtab                    1.7.2
    six                      1.17.0
    smmap                    5.0.2
    sympy                    1.14.0
    tensorboard              2.19.0
    tensorboard-data-server  0.7.2
    tokenizers               0.21.1
    torch                    2.7.0
    torch-tb-profiler        0.4.3
    torchvision              0.22.0
    tqdm                     4.67.1
    transformers             4.52.4
    triton                   3.3.0
    trl                      0.18.2
    typeguard                4.4.4
    typing_extensions        4.14.0
    typing-inspection        0.4.1
    tyro                     0.9.24
    tzdata                   2025.2
    unsloth                  2025.6.4
    unsloth_zoo              2025.6.3
    urllib3                  2.5.0
    wandb                    0.19.11
    Werkzeug                 3.1.3
    wheel                    0.45.1
    xformers                 0.0.30
    xxhash                   3.5.0
    yarl                     1.20.1
    zipp                     3.23.0
    
  3. BugReporterZ commented on Jun 22, 2025

    @BugReporterZ

    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.

  4. mags0ft commented on May 4, 2026

    @mags0ft

    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...

  5. self-assigned this
    on Oct 8, 2026
  6. danielhanchen commented on Oct 9, 2026

    @danielhanchen
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions