Repository navigation
Description
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
- Materialize root-level parameters and buffers of each base-module parent (here
model.memory_tokens), not only child modules. For example, haveget_base_modules/capture_offloaded_base_modulesalso returnnamed_parameters(recurse=False)of every prefix node, or letHymbaQModeldeclarememory_tokensas a base tensor. - 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
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4891is working on this issue now.Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-root-4891is no longer working on this issue. The issue is free to claim.This host has no Hymba checkpoint and no
nvidia/Hymba-1.5B-Baseremote code cached (HF_HUB_OFFLINE=1), and transformers 5.20.2 ships no nativehymbaconfig/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 themamba_ssmkernels. The two defects are:gptqmodel/looper/awq_processor.py::AWQProcessor._sanitize_kwargskeeps only keys named ininspect.signature(module.forward).parameters, so a**kwargs-onlyforward(Hymba'sHymbaBlock) receives an empty dict and raisesKeyError: 'attention_mask'. Fix: pass the captured kwargs through when the signature has aVAR_KEYWORDparameter. This part is CPU-unit-testable with a stub module that readskwargs['attention_mask']— a good first commit.gptqmodel/models/definitions/hymba.pydeclarespost_attention_layernorm, whichHymbaDecoderLayerdoes not have (the real norm before the MoE ispre_moe_layernorm), soinput_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 plusmamba.in_proj:0:nosrcand thex_proj/dt_proj/conv1ddeclarations, validated by thetest_awq_scaling_groups.pyfold invariant for thehymbafamily.Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished 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
Merge origin/main into transformers5-local-models
fix(hymba): materialize root-level bare parameters and honour constru…
Port every supported model onto the Transformers 5.23 ABI; never patc…