Repository navigation
Closed
Labels
bugSomething isn't working
Description
Summary
Three issues affect free-threaded (PYTHON_GIL=0) and multi-worker use: process lifetime, shared Triton state, and GPU memory retention. None of them duplicates #3927, #3947, #3951, #3878 or #2441. #2441 was about _cache_lock missing on Autotuner instances created before the patch. Audited at a16977e.
Findings
1. Any exception in a DeviceThreadPool task calls os._exit(1) (High)
- Code:
gptqmodel/utils/threadx.py.- Task errors:
_DeviceWorker._run(556-562) runsexcept BaseException→fut.set_exception(exc)→self._abort_process(exc). - Warmup failures: lines 531-535 do the same.
_abort_process(570-581) prints the traceback and callsos._exit(1), falling back toos.system("kill -9 <pid>").
- Task errors:
- What triggers it: any error from a submitted task. Examples include
torch.OutOfMemoryError, a validationValueError, a CUDA error inevent.synchronize(), and anOSErrorfrom the async log writer. - Where tasks are submitted:
looper/stage_subset.py:1541looper/stage_layer.py:1305looper/forward_executor.py:708-735looper/loop_processor.py:567utils/stream.py:212- linalg warmups
- Consequences:
- A host app that embeds
quantize()(Jupyter kernel, web service, training script) is killed without unwinding. atexithandlers do not run, including gptqmodel's own pool join (__init__.py:302) and the tempdirrmtree(utils/structure.py:1157).finallyblocks and checkpoint signal restore (gptq_checkpoint.py:266-279) are skipped.- The caller's
try/exceptcan never catch the error. - The library's own handling in
stage_layer._drain_finalize_futures(1371-1378) andstage_subset._collect_worker_resultsbecomes dead code, because whether the main thread observes the future first is a race.
- A host app that embeds
- Inconsistencies:
_SyncWorker.submit(605-627) only sets the exception and does not abort.tests/test_threadx.py:801monkeypatches_abort_processto a no-op, which hides the behaviour.
- Fix:
- Drop
_abort_processfrom the task path and propagate errors through the future. - For warmup failures, fail the pending future instead of exiting.
- If fail-fast is wanted, make it an explicit config option.
- Drop
2. GIL=0 Triton autotuner patch shares self.nargs across threads (Medium)
- The patch is process-wide:
gptqmodel/__init__.py:69TritonPatch.apply()replacesAutotuner.runfor every@triton.autotunekernel in the process, including third-party ones (fla, Liger). - The race:
utils/nogil_patcher.py:257setsself.nargs = nargsand:291setsself.nargs = Noneon the shared Autotuner, without a lock.best_config(271) is written the same way. - Who reads it: upstream Triton reads
self.nargsinside_bench(full_nargs = {**self.nargs, ...}),prune_configs(early_config_prune(self.configs, self.nargs)) andperf_model. The patch's ownbenchmark()reads it at line 220. - What happens:
- Thread A benchmarks a cold key.
- Thread B finishes a call to the same kernel and resets
nargs = None. - A raises
TypeError: 'NoneType' object is not a mapping. - If B is still running instead, A benchmarks, prunes and runs
pre_hook/reset_to_zero/restore_valueagainst B's tensors. That gives silent corruption, or a config chosen from the wrong shapes and then cached.
- Concurrency path:
forward_executor.py:708-735runs the same layer class on several GPUs at once. - Fix: keep
nargsin thread-local storage, or pass it explicitly to_bench/prune_configs, and stop mutating the shared attribute. At minimum, hold a per-Autotuner lock across benchmark plus run for cold keys. - Same pattern in gptqmodel's own autotuner:
nn_modules/triton_utils/custom_autotune.py:91-123(GGUF Triton kernels) has an unlocked check-then-set onself.cacheand the same sharedself.nargs.
3. Low
- GPTQ Hessian workspace pool is never released:
quantization/gptq.py:110-111defines the module-level_WORKSPACE_SLOTS/_WORKSPACE_CACHE, filled by_lease_workspace(231-289).- It keeps up to 8 fp32 slots plus staging slots per (device, dtype), and they survive
quantize()returning and model deletion. - It is reached when
HessianConfig.chunk_size/chunk_bytesis set. torch.cuda.empty_cache()cannot reclaim the memory.- Fix: clear the pool in the looper finalize /
torch_empty_cachepath, or expose a release API.
os.environis changed process-wide during JIT builds:utils/cpp.py:951-969_temporary_merged_cuda_arch_overriderewritesTORCH_CUDA_ARCH_LISTfor the wholeload()(1911-1914, which can take minutes).load_pack_block_extension/load_floatx_cpu_extensionset and popGPTQMODEL_EXT_VERBOSE(2193-2203, 2229-2237).- Concurrent torch, triton and inductor compiles in pool workers see the temporary values.
- In glibc,
setenvracing with nativegetenvis undefined behaviour. - Fix: pass arch flags through
extra_cuda_cflagsor a copied env instead.
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
docs: avoid semicolons inside Mermaid labels (#3972)
fix(gil0): propagate thread-pool errors and isolate Triton autotuner …