Repository navigation
refactor(looper): fold quantization_layer_boundary_checkpoint into LoopExtensions - #6477
Merged
Merged
Conversation
…opExtensions The looper had two resume and commit mechanisms. LoopExtensions (on_start returns a LoopPlan cursor, on_boundary commits a step after quiescing its finalizers) drives CheckpointConfig. Next to it, a duck-typed model attribute `quantization_layer_boundary_checkpoint` (restore, commit_layer, is_catchup_layer, prepare_catchup_layer, finalize_catchup_layer, materialize_deferred_prefix) was probed with getattr in module_looper and five places in stage_layer. No class in gptqmodel/ implements it; only test fakes did. Drive resume and commit through the extension calls that already exist and delete the attribute protocol: - restore -> LoopExtension.on_start cursor (the start_layer_index parameter of run_layer_stage goes away). - commit_layer -> LoopExtension.on_boundary. LoopBoundary.quiesce() re-raises a failed finalizer, which replaces the finalize_ok gate. - The forced synchronous drain, the forced last-processor output replay and the per-layer TensorLifetimeDiagnostic existed only for the attribute and are removed. - The packed catch-up replay and the deferred-prefix hook are removed without a replacement hook. Nothing in-tree produces a packed layer without its activation boundary: CheckpointExtension stores the InputCache with every committed step. ModuleLooper raises TypeError when a model still sets the attribute, so an external runtime fails before any work instead of quantizing without its resume and commit callbacks. In-tree runs never set the attribute, so their behaviour is unchanged. The boundary test fakes in tests/test_stage_modules.py become a LoopExtension fake that checks the resume cursor, the commit order after finalizers, and that a failed finalizer is never committed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
marked this pull request as ready for review
November 30, 2026 03:54
This was referenced Nov 30, 2026
Merged
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
…to disk for every processor (#6656) ds4rt's disk-backed layer outputs (#3588) were reachable only through per-model configure_*_store hooks that nothing in-tree calls. Make the same DiskBackedLayerOutputWriter/Sequence available to every processor through one typed field, CalibrationConfig.spill_path (map PR-G2): - spill_writer() gives each pass a private, non-durable directory (no fsync, no resume journal) that weakref.finalize removes with its sequence, or with the writer when a failed pass never finalizes it. - ForwardExecutor._output_collection spills every pass that produces all batches (replays, native capture) after the unchanged model hook; subset forwards that stop early keep their list. The first-layer capture moves each batch into a spill writer as soon as its forward returns. - The writer records each batch's device and the sequence reads it back there, so consumers see the same tensors on the same device. Deep copies share the immutable files. - ContinuationCodec stores a spilled cache as the list it replaces, so spill composes with CheckpointConfig (layer and subset steps). - The lm_head stage copies a lazy cache into lists before the in-place norm hook. - Delete TensorLifetimeDiagnostic, whose last consumer #6477 removed. spill_path=None runs none of this: GPTQ and AWQ on Qwen2.5-0.5B-Instruct are bit-identical to main. With spill on, GPTQ and AWQ on Qwen2.5-0.5B-Instruct and GPTQ on OLMoE-1B-7B are bit-identical to spill off, and peak GPU memory drops by the hidden-state sets the default path keeps resident. Co-authored-by: Claude Opus 5.5 <[email protected]>
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
Looper R6, with the maintainer's decision to fold the protocol into LoopExtensions rather than delete it. The looper had two resume and commit mechanisms:
LoopExtensions(looper/extension.py).on_startreturns aLoopPlancursor andon_boundarycommits a step afterLoopBoundary.quiesce()has drained that step's finalizers.CheckpointConfiguses it.quantization_layer_boundary_checkpoint, with six methods:restore,commit_layer,is_catchup_layer,prepare_catchup_layer,finalize_catchup_layerandmaterialize_deferred_prefix. It came from feat(looper): carry causal replay and durable recovery callbacks #3600 (771b1e0) and was probed withgetattronce inmodule_looperand six times instage_layer. No class ingptqmodel/implements it. Only test fakes intests/test_stage_modules.pydid.This PR runs resume and commit through the extension calls that already exist and deletes the attribute protocol and its probes. Net −414 lines (
5 files changed, 153 insertions(+), 567 deletions(-)). Production code is −335 lines:stage_layer.py+6/−295 andmodule_looper.py+8/−40.No in-tree run sets the attribute, so in-tree behaviour does not change.
What Changed
file:line)restore(model, processors)returned a model-layer index (module_looper.py:2034-2055);run_layer_stage(start_layer_index=)skipped lower layers (stage_layer.py:670-682)LoopExtension.on_start(context)returns aLoopPlancursor. This call already existed. Thestart_layer_indexparameter is removed.commit_layer(...)after a successful drain, gated onfinalize_ok(stage_layer.py:1544,1695-1733)LoopExtension.on_boundary(boundary)through the existingextensions.publish(step, futures).boundary.quiesce()re-raises a failed finalizer, so a failed step is never committed.finalize_okand the boolean return of_drain_finalize_futuresare removed.stage_layer.py:157-163)stage_layer.py:1068-1073)quantization_layer_output_requiredneeds them.TensorLifetimeDiagnosticper layer and processor, logged only at commit time (stage_layer.py:1046-1052)input_cache.py, where it has other users.materialize_deferred_prefix(...)after the last layer (module_looper.py:1794-1806,2133)on_startor in its laston_boundary.is_catchup_layer,prepare_catchup_layer,finalize_catchup_layer(stage_layer.py:701-723,804-832,858-1001)prepare_catchuphook (see "Why no catch-up hook" below).Deprecation (approved). An external runtime that sets
quantization_layer_boundary_checkpointon its model stops working. It is not silently ignored:ModuleLooper.__init__raisesTypeErrorbefore any work starts:This follows the fail-closed rule in AGENTS.md and the regression-test-design skill ("Do not silently accept an option the consumer ignores").
WeightOnlyLoopernever read the attribute, so it gets no guard.Why no catch-up hook. The catch-up replay re-forwarded a layer whose projections were already packed by a run that "predates activation boundaries". That is the ds4rt EXL3 projection checkpoint, which is being deprecated. Nothing in-tree produces such a layer:
CheckpointExtensionstores the completeInputCachewith every committed step. ds4rt PR-G1 (subset-granular resume) also stores the current layer's InputCache, so it does not need catch-up either.Shape left for G1. One publish site remains:
extensions.publish(planned_step, boundary_futures)at the end of each plan step, followed byon_boundary→quiesce→ commit. G1 addsLoopStep("subset", …)and a secondpublishafter each subset's finalizers on this same path. It needs no model attribute and no other probe.Out of scope.
utils/exl3_projection_checkpoint.py::inspect_committed_manifestsis documented as "the discovery half of layer-boundary catch-up". It is left to the EXL3 / ds4rt PRs.Tests
Test migration in
tests/test_stage_modules.py:test_run_layer_stage_skips_boundary_commit_when_finalize_failsbecomestest_run_layer_stage_commits_extension_boundaries_after_finalizers[3-1-False | 1-0-True], built on aLoopExtensionfake. It asserts:on_start(1);on_boundarysees each later step once, in plan order, after that step's finalizers;quiesce()with no commit, and the loop stop was still requested.test_module_looper_rejects_removed_layer_boundary_checkpoint. It fails on origin/main (DID NOT RAISE) and passes on this branch.test_deferred_boundary_prefix_materializes_once_before_publication;test_stage_layer_forces_sync_finalizers_for_durable_boundary;test_run_layer_stage_catches_up_packed_layer_with_original_forward_topology, the catch-up test, which had no in-tree producer.Call-log A/B (tiny Llama, CPU, checkpoint save + resume)
The script is
calllog_ab.py <repo> <workdir> <out.json>. It builds a 3-layer random Llama and runs GPTQ 4-bit g32 on CPU withCheckpointConfig, in four phases:CheckpointStopped;It records
LoopExtensions.start(plan steps and cursor), everypublish(step and future count),CheckpointExtension.on_boundary, everyCheckpointStore.commit(cursor and artifact names), everyrun_subset_stage(layer and subset), and a sha256 of every saved tensor.GPU A/B (GPTQ, Qwen2.5-0.5B-Instruct, checkpointing on, resume in a new process)
Setup:
run_gpu_ab.sh/gpu_resume.py, one GPU,GPTQConfig(bits=4, group_size=128), fp16, seed 0, 32 fixed calibration texts. Each tree runs two processes:CheckpointConfig, sends SIGTERM at themodel.layers.5boundary and getsCheckpointStopped;Measured Impact
Not applicable: this is a refactor with no claimed issue. The GPU and CPU A/B runs above are bit-identical.
Model Support / Module Plan
Not applicable: no model, alias or definition changes.
AWQ onboarding safety
Not applicable: AWQ grouping, search, replay and folding are not touched.
Logic Flow Documentation
file:lineevidence (What Changed).docs/repeats the diagram:docs/looper-checkpoint-redesign.md§ "Retiredquantization_layer_boundary_checkpoint". That page is not linked fromREADME.mdtoday, and this PR does not add a link.flowchart TD A["ModuleLooper.__init__"] -->|"model sets quantization_layer_boundary_checkpoint"| X["TypeError: pass a LoopExtension"] A --> B["_loop_impl builds LoopPlan"] B --> C["LoopExtensions.start: on_start returns cursor"] C --> D["run_layer_stage runs plan.steps from cursor"] D --> E["layer finalizers submitted"] E --> F["LoopExtensions.publish: on_boundary"] F --> G["boundary.quiesce"] G -->|"a finalizer failed"| Y["original error re-raised, step not committed"] G --> H["extension commits the step"] H --> D style X fill:#fee,stroke:#b22 style Y fill:#fee,stroke:#b22TypeErroronly if a method was missingTypeErrorinModuleLooper.__init__, before any workquiescere-raises.quiescere-raises (unchanged)docs/quantization-lifecycle-contracts.mdno longer mentions "layer-boundary recovery".Review Requirements
Kernel Accuracy Requirements
Not applicable: no kernel, dispatch or fusion change.
Notes
quantization_layer_boundary_checkpointmust pass aLoopExtensionthroughModuleLooper(extensions=...)instead. Its resume cursor is now aLoopPlanposition, not a model-layer index.input_embeddingswhile it skips layers;materialize_deferred_prefixcall after the last layer.publishon the remaining call site.🤖 Generated with Claude Code