Repository navigation
refactor(looper): share run teardown between ModuleLooper and WeightOnlyLooper - #6465
Merged
Merged
Conversation
…nlyLooper ModuleLooper and WeightOnlyLooper each carried their own copy of the run exit steps that RunExitRecovery drives (fence, restore offloaded/disk modules, materialize meta modules, release processors/workspace, keep or release the private offload root, bind the private offload namespace) and of quant-device assignment. The copies differed only in data: log wording, telemetry event prefix, the processor list, the fence's extra watcher wait, ModuleLooper's deferred-weight step, WeightOnly's base-module fill and its release order. Move the single implementation onto the bases both loopers already inherit: - DeviceAssignmentState: _cross_device_pool, _assign_quant_device_for_module (event names come from _quant_device_event_prefix). - InflightLayerTracker: every shared exit step plus _make_run_exit_recovery, which builds RunExitRecovery from the shared steps and takes per-looper overrides as keyword steps. Each looper now declares only its differences: _run_processors(), the _fence_run_label/_kept_root_run_label wording, the event prefix and _release_processors_before_restore. ModuleLooper adds its watcher-thread fence wait and deferred runtime weights; WeightOnlyLooper overrides _materialize_meta_modules to fill its base modules first. Log text, telemetry event names, step order and strictness are unchanged. Tests that patched module globals now patch them in inflight_layer, where the shared steps resolve them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
marked this pull request as ready for review
November 30, 2026 02:29
Qubitium
added a commit
that referenced
this pull request
Nov 30, 2026
…d teardown Rebased fix/6148-issue onto origin/main 94ceaf7 (after #6464, #6465, #6467, #6469, #6470). Three conflicts: - gptqmodel/looper/forward_executor.py: import block. Main dropped the unused resolve_calibration_keep_mask import; kept only the PR's replay_records import. - gptqmodel/looper/module_looper.py: #6465 moved the failed-run teardown into InflightLayerTracker (inflight_layer.py). Kept main's structure and re-applied the PR's release_looped_capture() as a ModuleLooper override of _release_failed_run_processors that calls super() first. - gptqmodel/models/definitions/inkling2_loop.py: #6464 reduced pre_quantize_generate_hook_start to the batch-index/bank reset plus super(); the PR removes that reset, so the override is deleted. Earlier rebase (onto 81ac176): Rebased fix/6148-issue onto origin/main 81ac176. Two conflicts: - gptqmodel/models/definitions/inkling2_loop.py: import block. Kept the PR's replay_records imports; dropped the PR's get_op_name import because main removed its last use and the rebased file does not use it. - tests/module_tree/test_inkling2_loop_plan.py: main added the AWQ declaration block where the PR deletes _capture_inkling2_forward. Kept all of main's AWQ tests, removed only the helper the PR replaced with record-owned head banks. Tests: 135 passed, 1 skipped on CPU (main baseline for the pre-existing files: 124 passed). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
added a commit
that referenced
this pull request
Dec 1, 2026
…d teardown Rebased fix/6148-issue onto origin/main 94ceaf7 (after #6464, #6465, #6467, #6469, #6470). Three conflicts: - gptqmodel/looper/forward_executor.py: import block. Main dropped the unused resolve_calibration_keep_mask import; kept only the PR's replay_records import. - gptqmodel/looper/module_looper.py: #6465 moved the failed-run teardown into InflightLayerTracker (inflight_layer.py). Kept main's structure and re-applied the PR's release_looped_capture() as a ModuleLooper override of _release_failed_run_processors that calls super() first. - gptqmodel/models/definitions/inkling2_loop.py: #6464 reduced pre_quantize_generate_hook_start to the batch-index/bank reset plus super(); the PR removes that reset, so the override is deleted. Earlier rebase (onto 81ac176): Rebased fix/6148-issue onto origin/main 81ac176. Two conflicts: - gptqmodel/models/definitions/inkling2_loop.py: import block. Kept the PR's replay_records imports; dropped the PR's get_op_name import because main removed its last use and the rebased file does not use it. - tests/module_tree/test_inkling2_loop_plan.py: main added the AWQ declaration block where the PR deletes _capture_inkling2_forward. Kept all of main's AWQ tests, removed only the helper the PR replaced with record-owned head banks. Tests: 135 passed, 1 skipped on CPU (main baseline for the pre-existing files: 124 passed). 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
Debloat refactor (behavior-preserving):
ModuleLooperandWeightOnlyLoopereach kept their own copy of the run-exit steps thatRunExitRecoverydrives, plus quant-device assignment. The copies differed only in data. This PR keeps one implementation on the bases both loopers already inherit, and each looper now declares only what is different about it. No new classes, mixins or registries.No issue is fixed. This is a debloat refactor.
What Changed
gptqmodel/looper/execution_state.py(DeviceAssignmentState, already shared): now owns the single_cross_device_pooland_assign_quant_device_for_module. Telemetry event names come from_quant_device_event_prefix(""/"weight_only_").gptqmodel/looper/inflight_layer.py(InflightLayerTracker, already the run-exit base): now owns the single_bind_private_offload_namespace,_restore_offloaded_base_modules,_restore_disk_offloaded_modules,_materialize_remaining_meta_modules,_materialize_unreached_meta_modules,_release_run_workspace,_release_failed_run_processors,_fence_run_work(*extra_waits),_release_or_keep_private_offload_rootand_make_run_exit_recovery(**steps)._run_processors()(self.processors/(self.processor,)).ModuleLooper:_make_run_exit_recoveryadds the finalizer-watcher fence wait andrestore_deferred. The_finalize_deferred_runtime_weightshook-probe site is not touched, so it stays clear of R2.WeightOnlyLooper:_quant_device_event_prefix,_fence_run_label,_kept_root_run_label,_release_processors_before_restore = False, and an override of_materialize_meta_modulesthat fills its base modules first. That is the samestrict=Falseon abort andstrict=Trueon success as before._release_run_workspaceused to probegetattr(processor, "release_run_workspace"). It now calls the method directly, asModuleLooperalready did. Every real processor is aLoopProcessor, andLoopProcessordefines the method. Only duck-typed test fakes differ, and the fake intests/test_weight_only_looper.pynow implements the method.inflight_layer, because the shared steps look them up there:test_failed_run_fence_4595,test_failed_run_device_smi_cleanup_4813,test_weight_only_failed_run_device_5011,test_exl3_workspace_release,test_post_loop_tail_failure_5023. Each is a patch-target change only, and the assertions are unchanged. The 5011 stub processor also getsrelease_run_workspace, and the test now asserts that it runs last.scripts/repro_issue_2326.py: its fake looper borrowsModuleLooper._assign_quant_device_for_module, so it now also declares the event prefix._loop_impl(genuinely different pipelines),_finalize_deferred_runtime_weightsand the other processor hook probes (R2).git diff --shortstat origin/main: 12 files changed, 330 insertions(+), 406 deletions(-). That breaks down asgptqmodel/+249/-381 (net -132) and tests/scripts +81/-25, mostly the new guard test.Tests
New guard:
tests/test_run_exit_recovery_contract_5060.py::test_shared_exit_steps_keep_each_loopers_wording[ModuleLooper-...]and[WeightOnlyLooper-...]. They assert each looper's exact fence-drain warnings (including the watcher wait forModuleLooperonly), the kept-root debug line and the*quant_device_{preferred_hint,assign,cache_hit}event names. Mutation check: changing the weight-only label to"weight only run"and the prefix to"weightonly_"makes the test fail at the wording assertion.Family A/B. I ran all 88 non-
tests/models/test files that reference either looper, on origin/main (1c51b32) and on this branch, with an identical command (CPU,CUDA_VISIBLE_DEVICES=""):Teardown files run on their own on the branch (all pass):
tests/test_failed_run_fence_4595.py tests/test_run_exit_recovery_contract_5060.py tests/test_weight_only_failed_run_device_5011.py tests/test_failed_run_device_smi_cleanup_4813.py tests/test_exl3_workspace_release.py tests/test_cancelled_quantize_default_offload_4860.py tests/test_cancelled_quantize_disk_offload_4807.py tests/test_post_loop_tail_failure_5023.py tests/test_exl3_cancelled_run_5083.py tests/test_checkpoint_devices.py tests/test_weight_only_looper.py tests/test_layer_module_coverage.py.The one failure is
tests/test_looper_processor_capabilities.py::test_gptq_never_inherits_previous_calibration. It fails the same way on clean origin/main when run alone:SimpleNamespacehas nocalibration_dataset_owner. It comes from a stale test after #6422 and is unrelated to this PR.Skips (113, identical on both trees) are CUDA-only nodes, mainly:
test_exl3_cancelled_run_5083(EXL3 needs NVIDIA)test_weight_only_failed_run_device_5011:116(needs an accelerator)test_checkpoint_devicesmulti-GPU restoretest_calibration_data_devicemulti-GPUAccelerator-placement recovery for the cancelled EXL3 / weight-only device runs is therefore not verified by these runs. The GPU A/B below covers only the success path on one GPU.
Structural A/B (
teardown_ab.py, run on both trees). It patches every pool and offload helper in whichever module owns it on that tree, then records the full event sequence, rendered log text, telemetry names,RunExitRecoverywiring (which steps are set, plus release order),failures,completedandrecovered. It covers both loopers × {success, raise, StopMainLoop, wedged pools, disk-kept root, unreached-materialize failure, success-path materialize failure}, device assignment (single, round-robin, preferred hint as device and as string, hint outside the pool,Nonedevice, CPU pool, cache hits),_cross_device_pooland private-namespace rebinding. Output: identical JSON (sha256 b2492c29…), excluding thegptqmodel.__file__line.GPU A/B on one GPU: Qwen2.5-0.5B-Instruct, fp16,
group_size=128, defaultoffload_to_disk=True, seed 0, fixed 32-row calibration. GPTQ 4-bit and RTN 4-bit each quantized on both trees, followed by one in-session forward, then save:bash format/check.sh: All checks passed (ruff 0.14.2).Measured Impact
Not applicable: no runtime behavior change.
Model Support / Module Plan
Not applicable: no model, definition or module-plan change.
AWQ onboarding safety
Not applicable: AWQ is not touched.
Logic Flow Documentation
Not applicable: the
RunExitRecoverystep order and the quant-device selection order are unchanged. What moved is where the step bodies live, and per-looper copies became class-attribute data. The table below maps old to new (old line numbers at 1c51b32).docs/cancelled-run-contract.mdstill describes the sequence, so no docs page is needed._cross_device_pool_assign_quant_device_for_module_quant_device_event_prefix_bind_private_offload_namespace_run_processors()_materialize_unreached_meta_modules_materialize_meta_modules(strict); weight-only override_fence_run_work*extra_waits,_fence_run_label_release_or_keep_private_offload_root_kept_root_run_label_make_run_exit_recoveryfenceandrestore_deferred; weight-only uses_release_processors_before_restore = FalseReview Requirements
Kernel Accuracy Requirements
Not applicable: no kernel change.
Notes
InflightLayerTrackernow owns all of the looper-side exit steps, not just in-flight tracking. A rename (e.g.RunExitSteps) would be a separate, purely cosmetic follow-up.ModuleLooper's success-path materialize step now resolves_materialize_remaining_meta_moduleswhen it is called, not when the recovery object is built. This matches how weight-only already worked, and only differs if someone patches the method in the middle of a run._make_run_exit_recoverysits next to_finalize_deferred_runtime_weights, so a textual rebase may be needed.🤖 Generated with Claude Code