Repository navigation
fix(structure): publish materialized parameters atomically (#5088) - #5132
Merged
Merged
Conversation
A lazy shell owns meta parameters. `_copy_checkpoint_tensors_into_submodule` allocated replacement storage, installed it on the module, and copied the checkpoint values in a second step. An interrupt between the two left `torch.empty` weights that are no longer meta, so run-exit recovery (whose only "not loaded" test is `is_meta`) treated the module as materialized and the in-session model forwarded with uninitialized weights. Fill the replacement before publishing it. An interrupt during the copy now leaves the old meta parameter, which the recovery already re-materializes. Buffer materialization already copied before `register_buffer` and is unchanged. Add regression nodes for the weight-only post-loop tail and the GPTQ first-capture layer; both assert every floating parameter is finite and the recovered weights still match the checkpoint.
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.
Summary
Fixes #5088.
A Ctrl-C (or any exception) during lazy checkpoint materialization could leave a
module owning
torch.emptyweights.ModelLoader._copy_checkpoint_tensors_into_submoduleallocated replacement storage, installed it on the module with
setattr, andonly then copied the checkpoint values. The installed tensor is no longer
meta, so run-exit recovery — whose only "not loaded" test isis_meta—treated the module as materialized.
quantize()re-raised the interrupt andthe in-session model forwarded with uninitialized weights, silently producing
NaN or plausible-looking wrong logits.
This affects the weight-only post-loop tail (RTN/GGUF/FP8) and the GPTQ
first-capture layer, both of which materialize through the same helper. The
defect reproduces on current
main.What Changed
gptqmodel/utils/structure.py: new_publish_checkpoint_param_allocates andfills the replacement parameter, then publishes it with
setattr. Both theconcatenated-shard and grouped-shard branches call it. An interrupt during
the copy leaves the old
metaparameter, which the existing recovery alreadyre-materializes.
register_buffer; unchanged.tests/test_run_exit_recovery_contract_5060.py: two regression nodes injecta
KeyboardInterruptat the first checkpoint copy inside materialization,one for the weight-only post-loop tail and one for the GPTQ first-capture
layer. They assert the injection fired, every floating parameter is finite,
and the recovered weights still match the checkpoint.
docs/cancelled-run-contract.md: records the atomic-publish contract, theold/new state flow and the before/after table.
Tests
Red evidence on the pre-fix revision:
Green with the fix:
A native GPU run of the same two interrupt windows (weight-only post-loop tail
and GPTQ first-capture layer) left no
metaor non-finite parameters and therecovered forward was finite; the pre-fix code produced NaN in both windows.
The new pytest nodes are CPU-only so they stay in the default suite.
Pre-existing, unrelated:
tests/test_auto_dtype_cast.pyhas three failures onthe unmodified base revision (NF12 fused-diff and GPU-encoding tests); they are
not touched by this change.
Model Support / Module Plan
Not applicable: no model type, alias, definition, module-plan, or fusion change.
AWQ onboarding safety
Not applicable: no AWQ grouping, search, replay, or fold change.
Logic Flow Documentation
and docs page are included below.
file:lineevidence.docs/repeats the diagrams, titled for themechanism, and is linked from
README.md.Diagram summary: this is a local ordering fix inside one materialization helper,
but it changes the failure state of tensor publication, so the state flow and a
before/after table are recorded in
docs/cancelled-run-contract.md(alreadylinked from
README.md).stateDiagram-v2 state "module owns meta parameter" as Meta state "replacement filled off-module" as Filling state "module owns loaded parameter" as Loaded [*] --> Meta Meta --> Filling: allocate storage + copy checkpoint Filling --> Loaded: publish (setattr / register_parameter) Filling --> Meta: interrupt (discard replacement) Loaded --> [*]gptqmodel/utils/structure.py::_copy_checkpoint_tensors_into_submodule, concatenated and grouped-shard branches)torch.empty_likewas installed withsetattrand only then filled bycopy_. An interrupt between them left non-metatorch.emptyweights that recovery skipped, so the forward silently returned NaN or wrong logits.gptqmodel/utils/structure.py::_publish_checkpoint_param_allocates and fills the replacement, then publishes it. An interrupt leaves the old meta parameter, which recovery re-materializes.Review Requirements
I have:
Kernel Accuracy Requirements
Not applicable: no kernel or fusion change.
Notes
The regression nodes use a tiny real Llama checkpoint and inject the interrupt
at the first
Tensor.copy_inside_copy_checkpoint_tensors_into_submodule, sothey exercise the materialization window itself rather than a helper boundary.