Repository navigation
fix(load): gate post_init on each kernel's checkpoint payload (#5261) - #5276
Merged
Merged
Conversation
`_post_init_offloaded` decided whether a layer was a disk-offloaded meta placeholder by reading `module.qweight`. NF12, QQQ, VPTQ, BitsAndBytes, MacaQ and other families store their payload under different names, so every plain single-GPU `GPTQModel.load()` of such a checkpoint raised `AttributeError: '<Kernel>' object has no attribute 'qweight'` before `post_init` ran. - `BaseQuantLinear.checkpoint_payload_tensors()` resolves the family's `CHECKPOINT_REQUIRED_BUFFERS` (the names the checkpoint validator already requires, dotted submodule names included) and falls back to every registered tensor. - `checkpoint_payload_is_meta()` reports whether Accelerate replaced that payload with meta placeholders. - `_post_init_offloaded` and `_post_init_cpu_offloaded_marlin` use the probe, so resident layers still run `post_init` once and disk-offloaded layers are still materialized, initialized, and returned to meta. - Regression tests load one checkpoint per family (GPTQ/Marlin control, NF12, QQQ, VPTQ, FP8, BitsAndBytes), assert a family-specific post-init side effect and a finite forward, and cover the meta/offload and fail-closed branches. Docs describe the payload contract.
Qubitium
marked this pull request as ready for review
November 18, 2026 16:12
This was referenced Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(load): gate post_init on each kernel's checkpoint payload (#5261)
Summary
#5247 added a general
_post_init_offloadedfor non-Marlin kernels so adisk-offloaded layer could be materialized through its Accelerate hook before
post_init. The helper opened withif not module.qweight.is_meta:, but mostkernel families do not store their payload in
qweight. On a plainsingle-GPU load (no offload at all) every NF12, QQQ, VPTQ, BitsAndBytes,
MacaQ, ... checkpoint raised:
before
post_initwas ever reached. This PR replaces the name probe with akernel-level payload contract.
Root cause
gptqmodel_post_init(gptqmodel/utils/model.py) routed everyBaseQuantLinearthrough_post_init_offloaded. That helper assumed the GPTQstorage name
qweight, so it raisedAttributeErrorfor every family whosepayload is named differently:
nf12_packed,nf12_escapes,nf12_exp_baseB,s_channel,s_groupindices+ codebooks / norm / permutationweight,weight_scale_inv(has a PEFTqweightproperty)weight+ quant-state buffersW_packed,W_scales,BH,pre_scaleThe regression is load-time only: quantization and save already worked.
Before
flowchart TD A["gptqmodel_post_init(model)"] --> B["for each BaseQuantLinear"] B --> C["_post_init_offloaded(module)"] C --> D["module.qweight.is_meta"] D -- "GPTQ / Marlin / EXL3" --> E["resident -> post_init()"] D -- "NF12 / QQQ / VPTQ / BnB" --> F["AttributeError:<br/>no attribute 'qweight'"] F --> G["GPTQModel.load() fails<br/>even on a plain cuda:0 load"] style F fill:#f8d7da,stroke:#b02a37,stroke-width:2px style G fill:#f8d7da,stroke:#b02a37,stroke-width:2pxAfter
flowchart TD A["gptqmodel_post_init(model)"] --> B["for each BaseQuantLinear"] B --> C["module.checkpoint_payload_is_meta()"] C --> D["checkpoint_payload_tensors()<br/>resolve CHECKPOINT_REQUIRED_BUFFERS"] D --> E{"any payload tensor<br/>is meta?"} E -- "no, resident" --> F["post_init() in place<br/>(exactly once)"] E -- "yes, disk-offloaded" --> G{"SUPPORTS_CPU_OFFLOAD?"} G -- "no" --> H["RuntimeError<br/>fail closed (#5194)"] G -- "yes" --> I["hook.pre_forward<br/>-> post_init()<br/>-> hook.post_forward"] style F fill:#d1e7dd,stroke:#146c43,stroke-width:2px style I fill:#d1e7dd,stroke:#146c43,stroke-width:2px style H fill:#f8d7da,stroke:#b02a37,stroke-width:2pxWhat changed
gptqmodel/nn_modules/qlinear/__init__.pyBaseQuantLinear.checkpoint_payload_tensors()andcheckpoint_payload_is_meta(); dotted-name resolver_named_tensorgptqmodel/utils/model.py_post_init_offloadedand_post_init_cpu_offloaded_marlincall the probe instead ofmodule.qweight.is_metatests/test_post_init_payload_5261.pytests/test_hf_bridge_cpu_offload_5022.py_OffloadableLayerimplements the new contractdocs/kernel-dispatch-cpu.mdThe contract deliberately reuses
CHECKPOINT_REQUIRED_BUFFERS, the samedeclaration
validate_checkpoint_qweightsalready enforces, so the probecannot drift from the loader's required payload. A kernel that declares
nothing (or whose declared tensors were replaced by a derived cache) falls
back to every tensor the module registers. Dotted names are supported because
VPTQ's codebooks are submodule tensors (
centroids.weight).Resident layers are unchanged: the probe is
False,post_initruns inplace, and the materialize/restore path is never entered. Disk-offloaded
layers still run
post_initwhile materialized and are returned to meta, sothe offload map stays authoritative (#5194/#5247 behaviour preserved).
Red -> green evidence
Repro:
.scratch/repro_5261.py, one 2-layer Qwen2.5-0.5B-Instruct checkpointper family, then
GPTQModel.load(ckpt, device="cuda:0")+ forward.c1807f889e24743120^MarlinLinearNF12LinearQQQLinearVPTQCudaLinearTorchFP8Linearqweightproperty)BitsAndBytesLineartests/test_post_init_payload_5261.py:mainThe two rows that pass on
mainare the GPTQ/Marlin control and FP8 (itsqweightproperty hides the bug). The fourAttributeErrorrows plus thecontract/meta/offload unit tests are the red->green delta.
Test counts
tests/test_post_init_payload_5261.py(new)tests/test_hf_bridge_cpu_offload_5022.py(#5247)test_load_*,test_loader_*)test_offload_{base,quantized,disk,run_namespace})test_fp8*selection)-k "roundtrip or reload or save"-k "load or save or reload or roundtrip or checkpoint"overtest_*nf12*/*qqq*/*vptq*/*fp8*)GPTQModel.loadreloaduvx [email protected] check gptqmodel docs/eora tests setup.pyNot verified
MacaQ checkpoint load was run.
TorchFP4Linear) is a plainnn.Module, not aBaseQuantLinear, soit never enters this branch; W4A* inherits the GPTQ payload. Both were
reasoned about, not loaded.
device_map="disk") for non-Marlin families was not exercisedend-to-end. The meta materialize/restore path is covered by a real NF12
layer on CPU (
accelerate.cpu_offload(..., offload_buffers=True)) and byfake layers; the fail-closed branch is covered as well.
tests/test_offload_files.py(2595 lines) andtests/test_loader.pywerenot run in full; the focused files above were.