Skip to content

fix(load): require every kernel's checkpoint payload (#5218) - #5239

Merged
Qubitium merged 1 commit into
mainfrom
fix/5218-fail-closed-load
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5218-fail-closed-load

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #5218.

fix(load): require every kernel's complete checkpoint payload (#5218)

Root cause (one line)

validate_checkpoint_qweights only enforced the suffixes a kernel declared, and
only qweight (GPTQ/AWQ family) and QQQ's B/s_group/s_channel were
declared, so a checkpoint truncated at scales/qzeros/g_idx or at any
FP8/NF12/GGUF/Paro/VPTQ/BnB/MACaQ/EXL3 tensor loaded into the module's
torch.empty/zero placeholder and produced NaN, wrong logits, a CUDA illegal
memory access, or a device-mismatch error.

Fixes #5218. Follow-up to #5032 / #5010.

Before / after

flowchart TD
    A[GPTQModel.load] --> B[validate_checkpoint_qweights]
    B --> C{module declares<br/>CHECKPOINT_REQUIRED_BUFFERS?}
    C -- "GPTQ/AWQ: qweight only<br/>QQQ: B/s_group/s_channel" --> D{checkpoint has suffix?}
    D -- yes --> E[load]
    D -- no --> F[ValueError]
    C -- "FP8/NF12/GGUF/Paro/VPTQ/<br/>BnB/MACaQ/EXL3: nothing declared" --> G[no check]
    G --> H[torch.empty / zero placeholder]
    H --> I[NaN · wrong logits ·<br/>illegal memory access ·<br/>device mismatch]
Loading
flowchart TD
    A[GPTQModel.load] --> B[validate_checkpoint_qweights]
    B --> C["instance hook checkpoint_required_buffers()<br/>else CHECKPOINT_REQUIRED_BUFFERS"]
    C --> D["resolve dotted suffix on the live module<br/>_checkpoint_suffix_tensor"]
    D -- "live tensor absent (conditional payload)" --> E[skip: nothing to restore]
    D -- "live tensor present" --> F{optional-empty and numel==0?}
    F -- yes --> E
    F -- no --> G{checkpoint has<br/>module.suffix or alias?}
    G -- yes --> H[load]
    G -- no --> I["ValueError: Missing required quantized weights ...: module.suffix"]
Loading

What changed

  • gptqmodel/utils/model.py
    • New _checkpoint_suffix_tensor(module, suffix) resolves a dotted suffix
      (e.g. VPTQ centroids.weight) through _modules/attributes and returns
      None when this instance does not own the tensor.
    • validate_checkpoint_qweights asks the instance hook
      checkpoint_required_buffers() first (falling back to the class tuple) and
      is now presence-aware: a suffix the live module does not own is skipped.
      This is what lets one union declaration cover conditionally allocated
      payloads (AllSpark has no qzeros; plain MXFP4 MACaQ has no BH/pre_scale;
      VPTQ without residuals has no res_centroids; BnB 4/8-bit differ; EXL3
      packed vs unpacked signs and mcg vs mul1).
    • CHECKPOINT_OPTIONAL_EMPTY_BUFFERS keeps its meaning: an empty live buffer
      is not required (QQQ per-channel s_group, symmetric BitBLAS qzeros).
    • The fail-closed message is unchanged:
      Missing required quantized weights in checkpoint '<path>': <keys>.
  • gptqmodel/nn_modules/qlinear/__init__.py
    • PackedGroupedQuantLinear: ("qweight", "scales", "qzeros").
    • BaseQuantLinear.checkpoint_required_buffers() is the class-tuple default;
      GPTQQuantLinear appends g_idx when desc_act is set.
  • Per-kernel declarations: BitBLAS (qweight,scales,qzeros + empty
    qzeros), TT blockfloat linear/embedding (codes,exponents), FP8
    (weight,weight_scale_inv), NF12 (nf12_packed,nf12_escapes,
    nf12_exp_base), GGUF (qweight), BnB (weight + quant-state/absmax/map/scb),
    Paro (qweight,qzeros,scales,theta,pairs,channel_scales), VPTQ
    (indices + codebooks/scales/perm), MACaQ (W_packed,W_scales,BH,
    pre_scale), EXL3 (trellis + sign vectors + codebook).
  • Not declared on purpose: AllSpark qzeros (no such buffer),
    qzeros_format (not serialized), g_idx when desc_act=False (derived),
    code_shape (derived), AutoNF12Embedding buffers (calibration scratch; the
    writer saves the dense weight).

Evidence

Issue-reported symptom (2-layer Qwen2.5-0.5B, delete one tensor of
model.layers.0.self_attn.q_proj) and the new behavior. "refused" means the
fail-closed ValueError naming the missing tensor; the new matrix reproduces
each deletion at the loader boundary.

format missing tensor before (issue) after
GPTQ (Marlin) qweight refused (#5032) refused
GPTQ scales loads, logits NaN refused
GPTQ qzeros loads, max diff 5.33 refused
GPTQ desc_act=True g_idx loads, max diff 0.73 refused (config-dependent)
AWQ GEMM scales loads, logits NaN refused
AWQ GEMM qzeros loads, max diff 5.33 refused
AWQ GEMV_FAST qzeros / scales loads, diff 6.91 / 5.41 refused
FP8 (row) weight_scale_inv loads, max diff 20.2 refused
FP8 weight refused refused
NF12 nf12_packed / nf12_exp_base loads, diff 3.11 / 3.15 refused
NF12 nf12_escapes unrelated escape index 0 out of range refused
GGUF q4_k_m qweight (only tensor) loads, diff 3.16 refused
Paro scales / theta / pairs / channel_scales loads, diff 3.24 / 2.64 / 3.99 / 1.16 refused
VPTQ centroids.weight / res_centroids.weight loads, logits NaN refused
BitsAndBytes 4-bit weight loads, CUDA illegal memory access refused
BitsAndBytes 4-bit weight_absmax / weight_quant_map / weight_quant_state refused refused
MACaQ BH/W_packed/W_scales/pre_scale loads, device mismatch at forward refused
EXL3 trellis/suh/svh/mcg meta-device ValueError (not fail-closed) refused
AWQ GEMV qzeros / scales AWQ GEMMV2 expects all tensors on CUDA refused
QQQ B/s_group/s_channel refused (#5032) refused

Regression matrix

New tests/test_fail_closed_checkpoint_5218.py builds each real kernel,
publishes state_dict() as safetensors, and deletes one tensor at a time:
21 cases (GPTQ, GPTQ desc_act, AWQ, FP8, NF12, GGUF, BnB 4/8-bit, Paro, VPTQ
plain/full, MACaQ default/plain, QQQ grouped/per-channel, TT blockfloat, EXL3
mcg/mul1/packed, AllSpark, BitBLAS). It asserts the intact checkpoint
passes, the declared set covers every published tensor, every required tensor
fails closed and is named, and optional/derived tensors do not. Two
end-to-end cases (FP8, NF12) quantize → save → reload → forward, then truncate
and assert the fail-closed error.

Verification

# new matrix, GPU 4 (RTX 5090, sm_120)
22 passed, 1 skipped in 5.73s        # bitblas not installed

# pre-fix (implementation stashed, test kept), GPU 4
20 failed, 2 passed, 1 skipped       # only QQQ passed; 20 families red

# no-regression
110 passed, 7 skipped   # loader/checkpoint/QQQ contracts
229 passed, 13 skipped  # FP8/NF12/BnB/AWQ/checkpoint-quantization
727 passed, 1 skipped   # macaq/paro/vptq/gguf/blockfloat/exl3

# ruff
uvx [email protected] check gptqmodel docs/eora tests setup.py
All checks passed!

Not verified: bitblas (not installed); native GGUF/VPTQ/EXL3 CUDA kernels and
the BnB CUDA forward path (loader-level matrix uses the Torch implementations);
Marlin/AWQ-Marlin/Machete/Swordfish/ExLlamaV2/MLX inherit the family
declaration but were not separately constructed in the new matrix.

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

Labels

None yet

Projects

None yet

1 participant