Skip to content

feat(checkpoint): subset-granular resume and per-module result objects in CheckpointConfig - #6492

Merged
Qubitium merged 1 commit into
mainfrom
refactor/ds4rt-subset-resume
Nov 30, 2026
Merged

Qubitium merged 1 commit into
mainfrom
refactor/ds4rt-subset-resume

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

First generic piece of the ds4rt deprecation (map PR-G1). The EXL3-only projection checkpoint is generalized into two typed CheckpointConfig fields that any processor can adopt, on the existing LoopPlan/LoopExtensions/CheckpointStore (after #6477, #6467, #6406). Plain GPTQ and RTN are the reference adopters. EXL3/ds4rt code is not touched here (PR-E1).

  • CheckpointConfig(interval="subset:<n>"): one planned step per module subset. A crash loses at most one subset instead of one layer.
  • CheckpointConfig(module_results=True) (requires "subset:1"): each module result in the running subset is stored as soon as its process() returns. A resume solves only the modules that have no stored result. The key covers identity, module, weight and statistic, so a changed Hessian always misses.

The defaults are interval="layer:1" and module_results=False. With them the LoopPlan is unchanged and no new branch runs. This was checked with a plan A/B over 24 configs and a GPU bit-identical A/B, both below. This is a feature PR, so lines go up: gptqmodel/ +437/-46, tests +348/-3, docs +57/-3. It adds no meta keys, no environment switches and no new classes. The new surface is two typed config fields, one processor flag and three processor methods with no-op defaults.

No issue is fixed. This is the planned feature step of the ds4rt deprecation.

What Changed

  • looper/checkpoint_store.py
    • CheckpointConfig.interval accepts (layer|subset):<n>, and CheckpointConfig.module_results: bool = False is new. Using module_results without "subset:1" raises ValueError.
    • The property interval_layers is replaced by interval_steps (the count is plan steps), and subset_steps is added.
    • CheckpointStore.put_result / result_path / drop_results: results/<key> names a content-addressed object. collect() keeps those objects reachable until the next commit drops them. A damaged entry counts as a miss.
  • looper/extension.py
    • LoopBoundary.pending holds the processed but not yet finalized modules of the running layer.
    • LoopExtensions.publish(step, futures, pending=None).
    • LoopExtensions.subset_steps and module_results are new properties.
  • looper/checkpoint.py (CheckpointExtension)
    • Commits every interval_steps steps.
    • With subset steps, on_start rejects, before restore, a processor without checkpoint_subset_boundaries or a multi-processor chain.
    • In subset mode it passes boundary.pending to adapter.capture. Layer mode still calls capture() unchanged.
    • New methods: restored_result, result_key, load_result, save_result. A commit drops the result cache.
  • looper/gptq_checkpoint.py
    • capture(pending=None) stores module_result_state_dict() for each pending module under the continuation key "pending". This key is only present for subset steps.
    • restore hands the stored results back through restored_results.
    • capture skips AutoNF12HookedLinear, the transient forward-only NF12 view of an untouched source weight. These views exist inside a running layer on CUDA, and before this change their capture failed restore with checkpoint module kernel is unavailable.
  • looper/module_looper.py, looper/weight_only_looper.py: plans add LoopStep("subset", L, "<layer>:subset<g>") for each group of layer_module_groups() before the layer step, but only when an extension asks for subset steps. The weight-only loop now finds steps by object rather than by plan.steps[layer_index].
  • looper/stage_subset.py
    • layer_module_groups() is extracted from build_layer_subset_plans, so the plan and the runtime share one source.
    • SubsetPlan.group_index is new.
    • _collect_worker_results(on_result=) saves each result in submission order as soon as it resolves.
    • The process phase loads a cached result instead of submitting process() when result_key hits.
  • looper/stage_layer.py
    • Subset steps are published after each group, and empty groups are published together with the next group.
    • A subset committed before this run is neither forwarded nor solved. Its modules go through _prepare_named_module_for_quantization, which uses the memoized device so placement is unchanged, and then load_module_result_state_dict.
  • looper/loop_processor.py: no-op defaults checkpoint_subset_boundaries = False, module_result_statistic(), module_result_state_dict() and load_module_result_state_dict(). Also module_stat_row() / restore_stat_row(), so a restored result republishes its quant-log row once.
  • looper/gptq_processor.py
    • Plain GPTQ implements the four. The statistic is GPTQ.snapshot_hessian(). The result holds the replay weight, q_scales, q_zeros, q_g_idx, the optional pack_wq and the stat row.
    • Runs that keep state elsewhere opt out: EoRA (calculate_w_wq_diff), W4A activation modes, GSQ, ADMM-Q, and G2PTQProcessor (pristine-layer refresh).
  • looper/weight_only_processor.py: checkpoint_subset_boundaries = True, because the weight-only looper packs every subset before its boundary.
  • docs/looper-checkpoint-redesign.md: new section "Subset steps and module results" with the flow diagram and table.
  • Out of scope, as follow-ups from the map:
    • Statistics boundary (G1b).
    • Adoption by AWQ/QQQ/MACaQ/Paro (A1).
    • EXL3 moving to this mechanism and retiring the ds4rt switches (E1).
    • Deduplicating the per-subset continuation (input cache and the running layer's dense tensors are rewritten by each subset commit; see Notes).

Tests

  • Unit tests have been executed and passed, or the reason they are not applicable is documented.
  • I added a new simple/fast unit test for this change, or documented why that is not applicable.

New tests:

Node Pins
tests/test_checkpoint_quantization.py::test_quantized_tensors_equal_after_subset_resume[llama-gptq, llama-rtn, qwen3_moe-gptq, qwen3_moe-rtn, llama-gptq-last-subset, llama-gptq-cuda, qwen3_moe-gptq-cuda] SIGTERM at the model.layers.1:subset1 boundary (or :subset3, the last one). Resume runs process()/RTN only for the remaining layer-1 groups, and every saved tensor is bit-identical to a run without a checkpoint.
tests/test_checkpoint_quantization.py::test_module_results_skip_solved_experts_after_kill Subprocess SIGKILL after 3 of the 8 layer-1 expert gate/up results of tiny Qwen3-MoE are stored. Resume calls process() for exactly the other 5, never for layer 0 or attention, and the output is bit-identical.
tests/test_checkpoint_quantization.py::test_module_result_misses_when_hessian_changes The same interruption in-process. A control resume solves 5 of 8. Scaling only the layer-1 expert Hessian inputs makes all 8 miss.
tests/test_checkpoint_quantization.py::test_checkpoint_plan_steps[layer:1, subset:1] Exact plan.steps: the default is layer steps only, and subset mode is 4 subset steps plus the layer step per layer.
tests/test_checkpoint_store.py::test_invalid_config, test_checkpoint_config_defaults_and_interval, test_module_results_live_until_dropped Config grammar; the cache survives collect() until drop_results().
tests/test_checkpoint_extension.py::test_subset_interval_rejects_processors_without_subset_boundaries[...] Rejection happens before the adapter binds.

Red evidence: each defect below was injected in a disposable worktree and the run failed at the intended assertion.

Injected defect Failing node Failure
Committed subsets re-run (if False: on the restore branch) subset_resume[llama-gptq], [qwen3_moe-gptq] processed includes self_attn.q_proj/o_proj
Result key ignores the statistic test_module_result_misses_when_hessian_changes assert 5 == 8
Restored modules not prepared before the result loads subset_resume[llama-gptq-cuda] model.layers.1.mlp.gate_proj.qweight differs
Neither the result weight nor the running layer's dense tensors restored subset_resume[llama-gptq] model.layers.1.self_attn.q_proj.qweight differs
No transient-NF12 skip in capture (first version of this branch) subset_resume[*-gptq-cuda] CheckpointError: checkpoint module kernel is unavailable: ...AutoNF12HookedLinear

(Dropping only the result weight, or only the running layer's dense tensors, still passes. Each one restores the processed weights on its own.)

# affected families, CPU (CUDA_VISIBLE_DEVICES="")
PYTHONPATH=$PWD python -P -m pytest -q -n 8 -p no:cacheprovider -rs \
  tests/test_checkpoint_extension.py tests/test_checkpoint_store.py tests/test_checkpoint_processor_adapter.py \
  tests/test_checkpoint_quantization.py tests/test_checkpoint_method_compatibility.py \
  tests/test_checkpoint_continuation_stream_5749.py tests/module_tree/test_subset.py tests/test_awq_balanced_moe_5104.py \
  tests/test_awq_balanced_moe_group_5104.py tests/test_awq_moe_prune_uncovered_4456.py tests/test_backend_config_reuse_4446.py \
  tests/test_checkpoint_devices.py tests/test_checkpoint_gpu_identity.py tests/test_checkpoint_telemetry.py \
  tests/test_failed_run_model_state_5009.py tests/test_host_memory_trim_4990.py tests/test_layer_module_coverage.py \
  tests/test_loop_extensions.py tests/test_looper_concurrency.py tests/test_looper_helpers.py tests/test_moe_expert_batching.py \
  tests/test_moe_prune_nf12_save_4349.py tests/test_offload_quantized_modules_restored_4450.py tests/test_quant_log_coverage_4321.py \
  tests/test_quantize_in_session_4381.py tests/test_resume_first_capture_release_5829.py tests/test_rtn_nemotron_h_identity_5270.py \
  tests/test_run_exit_recovery_contract_5060.py tests/test_stage_modules.py tests/test_subset_declared_order_4679.py \
  tests/test_subset_plan.py tests/test_weight_only_failed_run_device_5011.py tests/test_weight_only_looper.py \
  tests/test_weight_only_tied_lm_head_5027.py tests/test_checkpoint_resume_nonpersistent_4777.py \
  tests/test_checkpoint_state_invariant.py tests/test_checkpoint_driver_guard.py tests/test_exl3_projection_checkpoint.py \
  tests/test_checkpoint_modules.py tests/test_checkpoint_compat.py
# 582 passed, 137 skipped in 541s

# opt-in subprocess recovery matrix (every checkpoint-capable method, layer:1), CUDA_VISIBLE_DEVICES=0
PYTHONPATH=$PWD python -P -m pytest -q -n 6 -p no:cacheprovider -rs -m checkpoint_recovery tests/test_checkpoint_method_compatibility.py
# 73 passed, 15 skipped in 409s (14 need two CUDA devices, 1 needs BitBLAS)

# single-GPU nodes that the CPU run skipped, CUDA_VISIBLE_DEVICES=0
PYTHONPATH=$PWD python -P -m pytest -q -n 4 -p no:cacheprovider -rs tests/test_checkpoint_telemetry.py \
  tests/test_checkpoint_processor_adapter.py tests/test_checkpoint_state_invariant.py tests/test_checkpoint_devices.py \
  tests/test_offload_quantized_modules_restored_4450.py tests/test_weight_only_failed_run_device_5011.py \
  tests/test_quant_log_coverage_4321.py tests/test_awq_moe_prune_uncovered_4456.py tests/test_checkpoint_gpu_identity.py
# 130 passed, 20 skipped

bash format/check.sh   # All checks passed! (ruff 0.14.2)

Skips and what they leave unverified:

  • CPU run (137 skipped): CUDA-only nodes, and the 9 opt-in checkpoint_recovery files. Both groups were then run on GPU 0, above.
  • Still unverified on any run:
    • Every node that needs two CUDA devices: 14 recovery-matrix cases, test_checkpoint_devices multi-GPU restore, the test_awq_balanced_moe* placement tests, and the cuda:1 telemetry/adapter nodes. Multi-GPU placement after a subset resume is therefore not exercised. The memoized per-module device map makes it deterministic by construction, but that is untested.
    • BitBLAS, Machete and Swordfish runtimes (unavailable on this host).
    • module_results on CUDA. The kill/tamper tests run on CPU only; subset resume itself runs on CUDA.

Structural A/B (default plan unchanged)

plan_ab.py patches LoopExtensions.start, records every LoopPlan.steps the loopers build, and runs the same script on origin/main and on this branch. It covers 3 tiny families (llama, qwen3_moe, qwen2_untied, 3 layers) × {GPTQ, RTN} × {no dynamic, last layer excluded by -:} × {checkpoint off, CheckpointConfig() default}, which is 24 configs. Result: identical (sha256 c8a06e8e6a73bf07… on both trees).

GPU A/B (checkpointing off)

gpu_ab.py was run on origin/main (126e83f) and on this branch with an identical config. Setup:

  • One GPU (CUDA_VISIBLE_DEVICES=0), seed 0.
  • Fixed 32 × 64-token calibration, batch_size=4.
  • BACKEND.TORCH, default offload_to_disk.
  • One in-session forward, then save.
Job Tensors Files Result
GPTQ 4-bit, g128, Qwen2.5-0.5B-Instruct 794 safetensors, config/quantize_config/generation_config/tokenizer jsons, chat template bit-identical; jsons byte-equal; in-session logits sha256 equal
RTN 4-bit, g128, Qwen2.5-0.5B-Instruct 794 same bit-identical; jsons byte-equal; logits equal
GPTQ 4-bit, g32, tiny Qwen3-MoE (3 layers, 8 experts, fp16, ExpertsRoutingOverride) 354 same bit-identical; jsons byte-equal; logits equal

Measured Impact

Not applicable. No issue is claimed. With the defaults, quantization output is bit-identical and no new code runs. Subset-mode cost is described under Notes; it was not benchmarked.

Model Support / Module Plan

Not applicable. No model, alias, definition or module tree changes.

AWQ onboarding safety

Not applicable. AWQ is not touched. It keeps layer boundaries, and "subset:<n>" is rejected for it in on_start.

Logic Flow Documentation

  • The required diagrams and docs page are included below.
  • New-flow Mermaid diagram(s) describe the shipped code using real symbol names.
  • The replaced mechanism is tabulated with file:line evidence.
  • Failure and ambiguity paths are marked and visually distinct from success.
  • A reference page under docs/ repeats the diagrams, titled for the mechanism, and is linked from docs/README.md.
flowchart TD
    A["ModuleLooper / WeightOnlyLooper build LoopPlan"] -->|"interval subset:n"| B["per layer: subset steps, then layer step"]
    A -->|"interval layer:n"| C["layer steps only, unchanged"]
    B --> D["CheckpointExtension.on_start"]
    D -->|"processor lacks checkpoint_subset_boundaries<br/>or several processors"| X["NotImplementedError"]
    D --> E["run_layer_stage from cursor"]
    E -->|"subset committed before this run"| F["_prepare_named_module_for_quantization<br/>load_module_result_state_dict"]
    E -->|"subset to run"| G["subset forward, then per module"]
    G -->|"module_results and result_key hits"| H["load_result, skip process"]
    G -->|"miss"| I["process, then save_result"]
    F --> J["publish subset step with pending modules"]
    H --> J
    I --> J
    J --> K["adapter.capture stores module_result_state_dict of pending"]
    K -->|"commit"| L["drop_results"]
    F -->|"no stored result"| Y["RuntimeError"]
    style X fill:#fee,stroke:#b22
    style Y fill:#fee,stroke:#b22
Loading
Decision origin/main This PR
Interval grammar re.fullmatch(r"layer:(\d+)") (checkpoint_store.py:50) (layer|subset):(\d+) plus module_results (checkpoint_store.py:55-64)
Plan steps LoopStep("layer", ...) only (module_looper.py:2052, weight_only_looper.py:1066) adds LoopStep("subset", ...) per layer_module_groups() group when an extension asks (module_looper.py:2058)
Commit frequency interval_layers (checkpoint.py:143) interval_steps (checkpoint.py:199)
Boundaries inside a layer none; publish only after finalizers (stage_layer.py:1456) publish_subset_steps after each group with pending (stage_layer.py:943)
Resume inside a layer the whole layer replays from its inputs committed subsets load restored_result (stage_layer.py:958)
A module inside the running subset always process() result_key hit loads the stored result (stage_subset.py:1592)
Weight-only resume skip layer_index < start_step (weight_only_looper.py:1082) layer_step in committed, and the same per group (weight_only_looper.py:1097, :1172)
Situation layer:1 (before and after) subset:1 subset:1 + module_results
Crash in layer L, subset s replay layer L replay from subset s replay from subset s
Crash after k of m modules of subset s are solved m solved again m solved again m - k solved again
Changed calibration or config identity mismatch, resume refused same same; a changed Hessian also misses the key

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

Not applicable. No kernel, packer or dispatch changes.

Notes

  • Cost of subset:1. Each subset commit rewrites the full continuation, including the layer input cache and the running layer's materialized tensors. The processed weights are stored twice, once in the dense capture and once in the result. Referencing the input cache by digest and dropping duplicated weights are follow-ups; neither was measured here. module_results=True also hashes each module's weight and a CPU snapshot of its Hessian before process().
  • Scope of the adopters. Subset steps need a single-processor chain. Plain GPTQ adopts both features. RTN/weight-only adopts subset steps; it has no statistic, so its results are never cached. AWQ, QQQ, MACaQ, Paro, EXL3 and G2PTQ keep layer boundaries until their adoption PRs (A1, E1).
  • API change. CheckpointConfig.interval_layers is renamed to interval_steps. Its only in-tree reader was checkpoint.py, and tests/test_checkpoint_store.py is updated.
  • AUTO_NF12. The AutoNF12HookedLinear skip in capture only matters at subset boundaries. At layer boundaries no such view remains in the tree, and the default-path A/B above is unchanged.
  • quant_log row order. Rows of reused modules are republished before the rows of modules solved on resume, so the row order inside one subset can differ from an uninterrupted run. Row order inside a subset already depends on worker completion order.

🤖 Generated with Claude Code

…s in CheckpointConfig

First generic piece of the ds4rt deprecation (map PR-G1): the EXL3-only
projection checkpoint becomes two typed CheckpointConfig fields that any
processor can adopt. GPTQ and RTN are the reference adopters; EXL3 is not
touched here (PR-E1).

- CheckpointConfig.interval accepts "subset:<n>". The ModuleLooper and
  WeightOnlyLooper plans then carry LoopStep("subset", layer,
  "<layer>:subset<g>") for every group of layer_module_groups() before each
  layer step. run_layer_stage publishes a subset step after the group's
  process() (empty groups publish with the next group) and passes the
  processed but unfinalized modules as LoopBoundary.pending. The adapter
  stores their module_result_state_dict() in the continuation; on resume a
  committed subset is not forwarded or solved, its modules are placed as
  before (memoized device) and loaded from the stored result.
- CheckpointConfig.module_results (requires "subset:1") stores each solved
  module of the running subset under sha256(identity, module, weight,
  statistic) in <checkpoint>/results as soon as its process() returns. A
  resume re-forwards the subset and calls process() only on a miss, so a
  changed Hessian can never reuse a stale result. A commit drops the cache.
- LoopProcessor gains no-op defaults: the checkpoint_subset_boundaries flag,
  module_result_statistic(), module_result_state_dict() and
  load_module_result_state_dict(). Plain GPTQ implements them (G2PTQ, EoRA,
  W4A, GSQ and ADMM-Q opt out); weight-only declares the flag because it packs
  every subset before its boundary. CheckpointExtension.on_start rejects
  "subset:<n>" for other processors or multi-processor chains before restore.
- The capture skips transient AUTO_NF12 forward views (AutoNF12HookedLinear)
  of untouched source weights, which exist inside a running layer on CUDA.
- interval_layers becomes interval_steps (the count is plan steps).

With the defaults (interval="layer:1", module_results=False) the LoopPlan
is unchanged and none of the new branches run: a plan A/B over 24
configurations is identical, and GPTQ/RTN Qwen2.5-0.5B plus a tiny
Qwen3-MoE quantized on one GPU with checkpointing off are bit-identical
to origin/main. This is a feature PR, so production lines go up (+437/-46).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread gptqmodel/looper/loop_processor.py Resolved
@Qubitium
Qubitium marked this pull request as ready for review November 30, 2026 11:10
@Qubitium
Qubitium merged commit 99fd14d into main Nov 30, 2026
6 checks passed
@Qubitium
Qubitium deleted the refactor/ds4rt-subset-resume branch November 30, 2026 11:11
Qubitium added a commit that referenced this pull request Dec 1, 2026
…6506)

`tests/test_docs_contract_refs.py` had 8 failures on main:

- docs/cancelled-run-contract.md (+ the citation table) still cited
  `_copy_checkpoint_tensors_into_submodule` / `_publish_checkpoint_param_`
  in gptqmodel/utils/structure.py; #6473 moved both to
  gptqmodel/weight_loader/source.py.
- docs/weight-loader.md blocks 0/1 (#6473) executed on a CPU-only host:
  a two-accelerator `accel:0`/`accel:1` placement map and a continuation
  that needs `model` and a real checkpoint. Skip-listed with reasons.
- docs/measurement.md block 3 is a continuation snippet (prose-defined
  `texts`, `tokenizer`, models); skip-listed.
- Skip-list digests refreshed for docs/calibration-config.md::0 (#6500
  added `exclude_attention_sinks=None`) and
  docs/looper-checkpoint-redesign.md::0 (#6492 added subset intervals);
  both reasons still hold.

The eighth, docs/jit-kernel-builds.md::0, is fixed in #6505.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant