Skip to content

fix: preserve bias dtype across checkpoint restore (#4324) - #4362

Merged
Qubitium merged 1 commit into
mainfrom
pr/4324
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
pr/4324

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

restore_packed_module rebuilt each packed layer on the meta device with the kernel's default fp16 bias placeholder. Quantized layers keep their bias at the source model dtype (bf16/fp32 on Qwen2/2.5, OPT, Bloom), so the resume schema check compared the rebuilt fp16 bias against the BF16 bundle tensor and aborted with checkpoint tensor schema differs: <module>.

What Changed

  • packed_module_config now records the real bias dtype (bias_dtype) whenever the packed module owns a bias tensor.
  • restore_packed_module consumes that recorded dtype and casts the rebuilt meta bias (and bias_dtype attribute) to the checkpoint width, so the tensor schema matches the bundle.
  • The schema comparison in gptq_checkpoint.py is unchanged: a genuinely different bundle dtype still raises CheckpointError.

Tests

$ export GPTQ_BYPASS_SAFETY_CHECKS=1 PYTHONPATH=$PWD CUDA_VISIBLE_DEVICES=
$ python3 -m pytest tests/test_checkpoint_bias_dtype_4324.py -q
3 passed

$ python3 -m pytest tests/test_checkpoint_modules.py tests/test_checkpoint_processor_adapter.py \
    tests/test_checkpoint_metadata_contracts.py tests/test_checkpoint_store.py \
    tests/test_checkpoint_extension.py tests/test_checkpoint_scale_dtype.py \
    tests/test_checkpoint_bias_dtype_4324.py -q
1 failed, 113 passed, 5 skipped
# only failure: tests/test_checkpoint_modules.py::test_qqq_optional_group_scales_schema
#   -> pre-existing environment limit (ImportError: QQQ: CUDA is not available);
#      reproduces on the unmodified tree.

$ python3 -m pytest tests/test_quantization_lifecycle_contracts.py -q
16 passed

The new test drives the real QuantizationCheckpointAdapter.capture()/restore() path with a synthetic TorchLinear bundle whose bias is bf16/fp32; both cases fail on the parent commit with CheckpointError: checkpoint tensor schema differs: proj and pass with the fix. The negative case rewrites the bundle bias to fp32 while the recorded schema says bf16 and asserts CheckpointError is still raised.

Model Support / Module Plan

N/A — no new model types or registry entries.

Fixes #4324

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