Skip to content

Can't load NVFP4 on 5060TI 16 GB #8246

Closed

Description

@oro872gioioso
  1. Did you update? pip install --upgrade unsloth unsloth_zoo
    Yes
  2. Colab or Kaggle or local / cloud
    Local
  3. Number GPUs used, use nvidia-smi
    +-----------------------------------------------------------------------------------------+
    | NVIDIA-SMI 610.74 KMD Version: 610.74 CUDA UMD Version: 13.3 |
    +-----------------------------------------+------------------------+----------------------+
    | GPU Name Driver-Model | 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 5060 Ti WDDM | 00000000:01:00.0 On | N/A |
    | 0% 43C P1 30W / 234W | 2263MiB / 16311MiB | 1% Default |
    | | | N/A |
    +-----------------------------------------+------------------------+----------------------+
  4. Which notebook? Please link!
    ?
  5. Which Unsloth version, TRL version, transformers version, PyTorch version?
    v0.1.526-beta
    Transformers 4.57.6
    Python 3.13.14
    Torch 2.10.0+cu130
  6. Which trainer? SFTTrainer, GRPOTrainer etc
    Not using trainer (i think)

Problem
Whenever i want to load a NVFP4 Unsloath tell me that either compressed_tensors is not installed or is the wrong version. But when i do the command pip install compressed-tensors every single time it come out as already installed.
The first time that i had problem was with Qwen 3.6 35B A3B NVFP4 Fast but now i have downloaded Gemma 4 E2B it NVFP4 and it still doesn't work. Saying every time the same error over and over.

Activity

  1. ahmad110abbas commented on Aug 11, 2026

    @ahmad110abbas

    Why This Happens

    Unsloth Studio runs inside its own isolated Python virtual environment (C:\Users\<YourUsername>\.unsloth\studio\unsloth_studio).

    When you run pip install compressed-tensors in a regular command prompt, it installs the package into your global Python environment, not into Unsloth Studio's virtual environment. That is why Unsloth Studio cannot find compressed_tensors.


    Solution

    You need to install compressed-tensors directly into Unsloth's Python environment.

    On Windows:

    Open Command Prompt (cmd) and run:

    C:\Users\%USERNAME%\.unsloth\studio\unsloth_studio\Scripts\pip.exe install --upgrade compressed-tensors llm-compressor

    On Linux / macOS:

    Open Terminal and run:

    ~/.unsloth/studio/unsloth_studio/bin/pip install --upgrade compressed-tensors llm-compressor
  2. oro872gioioso commented on Aug 11, 2026

    @oro872gioioso
    Author

    Thank you but the problem just moved.

    Gemma4ForConditionalGeneration LOAD REPORT from: unsloth/gemma-4-E2B-it-NVFP4
    Key | Status |
    -----------------------------------------------------------------------+------------+-
    model.language_model.layers.{0...34}.self_attn.k_scale | UNEXPECTED |
    model.language_model.layers.{0...34}.self_attn.v_scale | UNEXPECTED |
    model.language_model.layers.{1...23}.mlp.gate_proj.weight | UNEXPECTED |
    model.language_model.layers.{1...23}.mlp.up_proj.weight | UNEXPECTED |
    model.language_model.layers.{1...23}.mlp.down_proj.weight | UNEXPECTED |
    model.language_model.layers.{15...34}.self_attn.v_proj.weight_scale | MISSING |
    model.language_model.layers.{1...23}.mlp.down_proj.weight_global_scale | MISSING |
    model.language_model.layers.{15...34}.self_attn.k_proj.weight_scale | MISSING |
    model.language_model.layers.{15...34}.self_attn.v_proj.weight | MISSING |
    model.language_model.layers.{1...23}.mlp.down_proj.input_global_scale | MISSING |
    model.language_model.layers.{15...34}.self_attn.k_proj.weight | MISSING |
    model.language_model.layers.{1...23}.mlp.up_proj.weight_packed | MISSING |
    model.language_model.layers.{1...23}.mlp.gate_proj.input_global_scale | MISSING |
    model.language_model.layers.{1...23}.mlp.gate_proj.weight_global_scale | MISSING |
    model.language_model.layers.{15...34}.self_attn.k_norm.weight | MISSING |
    model.language_model.layers.{1...23}.mlp.up_proj.input_global_scale | MISSING |
    model.language_model.layers.{1...23}.mlp.up_proj.weight_global_scale | MISSING |
    model.language_model.layers.{1...23}.mlp.gate_proj.weight_packed | MISSING |
    model.language_model.layers.{1...23}.mlp.down_proj.weight_packed | MISSING |
    lm_head.weight | MISSING

    Downloaded directly from unsloth studio

  3. yashb98 commented on Aug 18, 2026

    @yashb98

    Reproduced this on a GB10 (Blackwell, aarch64), torch 2.12.1+cu130, transformers 5.15.0, compressed-tensors 0.18.0. Not specific to the 5060 Ti or Studio.

    I checked the safetensors header against the quantization_config and the checkpoint is consistent with itself. k_proj/v_proj exist only for layers 0-14 because of num_kv_shared_layers=20, and the MLPs are split exactly as group_0 and group_1 describe. The load path is what breaks, in three places:

    1. compressed_tensors get_head_dim (utils/helpers.py:481) does hasattr(config, "head_dim"), and transformers 5.x raises AmbiguousGlobalPerLayerAttributeError on per-layer configs like gemma4. The load dies right there whenever kv_cache_scheme is present.
    2. With that patched, init_weights (modeling_utils.py:2403) calls init.normal on the pack-quantized embed_tokens_per_layer, which has no .weight attribute. Second crash.
    3. With both patched the model loads and I get exactly the LOAD REPORT from the comment above. The cause is in how mixed-precision groups are resolved: match_targets orders overlapping regex targets by lexicographic string sort (compressed_tensors/utils/match.py:141), and _scheme_from_targets then takes the first match (lifecycle/apply.py:246). "re:.language_model." sorts before "re:.*layers.(1|2|3|...)", so the broad nvfp4 group beats group_0's specific fp8 layer list. Those 12 MLP layers get built as nvfp4 modules, the packed weights show up as missing, and the layers end up randomly initialized. Generation then dies on a dtype mismatch in layers.1.mlp.gate_proj (bf16 input vs a float32 randomly initialized weight), the first of those 12 layers, so the breakage is real and not just a noisy report.

    I have local patches for 1 and 2 and can turn them into proper PRs for compressed-tensors and transformers if that helps. For 3 the fix is a real specificity ordering for overlapping regex targets. Let me know where you want to track it.

    Full load report comparison

    My run on transformers 5.15.0 + compressed-tensors 0.18.0 (with bugs 1 and 2 patched) produces the same missing/unexpected pattern as the 4.57.6 report above:

    missing (gate_proj.weight_packed, plus the matching scales): layers [1, 2, 3, 10, 11, 12, 13, 14, 15, 19, 20, 23]
    unexpected (gate_proj.weight): the same 12 layers

    That set is exactly group_0's fp8 target list from the quantization_config, which is why this points at group priority resolution and not at the checkpoint. The {1...23} range in the rendered report is just display collapsing; the actual set is the 12 layers above. I confirmed the collapse on my own run: the rendered table says {1...23} while the raw missing_keys set is the 12 non-contiguous layers.

    Generation smoke on GPU dies at model.language_model.layers.1.mlp.gate_proj with "expected mat1 and mat2 to have the same dtype, but got: c10::BFloat16 != float", i.e. the first mis-grouped layer.

    Counts: missing=109, unexpected=76.

  4. oro872gioioso commented on Aug 19, 2026

    @oro872gioioso
    Author

    Reproduced this on a GB10 (Blackwell, aarch64), torch 2.12.1+cu130, transformers 5.15.0, compressed-tensors 0.18.0. Not specific to the 5060 Ti or Studio.

    I checked the safetensors header against the quantization_config and the checkpoint is consistent with itself. k_proj/v_proj exist only for layers 0-14 because of num_kv_shared_layers=20, and the MLPs are split exactly as group_0 and group_1 describe. The load path is what breaks, in three places:

    1. compressed_tensors get_head_dim (utils/helpers.py:481) does hasattr(config, "head_dim"), and transformers 5.x raises AmbiguousGlobalPerLayerAttributeError on per-layer configs like gemma4. The load dies right there whenever kv_cache_scheme is present.
    2. With that patched, init_weights (modeling_utils.py:2403) calls init.normal on the pack-quantized embed_tokens_per_layer, which has no .weight attribute. Second crash.
    3. With both patched the model loads and I get exactly the LOAD REPORT from the comment above. The cause is in how mixed-precision groups are resolved: match_targets orders overlapping regex targets by lexicographic string sort (compressed_tensors/utils/match.py:141), and _scheme_from_targets then takes the first match (lifecycle/apply.py:246). "re:.language_model." sorts before "re:.*layers.(1|2|3|...)", so the broad nvfp4 group beats group_0's specific fp8 layer list. Those 12 MLP layers get built as nvfp4 modules, the packed weights show up as missing, and the layers end up randomly initialized. Generation then dies on a dtype mismatch in layers.1.mlp.gate_proj (bf16 input vs a float32 randomly initialized weight), the first of those 12 layers, so the breakage is real and not just a noisy report.

    I have local patches for 1 and 2 and can turn them into proper PRs for compressed-tensors and transformers if that helps. For 3 the fix is a real specificity ordering for overlapping regex targets. Let me know where you want to track it.

    Full load report comparison

    Thanks for the explanation and for finding the cause!
    If the temporary workaround or local patch for bugs 1 and 2 isn't too complex to apply, could you share how to implement it? I'd really like to test it on my setup while waiting for the official PRs to be merged.

  5. yashb98 commented on Aug 19, 2026

    @yashb98

    Happy to share. Both are small monkeypatches, applied before from_pretrained. Save this as patch_8246.py and import it at the top of your script (before anything imports transformers):

    import torch
    
    # Fix 1: compressed_tensors get_head_dim breaks on transformers 5.x per-layer
    # configs. hasattr(config, "head_dim") raises AmbiguousGlobalPerLayerAttributeError
    # (not an AttributeError subclass, so hasattr does not swallow it). Read the
    # attribute out of __dict__ instead.
    import compressed_tensors.utils.helpers as h
    import compressed_tensors.quantization.lifecycle.initialize as init_mod
    
    def get_head_dim_safe(config):
        d = getattr(config, "__dict__", {})
        hd = d.get("head_dim") or d.get("global_head_dim")
        if hd is None and getattr(config, "per_layer_config", None):
            hd = getattr(config.per_layer_config[0], "head_dim", None)
        if hd is None:
            hd = config.hidden_size // config.num_attention_heads
        return hd
    
    h.get_head_dim = get_head_dim_safe
    init_mod.get_head_dim = get_head_dim_safe
    
    # Fix 2: transformers _init_weights calls init.normal_ on the pack-quantized
    # embedding, which has no .weight attribute. Skip those modules.
    from transformers.modeling_utils import PreTrainedModel
    _orig_init = PreTrainedModel._init_weights
    
    def _init_safe(self, module):
        if isinstance(module, torch.nn.Embedding) and not hasattr(module, "weight"):
            return
        return _orig_init(self, module)
    
    PreTrainedModel._init_weights = _init_safe

    One expectation to set: these two get you past the crashes and the checkpoint loads. They do not fix bug 3 (the nvfp4 group beating the fp8 layer list during target matching), so the 12 mis-grouped MLP layers are still wrongly built and generation will still die with the dtype mismatch. A working model needs the specificity fix in match_targets, which is the part that belongs upstream. I am turning all three into proper PRs for compressed-tensors and transformers.

  6. oro872gioioso commented on Aug 20, 2026

    @oro872gioioso
    Author

    Happy to share. Both are small monkeypatches, applied before from_pretrained. Save this as patch_8246.py and import it at the top of your script (before anything imports transformers):

    import torch

    Fix 1: compressed_tensors get_head_dim breaks on transformers 5.x per-layer

    configs. hasattr(config, "head_dim") raises AmbiguousGlobalPerLayerAttributeError

    (not an AttributeError subclass, so hasattr does not swallow it). Read the

    attribute out of dict instead.

    import compressed_tensors.utils.helpers as h
    import compressed_tensors.quantization.lifecycle.initialize as init_mod

    def get_head_dim_safe(config):
    d = getattr(config, "dict", {})
    hd = d.get("head_dim") or d.get("global_head_dim")
    if hd is None and getattr(config, "per_layer_config", None):
    hd = getattr(config.per_layer_config[0], "head_dim", None)
    if hd is None:
    hd = config.hidden_size // config.num_attention_heads
    return hd

    h.get_head_dim = get_head_dim_safe
    init_mod.get_head_dim = get_head_dim_safe

    Fix 2: transformers init_weights calls init.normal on the pack-quantized

    embedding, which has no .weight attribute. Skip those modules.

    from transformers.modeling_utils import PreTrainedModel
    _orig_init = PreTrainedModel._init_weights

    def _init_safe(self, module):
    if isinstance(module, torch.nn.Embedding) and not hasattr(module, "weight"):
    return
    return _orig_init(self, module)

    PreTrainedModel._init_weights = _init_safe
    One expectation to set: these two get you past the crashes and the checkpoint loads. They do not fix bug 3 (the nvfp4 group beating the fp8 layer list during target matching), so the 12 mis-grouped MLP layers are still wrongly built and generation will still die with the dtype mismatch. A working model needs the specificity fix in match_targets, which is the part that belongs upstream. I am turning all three into proper PRs for compressed-tensors and transformers.

    Hi! Thanks for the detailed breakdown. I tried implementing your patches inside Unsloth Studio, but due to how Unsloth handles isolated subprocesses and my limited familiarity with its codebase, I couldn't get past the second issue. Appreciate the help, and good luck with your PRs!

    If anyone has the same problem and more knowledge than me i think they could make good use of your fix. Until then i can only wait.
    Thanks for your work!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions