Skip to content

[BUG] Hymba cannot be quantized in fp16/bf16: default offload leaves model.memory_tokens on meta (capture crash); offload_to_disk=False is refused by the load dtype guard (fp32 A_log, #4209 incomplete) #4888

Closed

Description

@Qubitium

Found on main @ 4f287eb (same at 12c1273), AMD R9700 (ROCm 10.1). Hymba-1.5B-Base truncated to 2 layers. The CUDA-only mamba_ssm/causal_conv1d/flash_attn imports of the remote code were replaced by their reference torch implementations. Attention was forced to sdpa, as gptqmodel itself does when flash-attn is absent (utils/hf.py:2070).

What is wrong

Hymba cannot be quantized in half precision with either offload_to_disk setting. The two settings fail for different reasons.

1. offload_to_disk=True (the default): input capture crashes on model.memory_tokens.

  File "gptqmodel/looper/stage_inputs_capture.py", line 535, in cache_inputs
  File "gptqmodel/models/base.py", line 3180, in run_input_capture
  File ".../modeling_hymba.py", line 2201, in forward
    inputs_embeds, mem_packed_shape = pack((mem, inputs_embeds), 'b * d')
RuntimeError: Tensor on device cpu is not on the expected device meta!

HymbaModel owns its 128 meta tokens as a bare nn.Parameter (model.memory_tokens), not as a submodule, and prepends them before layer 0. With the offload shell, only the base modules returned by get_base_modules() (models/base.py:6655-6700: embed_tokens, final_layernorm, ...) are materialized for the capture forward. A parameter that sits directly on the decoder root stays on meta. The checkpoint stores it (model.memory_tokens, bf16). tests/models/test_hymba.py works around this with OFFLOAD_TO_DISK = False # FIXME the issue where hymba does not work with OFFLOAD_TO_DISK=True.

2. offload_to_disk=False (the test's setting): the load is rejected by the #4140 dtype guard.

RuntimeError: HymbaQModel.from_pretrained: model load left a corrupted state: floating parameters are not all torch.bfloat16: {'torch.float32': 2}

The two parameters are model.layers.{0,1}.mamba.A_log.0. The remote code builds them as nn.Parameter(torch.log(A)) from an explicit float32 A (modeling_hymba.py:1544). Transformers keeps the parameter's dtype and loads the bf16 checkpoint values into it, and the values are correct. Loading in fp32 and comparing gives a max difference of 0.0 against the checkpoint for A_log.0, D.0, memory_tokens and in_proj.weight. #4209 (the fix of #4170) only exempts modules declared in _keep_in_fp32_modules(_strict). A parameter the model's own code allocates in fp32 still fails assert_loaded_model_state (utils/hf.py:494-511), so a valid load is refused. With dtype=torch.float16 the result is the same.

Only dtype=torch.float32 together with offload_to_disk=False gets through. In that mode GPTQ completes (1448 samples reach every module of both layers), but nobody quantizes a 1.5B model in fp32 to ship it.

Repro

import torch
from gptqmodel import GPTQModel
from gptqmodel.quantization import GPTQConfig
from gptqmodel.quantization.config import CalibrationConfig

path = "nvidia/Hymba-1.5B-Base"   # truncated to num_hidden_layers=2 for speed; full model behaves the same
rows = [{"input_ids": torch.randint(3, 32000, (L,)).tolist(), "attention_mask": [1] * L} for L in (40, 48, 56, 64)]

# 1) default offload_to_disk=True
q = GPTQModel.load(path, GPTQConfig(bits=4, group_size=32), trust_remote_code=True, dtype=torch.bfloat16)
q.quantize(CalibrationConfig(dataset=rows))      # RuntimeError: Tensor on device cpu is not on the expected device meta!

# 2) offload_to_disk=False
q = GPTQModel.load(path, GPTQConfig(bits=4, group_size=32, offload_to_disk=False), trust_remote_code=True, dtype=torch.bfloat16)
# RuntimeError: ... floating parameters are not all torch.bfloat16: {'torch.float32': 2}

Both outcomes are identical at 12c1273.

Suggested fix

  1. Materialize root-level parameters and buffers of each base-module parent (here model.memory_tokens), not only child modules. For example, have get_base_modules/capture_offloaded_base_modules also return named_parameters(recurse=False) of every prefix node, or let HymbaQModel declare memory_tokens as a base tensor.
  2. In assert_loaded_model_state, accept a float32 parameter whose dtype comes from the model's construction rather than from a broken load. For example, compare against the dtype the parameter had on the meta/init model, or let a definition declare extra fp32 parameters (HymbaQModel: mamba.A_log.*).

Test that should have caught it

tests/models/test_hymba.py cannot pass in bf16 as written: it disables offload because of item 1, which runs straight into item 2. Its FIXME should be an issue, and the test should run with the default offload.

Severity

High for Hymba: there is no supported way to quantize it in fp16/bf16.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-4891 is working on this issue now.

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-root-4891 is no longer working on this issue. The issue is free to claim.

    This host has no Hymba checkpoint and no nvidia/Hymba-1.5B-Base remote code cached (HF_HUB_OFFLINE=1), and transformers 5.20.2 ships no native hymba config/model, so neither half of the issue can be reproduced or validated here. Both parts are needed together: fixing only _sanitize_kwargs (item 1) would convert today's hard crash into silent quality loss, which the issue explicitly warns against.

    Suggested next step for whoever picks this up: a host with nvidia/Hymba-1.5B-Base (or a truncated copy) plus the mamba_ssm kernels. The two defects are:

    1. gptqmodel/looper/awq_processor.py::AWQProcessor._sanitize_kwargs keeps only keys named in inspect.signature(module.forward).parameters, so a **kwargs-only forward (Hymba's HymbaBlock) receives an empty dict and raises KeyError: 'attention_mask'. Fix: pass the captured kwargs through when the signature has a VAR_KEYWORD parameter. This part is CPU-unit-testable with a stub module that reads kwargs['attention_mask'] — a good first commit.
    2. gptqmodel/models/definitions/hymba.py declares post_attention_layernorm, which HymbaDecoderLayer does not have (the real norm before the MoE is pre_moe_layernorm), so input_layernorm -> [mamba.in_proj, moe.experts.*.gate_proj/up_proj] is folded and the layer output drifts by 5.8e-2 / 8.2e-2. Needs the corrected tree plus mamba.in_proj:0:nosrc and the x_proj/dt_proj/conv1d declarations, validated by the test_awq_scaling_groups.py fold invariant for the hymba family.
  3. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-53ba17eb4d83 finished this issue.

    Pull request: #5021

    One workload with #4888, #4891: both are the Hymba quantization path: root-level parameter offload/dtype guard and the AWQ kwargs/tree defects share the same fixtures

    make Hymba quantizable in half precision: root-parameter offload + dtype guard, AWQ **kwargs passthrough and corrected norm tree

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions