You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG][GIL=0] ExllamaV3Linear: concurrent first forward races in unlocked _ensure_inner(): another thread's _drop_inner() nulls the handle -> AttributeError 'NoneType' object has no attribute 'forward' (111/4480 cold calls) #4793
Found on main @ dba142d, RTX 4090 (sm_89), torch 2.16 / CPython 3.14t with PYTHON_GIL=0.
What is wrong
ExllamaV3Linear.forward (gptqmodel/nn_modules/exllamav3.py:316) gets its native handle from _ensure_inner() (:227-267). That function takes no lock and does the following:
Checks the signature (:239-240).
Calls _drop_inner(), which sets self._inner = None (:242, :179).
Builds a new LinearEXL3 and stores it in self._inner.
Returns self._inner (:267), re-reading the attribute instead of returning the object it just built.
Every loaded model starts with _inner is None. post_init builds the handle, but the model-wide _apply (.to() / dtype cast) after it drops the handle again (:305-306). Verified right after GPTQModel.load(...): inner is None: True, and the signature check fails.
So when two threads hit the first forward of a module at the same time:
Thread B's _drop_inner() can null self._inner between thread A's assignment and A's return self._inner. A's forward then raises AttributeError: 'NoneType' object has no attribute 'forward'.
Each thread also calls _normalize_inference_metadata() / _bias_version(), which rebind buffers inside the forward. The signature therefore keeps changing while the other thread checks it.
The same happens after any clear_weight_cache().
GPT-QModel enables multi-threaded paths when it detects PYTHON_GIL=0, and EXL3 is the AUTO kernel for EXL3 checkpoints on CUDA. With the GIL enabled the window did not trigger (0/4480).
Repro (Qwen2.5-0.5B-Instruct truncated to 4 layers, EXL3Config(bits=4), loaded fp16 with BACKEND.EXL3_EXLLAMA_V3)
importthreading, collections, torchfromgptqmodelimportGPTQModel, BACKENDq=GPTQModel.load(CKPT, backend=BACKEND.EXL3_EXLLAMA_V3, dtype=torch.float16, device="cuda:0")
mods= [mforminq.model.modules() iftype(m).__name__=="ExllamaV3Linear"]
errs=collections.Counter(); T=8for_inrange(20):
forminmods:
m.clear_weight_cache() # same state as right after load (_inner is None)x=torch.randn(4, m.in_features, device="cuda", dtype=torch.float16)
b=threading.Barrier(T)
defw():
s=torch.cuda.Stream(); b.wait()
try:
withtorch.inference_mode(), torch.cuda.stream(s): m(x)
s.synchronize()
exceptExceptionase: errs[f"{type(e).__name__}: {e}"] +=1th= [threading.Thread(target=w) for_inrange(T)]; [t.start() fortinth]; [t.join() fortinth]
print(dict(errs))
Output:
PYTHON_GIL=0: RESULT calls 4480 errors {"AttributeError: 'NoneType' object has no attribute 'forward'": 111} wrong_outputs 0
GIL enabled : RESULT calls 4480 errors {} wrong_outputs 0
It also showed up in a generic cold-start stress run (8 threads, one stream each, first forward of the loaded model under PYTHON_GIL=0): COLD_ERRORS 1 ["AttributeError: 'NoneType' object has no attribute 'forward'"].
Suggested fix
Guard _ensure_inner (and _ensure_torch_inner / _drop_inner) with a per-module lock.
Build into a local variable and return that local, never re-reading self._inner.
Publish the handle and its signature together.
Do the _normalize_inference_metadata rebinding once under the same lock, not on every forward.
Test that should have caught it
tests/test_exl3_dispatch_concurrency.py covers the native dispatch caches (#3951) but not the Python handle. Add a PYTHON_GIL=0 test that clears the handle and runs one module's first forward from 8 threads behind a barrier.
Severity
Medium. Under free-threading, concurrent first requests to a freshly loaded EXL3 model, or the first requests after clear_weight_cache(), crash intermittently (about 2.5% of cold calls at T=8). Outputs that do return are correct.
Claiming. Will guard _ensure_inner/_ensure_torch_inner/_drop_inner with a per-module lock, return the locally built handle instead of re-reading self._inner, and add a cold-start concurrency regression test that runs with the native builder stubbed.
Activity
Qubitium commentedon Nov 17, 2026
Claiming. Will guard
_ensure_inner/_ensure_torch_inner/_drop_innerwith a per-module lock, return the locally built handle instead of re-readingself._inner, and add a cold-start concurrency regression test that runs with the native builder stubbed.fix(exl3): publish the native handle under a per-module lock (#4793) (#…
test(exl3): route the ModelCloud#4793 inner-handle burst back through…