Repository navigation
fix(looper): fence submitted work before tearing down a failed run (#4595) - #4631
Merged
Merged
Conversation
The failure branch of ModuleLooper.loop() restored the model and deleted the per-run offload directory while submodule finalizers already submitted to DEVICE_THREAD_POOL were still running. Those finalizers re-created the run directory that release_private_offload_root had just removed (one leaked bundle set per failed run) and kept packing/replacing modules after quantize() had raised to the caller. #4515 only fixed the capture-hook half of #4470. Drain the device pool, the finalizer watcher threads and the stream device pool before any teardown, mirroring the success path. Each wait is independent so one wedged pool cannot skip the others or mask the original exception. Issue #4595.
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.
Root cause
ModuleLooper.loop()drainsDEVICE_THREAD_POOL, the finalizer watcher threads andSTREAM_DEVICE_POOLonly on the success path. Theexcept BaseExceptionbranch went straight to_restore_inflight_layer()/release_private_offload_root(), so submodule finalizers that were already submitted kept running:release_private_offload_root()had just deleted, and wrote that layer's bundles into it. The model attribute and weakref finalizer were already cleared, so nothing removed it — one leaked bundle set per failed/cancelled run;quantize()had raised, racing caller code that retries, saves or inspects the model.#4515 fixed only the subset capture-hook half of #4470.
Change
gptqmodel/looper/module_looper.py: new_fence_run_work()drains the device thread pool, the dangling finalizer watcher threads and the stream device pool, and the failure branch calls it before restoring the in-flight layer, restoring base modules, or releasing the run directory. Each wait is guarded independently so one wedged pool cannot skip the remaining waits, and nothing in the fence can mask the original exception.Tests
New
tests/test_failed_run_fence_4595.py(3 tests):DEVICE_THREAD_POOL.wait()must not skip the other waits, teardown, or replace the run's original exception;offload_to_disk, a finalizer held in flight (offload_to_diskslowed) and alayer_callbackthat raises: after the raise, norun-*directory may reappear.All three fail on unmodified
main(the end-to-end one reproduces the leakedrun-126242db45b84bc9directory) and pass with the fix:tests/test_exl3_workspace_release.pyand 7tests/test_stage_modules.pycases fail identically on unmodifiedmain(they buildModuleLooperviaobject.__new__without the attributes those paths need); they are unrelated and untouched.Closes #4595.