Skip to content

feat(looper): carry causal replay and durable recovery callbacks - #3600

Merged
Qubitium merged 2 commits into
ModelCloud:mainfrom
tpurtell:upstream/20-looper-causal-replay-20261108
Nov 9, 2026
Merged

Qubitium merged 2 commits into
ModelCloud:mainfrom
tpurtell:upstream/20-looper-causal-replay-20261108

Conversation

@tpurtell

@tpurtell tpurtell commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Carry the existing layer/subset replay integration: input-capture hooks, output consumers, disk-backed boundaries, committed-batch callbacks, route recovery phases, bounded release, and shared Hessian ownership. Preserve the working control flow without a new looper abstraction.

This is layer 20/36, extracted from an already-used fork for initial maintainer feedback. It depends on #3599. Review only this feature; the cross-fork Files changed view is cumulative because the PR targets upstream main.

Incremental change: 16 files, +2726/−201 lines, including carried tests and the mechanism reference. No merge is automatic. Review value and API shape first; substantial rework can follow that feedback.

Flow and existing-code boundary

flowchart TD
    S0["ForwardExecutor"]
    M0_0["ForwardExecutor.__init__"]
    S1["StageInputsCapture"]
    M1_0["StageInputsCapture.__init__"]
    S2["GPTQ"]
    M2_0["GPTQ.__init__"]
    M2_1["GPTQ.validate_module"]
    M2_2["GPTQ.process_batch"]
    E["RuntimeError, TypeError, ValueError"]
    S0 -. "exposes" .-> M0_0
    S0 -->|"raises on rejected input/state"| E
    S1 -. "exposes" .-> M1_0
    S2 -. "exposes" .-> M2_0
    S2 -. "exposes" .-> M2_1
    S2 -. "exposes" .-> M2_2
    S2 -->|"raises on rejected input/state"| E
    style E fill:#fee,stroke:#b22
Loading
Before this extraction layer Carried implementation
Previous stack layer: gptqmodel/looper/forward_executor.py:36 gptqmodel/looper/forward_executor.py:36: ForwardExecutor
Previous stack layer: gptqmodel/looper/stage_inputs_capture.py:47 gptqmodel/looper/stage_inputs_capture.py:47: StageInputsCapture
Previous stack layer: gptqmodel/quantization/gptq.py:292 gptqmodel/quantization/gptq.py:328: GPTQ

Committed reference: docs/looper-causal-replay.md, linked from README. Class entry points/calls and rejected-state paths describe code present in this branch, rather than planned integrations.

Validation

Carried test files: tests/test_stage_modules.py, tests/test_stage_inputs_capture.py, tests/test_subset_plan.py, tests/test_gptq_hessian_pipeline.py, tests/test_gptq_shared_hessian.py, tests/test_calibration_data_device.py, tests/test_quant_telemetry.py

This packaging pass checked Python parsing, whitespace, dependency order and balanced Mermaid blocks. The author reports successful prior use of these features. Per the requested resource limit and feedback-first scope, existing model quantization, GPU/ROCm tests, heavyweight CPU workloads and full model benchmarks were not rerun; no new performance or model-accuracy claim is made. Tests accompanying earlier stack layers retain their previously reported results.

tpurtell and others added 2 commits November 9, 2026 09:21
Extract the existing working fork feature for first maintainer feedback. Preserve carried code and tests; limit validation to lightweight structural checks. See the linked mechanism reference for actual API/call and failure paths.
- _build_device_thread_pool hard-coded cuda:per=4 while the new telemetry
  test asserts GPTQMODEL_CUDA_WORKERS; add _default_cuda_workers() with the
  same invalid-value fallback as the CPU override.
- forward_executor had an unused segment_start; remove it.
- The calibration dummy model needs BaseQModel.prepare_layer_replay_keep_mask
  now that the executor calls it.
- Skip the DeepSeek V4 MTP and prepare_exl3_hessian tests that depend on
  later stack layers; keep the shared-capture assertions.
- Satisfy the ruff gate.
@Qubitium
Qubitium force-pushed the upstream/20-looper-causal-replay-20261108 branch from 9bb8720 to a884b37 Compare November 9, 2026 09:22

@Qubitium Qubitium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review (layer 20)

Reviewed the incremental layer-20 commit (9bb8720bd, 16 files, +2726/−201) after rebasing onto current main. The causal replay contracts, shared Hessian state, and durable recovery callbacks are coherent. I pushed a fix commit (a884b3799).

Fixed

  1. CUDA worker env override was unimplemented. The new telemetry test asserts GPTQMODEL_CUDA_WORKERS, but _build_device_thread_pool hard-coded cuda:per: 4. Added _default_cuda_workers() with the same invalid-value fallback as the CPU override.
  2. Unused segment_start in forward_executor (ruff F841).
  3. Dummy model missed the new hook. _DummyGPTQModelForLooper now aliases BaseQModel.prepare_layer_replay_keep_mask, which the executor calls; test_output_moved_to_input_device_in_single_mode failed without it.
  4. Out-of-layer tests. test_gptq_shared_hessian.py imports prepare_exl3_hessian, which lands later; the test that needs it is skipped and the shared-capture assertions are kept.
  5. Ruff import ordering.

Verification

  • Non-calibration suites: 96 passed, 1 skipped.
  • tests/test_calibration_data_device.py: 20 passed, 2 deselected — the two TestCalibrationDataDeviceIntegration cases require a homogeneous multi-GPU host and also fail on current main on this mixed sm_89/sm_120 machine.

Notes

  • Running tests/test_calibration_data_device.py before test_gptq_hessian_pipeline.py in one process inflates the shared-factor Cholesky probe count (the test_balanced_mode_* cases patch the global DEVICE_THREAD_POOL). The hessian test passes in its own file and in isolation; this looks like pre-existing cross-file test pollution rather than a layer-20 defect, but it is worth isolating.
  • The two mixed-GPU integration tests should be made capability-aware instead of assuming a uniform device map.

@Qubitium
Qubitium marked this pull request as ready for review November 9, 2026 09:22
@Qubitium
Qubitium merged commit 771b1e0 into ModelCloud:main Nov 9, 2026
Qubitium pushed a commit that referenced this pull request Nov 12, 2026
All but one test in this file fail on main. Two changes since the file was last
touched (#3572) moved the ground it stands on.

The mocked processor auto-creates attributes, so the capture-frontier restore
hook added in #3600 looks callable and returns a truthy mock, which makes
`_run_single_subset_pass` skip the forward pass every assertion is about. A real
processor without that hook returns None, so the fixture now says so explicitly.

#3600 also added a causal replay pass: with
`execution_config.fwd_replay_after_process` set, each chunk runs one capture
forward and one replay forward, so `_run_forward_batches` is called twice per
chunk instead of once. The expectations were doubled and the comments now say
why, instead of just carrying a different number. The flush counts are unchanged:
the replay pass does not call `torch_empty_cache`.

    tests/test_moe_expert_batching.py    9 passed

Before this change the file reported 8 failed, 1 passed on main.
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.

2 participants