Skip to content

Studio backend tests: pin the logical CPU count in the oversubscribed-threads spill test - #11120

Merged
danielhanchen merged 3 commits into
mainfrom
pr/spill-thread-test-cpu-count
Sep 17, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
pr/spill-thread-test-cpu-count

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

test_oversubscribed_decode_threads_decline_spill_planning fails on any host with more than 16 logical CPUs. It is not flaky. The dependency is exact.

The dependency

The test stubs os.sched_getaffinity to return 16 CPUs, meaning "affinity is the whole machine, nothing is restricted". But _spilled_decode_threads takes the logical count from psutil.cpu_count(logical = True), which the test leaves real:

if affinity_count is not None and logical is not None and affinity_count < logical:
    return None

On a wider host, affinity_count = 16 against a real logical of 32 or 192 reads as a taskset, so the function declines on the affinity arm and the oversubscription the test exists to check is never reached. Both calls come back None, and the second assertion fails with assert (None is not None).

Measured against a stubbed host width, everything else in the test held fixed:

host logical=   4  threads16->None    threads4->4        TEST GREEN
host logical=   8  threads16->None    threads4->4        TEST GREEN
host logical=  16  threads16->None    threads4->4        TEST GREEN
host logical=  32  threads16->None    threads4->None     TEST RED
host logical= 192  threads16->None    threads4->None     TEST RED

Green iff the host has 16 or fewer logical CPUs.

Two things worth knowing before anyone tries to reproduce it:

  • taskset does not reproduce it. psutil.cpu_count ignores affinity and reports the whole machine, so taskset -c 0-3 leaves logical at its real value and the test still fails.
  • Org CI on GitHub-hosted runners will never show it. Those are 2 to 4 vCPU, comfortably under the threshold. That is why it has survived since it was added in stop the planner withholding a split reserve from one card, and price physical cores #9863 on 2026-08-29 and only turns up on a wide self-hosted runner. Confirmed red on plain main at cf335fa47, on a 192-thread host.

The fix

Stub psutil as well, so the 16-CPU affinity reads as unrestricted the way the test intends. _SmtHost is already defined at module scope as exactly the 16 logical / 8 physical host this test assumed, and the two affinity tests immediately above it pin psutil the same way for the same reason, so this follows the file's existing pattern rather than introducing one.

One line plus a comment. No product code changes. The product is correct here: declining to price a spill under a restricted affinity is a deliberate abstain that hands placement back to llama.cpp, and the test was reporting the right thing for the wrong reason.

Can it still fail

The assertions are untouched and both arms still bite.

  • Removing the if actual > physical: return None arm from _spilled_decode_threads turns the first assertion red: _plan(...) returns a Plan where None was required.
  • Making the in-budget path return None instead of max(1, actual) turns the second assertion red: assert (None is not None).

studio/backend/tests/test_offload_planner_seam.py is 157 passed locally, ruff check clean.

…-threads spill test

test_oversubscribed_decode_threads_decline_spill_planning stubs
os.sched_getaffinity to 16 CPUs to say "affinity is the whole machine", but
_spilled_decode_threads takes the logical count from psutil.cpu_count(logical =
True), which the test leaves real. On a host wider than 16 threads that 16-CPU
affinity reads as a taskset, the function declines on the affinity arm, and the
oversubscription the test is about is never reached: both halves come back None
and the second assertion fails. Green iff the host has 16 or fewer logical CPUs,
which is why it has survived since #9863 on 2026-08-29 -- GitHub-hosted runners
are 2 to 4 vCPU and never show it. It reproduces on any wide self-hosted runner;
measured on a 192-thread host.

taskset does not reproduce it, because psutil.cpu_count ignores affinity and
still reports the whole machine.

Stub psutil as well. _SmtHost is already defined at module scope as the 16
logical / 8 physical host this test assumed, and the two affinity tests directly
above it pin psutil the same way for the same reason, so this is the established
pattern in the file rather than a new one.

The assertions are unchanged and both still bite. Dropping the `if actual >
physical: return None` arm turns the first one red; making the in-budget arm
return None turns the second one red.
@danielhanchen danielhanchen self-assigned this Sep 16, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-17T10:11:40.940117Z 3c8ee1b Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 16, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 81caf8c469

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

Merged current main in. All eight failing checks here were inherited from main rather than caused by this PR: they ran on 2026-09-16 16:32, before the repairs landed, and every failing test is one that has since been fixed on main.

failing test fixed on main by
test_cache_budget_discipline, test_playwright_suites_run_in_ci, test_windows_amd_gpu_scan_fallback, test_studiobench_queued_idle_live, test_setup_llama_cpp_backend #11139
test_woa_wheelhouse_guard_behaviour #11139, #11164
test_formatter_fixed_point #11145

Verified locally against the merge: the six suites that were red now give 417 passed, 2 skipped.

The merge also absorbs the studio/backend/main.py and banner-test edits this branch carried, which were formatter reflow only and have since landed on main via #11058. What remains is the change this PR is actually for, unchanged: pinning psutil to _SmtHost in test_oversubscribed_decode_threads_decline_spill_planning so the 16-CPU affinity reads as unrestricted. Left real, a CI box wider than 16 threads makes that affinity look like a taskset, the pricing declines for that reason instead, and the oversubscription the test is about is never reached.

test_offload_planner_seam.py and test_bootstrap_banner_password_visibility.py: 168 passed.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 3c8ee1b35c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 653d4ec into main Sep 17, 2026
31 of 35 checks passed
@danielhanchen
danielhanchen deleted the pr/spill-thread-test-cpu-count branch September 17, 2026 10:20
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…-threads spill test (unslothai#11120)

* Studio backend tests: pin the logical CPU count in the oversubscribed-threads spill test

test_oversubscribed_decode_threads_decline_spill_planning stubs
os.sched_getaffinity to 16 CPUs to say "affinity is the whole machine", but
_spilled_decode_threads takes the logical count from psutil.cpu_count(logical =
True), which the test leaves real. On a host wider than 16 threads that 16-CPU
affinity reads as a taskset, the function declines on the affinity arm, and the
oversubscription the test is about is never reached: both halves come back None
and the second assertion fails. Green iff the host has 16 or fewer logical CPUs,
which is why it has survived since unslothai#9863 on 2026-08-29 -- GitHub-hosted runners
are 2 to 4 vCPU and never show it. It reproduces on any wide self-hosted runner;
measured on a 192-thread host.

taskset does not reproduce it, because psutil.cpu_count ignores affinity and
still reports the whole machine.

Stub psutil as well. _SmtHost is already defined at module scope as the 16
logical / 8 physical host this test assumed, and the two affinity tests directly
above it pin psutil the same way for the same reason, so this is the established
pattern in the file rather than a new one.

The assertions are unchanged and both still bite. Dropping the `if actual >
physical: return None` arm turns the first one red; making the in-budget arm
return None turns the second one red.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant