Skip to content

fix(looper): fence a failed weight-only run's submitted work, via one shared exit helper (#5060) - #5067

Closed
Qubitium wants to merge 1 commit into
ModelCloud:mainfrom
Qubitium:fix/5060-looper-fence
Closed

Qubitium wants to merge 1 commit into
ModelCloud:mainfrom
Qubitium:fix/5060-looper-fence

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

First step of #5060's bounded migration. Does not close the issue.

Problem

ModuleLooper has drained the work a failed run already submitted since #4595 — DEVICE_THREAD_POOL, its finalizer watcher threads and STREAM_DEVICE_POOL — before it restores the in-flight layer or releases the per-run offload root.

WeightOnlyLooper submits submodule finalizers to the same pool (the pack/replace steps, weight_only_looper.py:650 and :708) but its failure branch went straight to _restore_inflight_layer(), rehome_failed_run_kernels() and release_private_offload_root().

That is the #4595 defect class in the other looper: a finalizer the run already submitted keeps packing and replacing modules after quantize() has raised, and re-creates the offload directory the teardown just removed (one leaked bundle set per failed run). #5049 made the same "the calibrated looper already guarantees this" argument for the in-flight placement, and this issue's contract states the obligation for both loopers.

Change

The identical part of the two exit sequences now lives in gptqmodel/looper/run_exit.py, so a new obligation is added once instead of twice:

Calibrated-looper behaviour is unchanged. The rest of #5060 — one run-exit owner covering body and tail, with obligations derived from what the run actually acquired — remains as follow-up; this PR is the "extract their common exit sequence around the existing helpers" step, done one piece at a time.

Verification

tests/test_failed_run_fence_5060.py drives the weight-only exit path with a pool that is still writing when the run fails:

  • asserts the drain runs before _restore_inflight_layer() and before the offload root is released, and that the released directory is not re-created;
  • asserts a wedged drain neither skips the repairs nor replaces the run's exception;
  • asserts both loopers delegate to the same helper.

All three nodes fail on unmodified main (AttributeError: type object 'WeightOnlyLooper' has no attribute '_fence_run_work').

Green with the change:

  • tests/test_failed_run_fence_5060.py + tests/test_failed_run_fence_4595.py: 6 passed.
  • tests/test_failed_run_model_state_5009.py (incl. the end-to-end RTN failed-run cases with offload on/off), test_cancelled_quantize_layer_cleanup_4546.py, test_cancelled_quantize_default_offload_4860.py, test_cancelled_quantize_disk_offload_4807.py, test_cancelled_quantize_kernel_rehome_4947.py, test_subset_cancel_hook_cleanup_4470.py, test_offload_base_modules_restored.py: 22 passed, 8 skipped.
  • ruff check clean.

… shared exit helper (ModelCloud#5060)

`ModuleLooper` has drained the work a failed run already submitted since
ModelCloud#4595: `DEVICE_THREAD_POOL`, its finalizer watcher threads and
`STREAM_DEVICE_POOL`, before it restores the in-flight layer or releases the
per-run offload root. `WeightOnlyLooper` submits submodule finalizers to the
same pool (the pack/replace steps) but its failure branch went straight to
`_restore_inflight_layer()`, `rehome_failed_run_kernels()` and
`release_private_offload_root()`.

That is the ModelCloud#4595 defect class in the other looper: a finalizer the run already
submitted keeps packing and replacing modules after `quantize()` has raised,
and re-creates the offload directory the teardown just removed (one leaked
bundle set per failed run). ModelCloud#5049 made the same "the calibrated looper already
guarantees this" argument for the in-flight placement.

This is the first step of ModelCloud#5060's bounded migration: the identical part of the
two exit sequences now lives in `gptqmodel/looper/run_exit.py`, so a new
obligation is added once instead of twice.

- `fence_submitted_work()` / `run_exit_waits()` own the waits and the
  "each wait is independent, never mask the run error" policy.
- `ModuleLooper._fence_run_work()` delegates to it with the same waits, labels
  and order; it still passes its module-level `DEVICE_THREAD_POOL` so a
  substituted pool keeps taking effect (the ModelCloud#4595 tests are unchanged).
- `WeightOnlyLooper` gains the same fence and calls it before its first repair
  step. It has no finalizer watcher threads, so only the two pools apply.

Behaviour for the calibrated looper is unchanged. The rest of ModelCloud#5060 (one
run-exit owner covering body and tail, obligations derived from what the run
acquired) stays as follow-up.

`tests/test_failed_run_fence_5060.py` drives the weight-only exit path with a
pool that is still writing when the run fails: it asserts the drain happens
before the in-flight restore and before the offload root is released, that the
released directory is not re-created, and that a wedged drain neither skips the
repairs nor replaces the run's exception. All three nodes fail on unmodified
`main` (`WeightOnlyLooper` has no fence at all). The ModelCloud#4595 suite, the
cancelled-run suite and the end-to-end RTN failed-run cases stay green.
@Qubitium

Copy link
Copy Markdown
Collaborator Author

Closing as superseded by #5066, which another agent opened for this issue while I was working on it.

#5066 implements the full bounded migration (RunExitRecovery, one run-scoped owner, body + tail unified) and already adds WeightOnlyLooper._fence_run_work() with the DEVICE_THREAD_POOL + STREAM_DEVICE_POOL waits — the exact gap this PR targeted, and the same "extract the common exit sequence" step. Keeping both would conflict in weight_only_looper.py and leave two fences.

The finding that motivated this branch is still worth recording on the issue: before #5066, WeightOnlyLooper.loop() submitted finalizers to DEVICE_THREAD_POOL and its failure branch never drained them, so it had the #4595 defect class. #5066's version of _fence_run_work fixes that. One detail to keep from this branch when #5066 lands: the fence must be called as the first step of the abort path, before _restore_inflight_layer() and before release_private_offload_root(), and it must never raise (a wedged pool is logged, not propagated) so it cannot mask the run's exception.

Nothing from this branch is needed beyond that; the regression test I wrote is subsumed by tests/test_run_exit_recovery_contract_5060.py.

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