Repository navigation
fix(threadx): skip warmup for devices excluded from quantization - #4347
Merged
Merged
Conversation
The global DeviceThreadPool eagerly created every CUDA worker and kicked
linalg warmup on every visible device. A caller that selected only cuda:1 still
got a CUDA context and ~524 MiB of warmup allocations on cuda:0.
Defer worker device activation until the first task and restrict the eager
warmup no-op to an explicit allow-list. GPTQModel.load/from_pretrained derive
that allow-list from device=("cuda:1",), so excluded GPUs never get a context.
Workers for other devices remain available and activate lazily if work is
submitted to them.
Adds a CPU unit test for the allow-list and a subprocess GPU test that checks
nvidia-smi compute apps for the excluded and permitted GPUs.
Fixes #4320
Qubitium
pushed a commit
that referenced
this pull request
Nov 17, 2026
…4688) #4320/#4347 made the pool's device activation lazy, so `load(device=("cuda:1",))` kept the excluded GPU clean until quantization started. Three later paths still touched it anyway: - `torch_sync()` synchronized every *visible* CUDA index. `synchronize` creates a full primary context on a device the process never used, which reserves hundreds of MiB (measured 386 MiB) on the excluded GPU. - `QuantizeConfig.compute_device_filter` was never consulted by the eager linalg warmup or the quantize/linear prewarms; both resolved their target from the `device=` load kwarg only. The documented filter therefore ran the full warmup on the excluded GPU (measured 384 MiB peak allocation). - The device pool's janitor swept `empty_cache` over every pool device, and `device_ctx` collapsed the index-less family selector to `cuda:0`. Resolve the warmup allow-list from the same filtered pool the loopers consume (`_quantize_warmup_devices`), apply it to a retained pool through `DeviceThreadPool.set_warmup_devices`, skip accelerators whose primary context this process never created (`accelerator_context_claimed`), and keep the current device for an index-less family selector while device 0 is untouched. A torch build without the primary-context query, a filter that rejects every device, and HIP (whose query reports every device active after the first allocation) all keep the previous behavior. Regression: tests/test_excluded_device_warmup.py runs a real quantization on two GPUs through both exclusion routes and asserts the excluded device has no primary context and no peak allocation.
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 #4320
Summary
The global
DeviceThreadPooleagerly created a worker for every visible CUDA device and kickedrun_torch_linalg_warmupon all of them duringGPTQModel.load. Selectingdevice=("cuda:1",)still gave the excluded GPU a CUDA context and ~524 MiB of warmup allocations.Two changes make excluded devices inert:
DeviceThreadPool(warmup_devices=...)restricts the eager warmup no-op to an allow-list. Workers for other devices still exist and can receive work, but they activate lazily._DeviceWorkerdefers_activate_thread_device()until its first warmup/task, so merely constructing the pool no longer creates a CUDA context on every device.GPTQModel.load()/from_pretrained()derive the allow-list from the existingdevice=("cuda:1",)selector (_explicit_requested_devices) and pass it to the pool before the pool is built. With no explicit device selector, the historical behavior (warm every discovered accelerator) is unchanged.Evidence
GPTQModel.load(..., device=("cuda:1",))withCUDA_VISIBLE_DEVICES=0,1Before (
origin/main):After (this branch):
Our PID has no
nvidia-smicompute-app row for GPU 0. The permitted GPU still has its context and warmup.Direct pool check
Before (default pool):
After (
get_device_thread_pool(warmup_devices=[torch.device("cuda:1")])):Tests
tests/test_excluded_device_warmup.py:test_warmup_devices_skips_excluded_device— fake-CUDA unit test that asserts only the permitted worker activates.test_default_pool_still_warms_every_accelerator— no allow-list keeps the historical all-device warmup.test_prebuild_passes_explicit_devices_to_pool—GPTQModelplumbing passes the selector to the pool.test_excluded_cuda_device_has_no_context— subprocess GPU test that runs a task oncuda:1, then parsesnvidia-smi --query-compute-apps=pid,gpu_uuid,used_memoryand asserts our PID appears for the permitted GPU but not the excluded one.On
origin/mainthe GPU test fails with the real assertion:After the fix:
Related threadx/compute-filter suite:
Ruff
Residual risk
GPTQModel.loadwith no allow-list, excluded devices may already have been warmed; the normal load path builds it first with the selector.device=("cuda:1",)) are treated as exclusions, matching the existingcompute_device_filtercontract. A single stringdevice="cuda:1"is not converted to a filter by the loader.warmup_devicesdoes not change virtual-pool alias creation; the global pool does not use aliases.