Repository navigation
fix(multi-gpu): release worker task refs, StopForward tracebacks, and ExLlamaV2 device (#4078) - #4088
Merged
Merged
Conversation
This was referenced Nov 15, 2026
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.
Fixes #4078
TL;DR
Three process-lifetime owners survived the operation that created them. Each now releases at its own scope: the device worker clears its task locals after
task_done(), every early stop raises a freshStopForward, and both ExLlamaV2make_q_matrixops are wrapped inOptionalCUDAGuard. Net diff: 11 files, +361/-9 (docs and tests included). No synchronization point added.1. The problem
fn,args,kwargs,fut,resultbound in the worker frame until the nextget()gptqmodel/utils/threadx.py:523(old_run)STOP_FORWARD_EXCEPTION.__traceback__from the last raisegptqmodel/nn_modules/hooked_linear.py:27; raises at:226,:288,:350,:380,:452,auto_dtype_cast.py:308,stage_inputs_capture.py:321QMatrix::QMatrixgptqmodel_ext/exllamav2/cuda/q_matrix.cu:72,q_matrix_awq.cu:72;make_q_matrixhad no guard (ext_gptq.cpp:10,ext_awq.cpp:10)flowchart TD A["forward_executor.submit(forward_batch_worker, replica)"] --> B["_DeviceWorker._run"] B --> C["fn, args, kwargs, fut, result bound in frame"] C --> D{"next task?"} D -- "yes" --> E["frame overwritten; previous released"] D -- "no: quantize finished" --> F["last replica pinned on every GPU"]2. The fix
flowchart TD A["_DeviceWorker._run"] --> B["execute task"] B --> C["resolve future"] C --> D["finally: task_done()"] D --> E["fn = args = kwargs = fut = result = None"] E --> F["worker blocks in get() with no task payload"]threadx.py:570-577): clear the five task locals in the loopfinally, immediately aftertask_done(). Reference-count only; no sync.StopForward("Forwarding stopped")at all 7 call sites.STOP_FORWARD_EXCEPTIONstays importable for compatibility but is never raised. Grep confirms nois STOP_FORWARD_EXCEPTIONidentity check anywhere in the repo; handlers only useexcept StopForward.const at::cuda::OptionalCUDAGuard device_guard(at::device_of(q_weight));at the top of bothmake_q_matrixops (ext_gptq.cpp:27,ext_awq.cpp:27), mirroring the fix(kernels): pack strided inputs, bind devices, widen offsets, handle M=0 (#4042) #4047 GGUF fix.3. Measured before/after
torch.cuda.memory_allocated, 2x RTX 4090 (CUDA 13.0, Torch 2.16.0.dev):StopForwardfrom a frame holding 512 MiB, caught + gcquantize()+save()+gc oncuda:1make_q_matrixwith operands oncuda:1, currentcuda:0ROCm 2x R9700: the worker-frame repro and its test report 0.000 MiB and a dead weakref after the fix.
Quantize wall time: 11.9 s after vs 12.6 s before (same host, warm cache) -- no throughput regression; the cleanup adds no synchronization.
4. Tests
New regression tests (all fail on pre-fix code, pass after):
tests/test_threadx.py::test_worker_frame_releases_last_task_referencestests/test_stop_forward_leak.py::test_stop_forward_does_not_pin_the_raising_tracebacktests/kernels/test_exllamav2_device_guard.py::test_make_q_matrix_restores_current_device[gptq/awq]Commands and results:
Pre-fix failure evidence: the same tests fail on
origin/mainwithassert tensor(...) is None(item 1),assert <traceback object> is None(item 2), andassert 1 == 0(item 3, GPTQ and AWQ).5. Docs
Committed
docs/multi-gpu-memory.md(ownership contract, old/new flow diagrams, measurements) and linked it fromREADME.mdoperational notes.6. Risk / scope
GPTQMODEL_*switches. No dense/dequantized weight cache added. CUDA and ROCm paths remain explicit.STOP_FORWARD_EXCEPTIONis kept as a compatibility import only; removing it is a separate cleanup.