Skip to content

[PERF] Each DEVICE_THREAD_POOL CPU worker gets its own full-size OpenMP team: ~2.5k OS threads on a 320-CPU host #4356

Closed

Description

@Qubitium

Severity: medium. Status: confirmed by repro. Related to item 2 of #4351, which records the test-side symptom.

Where

  • gptqmodel/__init__.py:391-405 (_default_cpu_workers) and the pool build (~430).
  • No worker calls torch.set_num_threads; cap_torch_threads is opt-in.

Description

  • libgomp gives each pthread that enters a parallel region its own team of torch.get_num_threads() threads. That is 205 by default on this host.
  • With 12 CPU workers, the thread count goes from 68 to 2538 (DPWorker-cpu#0..11 × 205).
  • The comment at line 401, "cap CPU workers to avoid OpenMP team explosion", caps the number of workers but not the team size.
  • The free-threading cap (≤8 workers) is also skipped here, because importing triton re-enables the GIL, so has_gil_disabled() is False. This part is partly environmental.
  • Inside a full pytest session (OMP_NUM_THREADS=8), the same mechanism gives 157 threads. That fails tests/test_thread_caps.py::test_process_thread_count_does_not_scale_with_cpu_count (157 > 80), which passes when run alone. Twenty of those threads are lingering device-smi-metrics threads.

Repro

Large-core host, OMP_NUM_THREADS not set:

import os, torch
from gptqmodel import DEVICE_THREAD_POOL
def w(): a = torch.randn(512, 512); (a @ a).sum().item()
[f.result() for f in [DEVICE_THREAD_POOL.submit(torch.device("cpu"), w) for _ in range(64)]]
print(len(os.listdir("/proc/self/task")))   # 2538 here

Expected: roughly the number of workers plus one OpenMP pool, e.g. by calling torch.set_num_threads(max(1, total // workers)) in each CPU worker's init.


Found during an AI-assisted review (Claude Code, round 11) of 842d666; repros were run at that commit on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

Activity

  1. added
    bug
    on Nov 16, 2026
  2. ZX-ModelCloud commented on Nov 16, 2026

    @ZX-ModelCloud
    Collaborator

    Claimed. I'm working on this issue and will submit a fix PR. Please avoid duplicate work in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions