Repository navigation
Description
Decision requested: make the run, rather than each looper's exception handler, responsible for returning a usable in-session model. This narrows #4615 to the boundary after a stage has already committed: the caller still owns the model even if the rest of the run fails. This is not a report that the fixed bugs still reproduce.
Why another unit case isn't enough. #5031 fixed hooks left by a post-forward stop and inference tensors left on abort. #5039 fixed the next exit window: an exception after the layer loop but before the model was usable. #5049 fixed the same in-flight placement guarantee for the weight-only looper that the calibrated looper already had. The documented caller contract exists; the problem is who enforces it. The calibrated loop has separate body and tail recovery, and the weight-only loop orders its own repairs. Each new obligation has to be remembered in several places.
Proposed contract
- One run-scoped exit owner covers layer processing and the final restore. Success is published only after the restore succeeds. Stop, exception and interrupt enter the same abort path, with obligations determined by what the run actually acquired.
- Fence submitted work before touching its inputs or releasing its storage. Restore the in-flight layer and hooks, make completed layers executable on their home device, and make unreached layers available. Repair tensor version counters after materialization. Retain offload backing while live shells need it; do not load all completed layers into RAM or copy the whole model for rollback.
- Keep cleanup idempotent and preserve the originating exception. Record secondary repair failures separately; do not claim the model is runnable if recovery itself failed. No new guarantee of retrying quantization on the same partially quantized model.
Bounded migration: start with one shared conformance fixture against today's two loopers. Then extract their common exit sequence around the existing InflightLayerTracker and offload helpers. Keep processor-specific draining/release as callbacks, migrate one looper at a time, and retire duplicate branches only after both pass the same suite. No checkpoint/API change.
Acceptance: drive tiny GPTQ and RTN runs beyond one completed layer, fail once during the next layer and once during final restore, with disk offload on and off where supported. Include the calibrated post-forward stop. Prove the intended fault fired; on successful recovery assert the original error, an ordinary grad-enabled forward, usable completed/in-flight/unreached layers, and no late worker mutation. Verify live disk shells retain their backing until release. Inject a secondary repair failure separately and assert it does not replace the primary error. Keep a successful-run control.
Activity
Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #5066
bounded migration: shared exit owner + conformance fixture for both loopers
Qubitium commentedon Nov 18, 2026
Claiming the bounded first step this issue asks for: extract the shared run-exit pieces around the existing helpers, one at a time, starting with the piece that is already asymmetrical between the two loopers.
Concrete gap found while comparing the two exit sequences:
WeightOnlyLooper.loop()submits work toDEVICE_THREAD_POOL(lines ~650 and ~708) but its failure branch never fences those submissions before_restore_inflight_layer(),rehome_failed_run_kernels()and the private offload-root release.ModuleLooper._fence_run_work()has done exactly that since #4595, and #5049's rationale ("the same guarantee the calibrated looper already has") applies verbatim.Plan for this PR (no behaviour change for the calibrated looper):
fence_submitted_work()helper that both loopers call, with the looper-specific waits passed in as callbacks.ModuleLooper._fence_run_workdelegates to it (same labels, same order, existing [BUG] #4470 only half fixed by #4515: failed quantize() returns while finalizers still run; they recreate the deleted offload run dir (orphaned bundles) and mutate the model after the exception #4595 tests keep passing).WeightOnlyLoopergains the same fence and calls it before its first repair step.main.The full "one run-exit owner" migration (body + tail unified, obligations determined by what the run acquired) stays as follow-up work on this issue.
refactor(looper): give both quantization loops one run-exit recovery …
Qubitium commentedon Nov 18, 2026
Agent claim released:
root/agent-5060is no longer working on this issue.Superseded while in progress: #5066 (branch
fix/issue-5060, another agent) implements the full bounded migration —RunExitRecoveryas the single run-scoped owner, body + tail unified, original exception preserved, abort idempotent — and already addsWeightOnlyLooper._fence_run_work(). I closed my narrower #5067 rather than leave a conflicting duplicate.What I verified before stepping back, in case it is useful for review of #5066:
DEVICE_THREAD_POOL(weight_only_looper.pypack/replace steps, ~lines 650 and 708) and its failure branch went straight to_restore_inflight_layer(),rehome_failed_run_kernels()andrelease_private_offload_root()without draining them, so a finalizer could keep packing modules afterquantize()raised and re-create the released offload directory. refactor(looper): give both quantization loops one run-exit recovery owner (#5060) #5066's_fence_run_workcovers this; I posted the two ordering properties it must keep on that PR.object.__new__, stub_loop_implto raise, substituteDEVICE_THREAD_POOLwith a pool whosewait()still writes into the run directory, and assert the call order isdevice_pool→stream_pool→inflight→base:False→materialize→rehome→counters→release_root, that the released directory is not re-created, and that a pool raising fromwait()still leaves the repairs intact with the original error. On unmodifiedmainsuch a test fails withAttributeError: type object 'WeightOnlyLooper' has no attribute '_fence_run_work'— the wholetests/test_run_exit_recovery_contract_5060.pysuite in refactor(looper): give both quantization loops one run-exit recovery owner (#5060) #5066 should cover the equivalent.test_failed_run_fence_4595.py,test_failed_run_model_state_5009.py(incl. end-to-end RTN failed runs with offload on/off), the fourtest_cancelled_quantize_*files,test_subset_cancel_hook_cleanup_4470.pyandtest_offload_base_modules_restored.py— 22 passed, 8 skipped.No repository file was changed by me and no branch of mine remains.
Qubitium commentedon Nov 18, 2026
Update: #5066 has merged (
2ea230cc5), soWeightOnlyLooper._fence_run_work()and the run-exit owner are onmain. The weight-only fence gap described in my release note above is fixed there; nothing further needed from me on this issue.