Skip to content

[BUG] auto_nf12: a fully excluded non-final layer is saved as NF12 buffers under nn.Linear names -> reload yields NaN logits #4007

Closed

Description

@Qubitium

Audit of main @ 105602e. Silent checkpoint corruption with the default auto_dtype_cast="auto_nf12".

A fully excluded non-final layer is saved as NF12 buffers under nn.Linear names, and the reload gives NaN logits (high)

If a dynamic -: rule excludes every module of a layer that is not the last one, the layer still runs one forward so the next layer gets its inputs. This is the replay_skipped_layer branch in gptqmodel/looper/stage_layer.py:1060-1100 → looper._prepare_named_module_for_forward → models/base.py:4726 → _maybe_auto_dtype_cast_forward_module (base.py:3529).

During that forward, the layer's nn.Linear modules are swapped for AutoNF12HookedLinear and never swapped back: the dense restore only happens on the role == "quant_source" path (base.py ~4626-4680), which an excluded layer never takes.

As a result:

  • save() writes *.nf12_packed / *.nf12_escapes / *.nf12_exp_base instead of *.weight, while quantize_config.json describes the layer as plain unquantized.
  • On load, HF reports the NF12 keys as "not used" (a warning only) and the nn.Linear weights stay uninitialised.

Repro (tiny bf16 Llama, 4 layers, CUDA sm ≥ 80, dynamic={"-:.*layers\.1\..*": {}}):

saved layer1 keys: ['model.layers.1.mlp.up_proj.nf12_escapes', 'model.layers.1.mlp.up_proj.nf12_exp_base', 'model.layers.1.mlp.up_proj.nf12_packed']
reloaded logits rel-err vs fp:  auto_dtype_cast="off": 0.18    default: nan

Scope:

  • Reproduced with GPTQ and AWQ (gemm). offload_to_disk=False doesn't help.
  • It happens for layers 0, 1, 2 and 1+2.
  • Not triggered by: excluding the last layer, a single module (-:.*mlp\.down_proj), one sub-block (-:.*layers\.1\.self_attn\..*), or auto_dtype_cast="off".
  • Triggers with any bf16 source (or fp16 that converts to bf16 exactly).

Fix:

  • Don't NF12-pack sources in the replay_skipped_layer forward: set state["auto_dtype_cast_forward_disabled"], or call restore_source_module after the replay.
  • Make save() refuse NF12 buffers under a module that is not quantized.

The dynamic skip-layer tests (tests/test_dynamic.py, test_checkpoint_quantization.py::test_dynamic_*) run on CPU, where NF12 is not eligible. A GPU bf16 whole-layer -: test that saves, reloads and checks logits is missing.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions