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
[PERF] Regression from #4832 (fix of #4814): ParoLinear runs every CPU GEMM inside the process-wide _cpu_transform_lock, serializing all concurrent Paro inference (4-thread decode throughput 2.0x lower with GIL, 2.9x with GIL=0) #4885
Found on main @ 5cded90, x86-64 AVX512-BF16 host (CPU only, OMP_NUM_THREADS=8), CPython 3.14 (GIL) and 3.14t (PYTHON_GIL=0).
What is wrong
#4832 (fix of #4814) moved Paro's CPU int4 operands into the module's own buffers. To keep state_dict() consistent, both CPU forwards now run the whole GEMM, not only the cold layout check, inside _cpu_transform_lock:
paro.py::_forward_cpu_avx512, around line 727: with self._cpu_transform_lock: wraps _ensure_cpu_layout("avx512"), the per-call FP32 widening of scales/bias and gemm(...).
paro.py::_forward_cpu_aten, around line 779: the same lock wraps _ensure_cpu_layout("aten", ...) and _cpu_int4pack_mm(...).
_cpu_transform_lock is a single process-wide threading.RLock (BaseQuantLinear._cpu_transform_lock, qlinear/__init__.py:347), shared by every module of every model in the process. So every Paro CPU matmul in the process is now serialized: concurrent requests, a thread pool, or two models served side by side. It also blocks against the cold transform and state_dict() of every other CPU int4 kernel. The GPTQ/AWQ siblings (TorchAtenLinear.forward, torch_aten_kernel.py:465) hold the lock only for the cold check-and-transform, and run the matmul outside it.
4 threads each run 20 single-token decode forwards (torch.set_num_threads(2)), compared with the same 80 forwards run serially:
4 threads concurrent serial speedup
5b5830789 (before #4832), GIL 16.11 s 33.40 s 2.07x
5cded90c9 (after), GIL 32.53 s 32.82 s 1.01x
5b5830789, PYTHON_GIL=0 8.65 s 31.77 s 3.67x
5cded90c9, PYTHON_GIL=0 24.72 s 32.45 s 1.31x
Concurrent throughput is 2.0x (GIL) and 2.9x (free-threaded) lower. The bf16 AVX512 path has the same lock around gemm. At decode it showed no measurable difference here (4.52 s vs 4.83 s, GIL=0), because the M=1 GEMM is small next to the rotation work. The lock is still held for the whole GEMM at prefill.
Minimal repro
importthreading, time, torchfromgptqmodelimportGPTQModelm=GPTQModel.load("<Paro 4-bit checkpoint>", dtype=torch.float16, device="cpu") # AUTO -> ParoLineardec=torch.randint(100, 1000, (1, 1))
withtorch.inference_mode():
m.model(dec) # cold transformtorch.set_num_threads(2)
defwork():
withtorch.inference_mode():
for_inrange(20): m.model(dec)
th= [threading.Thread(target=work) for_inrange(4)]
t=time.perf_counter(); [x.start() forxinth]; [x.join() forxinth]; print("concurrent", time.perf_counter() -t)
t=time.perf_counter(); [work() for_inrange(4)]; print("serial", time.perf_counter() -t)
# before #4832: concurrent 16.1 s, serial 33.4 s; after: 32.5 s / 32.8 s
Suggested fix
Do what TorchAtenLinear.forward does: take the lock only for _ensure_cpu_layout(...), read qweight/qzeros/scales_and_zeros (and the widened scales/bias) into locals while holding it, then release it and run the GEMM on those locals. A concurrent state_dict()/load_state_dict() can then rebind the module attributes, but the in-flight GEMM keeps the consistent operands it captured. Re-take the lock only for the _restore_cpu_checkpoint_layout() fallback on error.
Test that should have caught it
tests/kernels/test_paro.py covers residency and numerics only. A concurrency test, as in test_cpu_lazy_transform_concurrency_4565.py, could assert that two threads' warm forwards overlap: for example, a forward on thread B completes while thread A holds _cpu_transform_lock.
Severity
Medium. Multi-threaded CPU serving of Paro models gets no parallelism, which costs 2-2.9x throughput. Because the lock is global, a warm Paro forward also stalls any other model's cold CPU transform and state_dict() in the same process.
Activity
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-root-4885finished this issue. Fix merged in #4922 (squash commitb98f4028a).perf(paro): run the CPU int4 GEMM outside the process-wide transform …