mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #1056] Prefill: Stager threads yield-spin while waiting. On Linux with --mmap-experts (DGX Spark / GB10), prompts are read ~10x slower; elsewhere ~20 cores are burned during prefill #451
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#451
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @uncle-daddy-jp on GitHub (Oct 6, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1056
Summary
On a DGX Spark (GB10), using the
arm-gb10-portbranch from PR #409 (44df8fd), reading a prompt with--mmap-expertsran at ~90 tok/s instead of ~1,200-1,400 tok/s. The cause is the prefillStager: its threads wait by spinning (std::this_thread::yield()onissued, andcudaEventSynchronizeon events that spin under the defaultcudaDeviceScheduleAuto). With a transient expert source there are 32 of them. On Linux they inherit the host thread's single-core pin (SessionLoopScratch::init->pin_current_thread(physical_cores(false)[0])), so all 32 spin on the host's core and starve it. If they are unpinned, prompts are fast again, but the 32 spinners then take every core (process CPU 1,700-2,000% on a 20-core box) for the whole prompt.Making the two waits sleep fixes both the slowdown and the CPU use, and no affinity change is needed. The patch is 5 lines of code plus a 2-line comment; PR follows.
Environment
arm-gb10-port44df8fd(PR #409).src/prefill/prefill.cppis unchanged between99f3dbdand that branch; the same code is on main (1735d64as of today), and the patch applies cleanly there (git apply --check).--mmap-experts --expert-cache auto --prefill auto --spec 4 --mtp ... --kv int8 --vision, all 24,576 experts in the GPU cache.Repro
Linux plus an expert source whose blobs are
transient()(a GGUF read in place,--mmap-experts), so thatPrefill::initstarts 32 stager threads (files ? 32 : ...). Send an 8K or 30K-token prompt.Evidence (before)
STRATA_PREFILL_TIMING=1: 68-69% of prefill time was "host grouping" (~0.9 s per MoE layer). It drops to 0.5-1.4% with the fix./proc/<pid>/task/*/status: 35-36 threads hadCpus_allowed_list: 0. On GB10, CPU 0 is an A725 (cpu_capacity 718), becausephysical_cores(false)with the defaultPoolAffinity::Alllists CPUs in number order.perf record -gduring prefill: ~85% of samples inStager::work->sched_yield/__schedule.taskset -p -c 0-19on every task of the running engine: prompt reading became 10x faster at once (IQ3_S 8K 91 -> 1,199 tok/s, 30K 88 -> 1,357 tok/s).perfshowed the time going to__schedule/do_sched_yield(~45%) plus a libcuda spin incudaEventSynchronize(~15%), and process CPU was 1,640-1,880% (peaks 2,000%) for the whole prompt.Results (IQ3_S, prompts of 7,031 / 26,383 tokens, server-reported tok/s; CPU = process CPU sampled every 1 s, 100 = one core)
44df8fdas isStager::work)STRATA_STAGER_THREADS=8STRATA_STAGER_THREADS=4atomic::waitdma_doneeventsWith the patch, the remaining ~1 core during prefill is the host thread and the issuer (
Stager::wait,wait_issued), which still spin by design and share the host's pinned core. Decode is unchanged. The 32 copy threads can stay on core 0 without slowing anything down: the copies are a small part of the time (__memcpy_sve~1-2% of samples) and the waiting threads now sleep.Patch
atomic::wait/notify_allfor the ring wait,cudaEventBlockingSyncfordma_done, and one define in the HIP shim (not tested on HIP). Opened as a PR.Notes
issued_one(notify_all). With 32 threads that is cheap in practice (process CPU ~1,800% -> ~100%). A per-slot wait would avoid it if it ever matters.physical_cores(false)[0]picks a little core (CPU 0) for the host.STRATA_STAGER_THREADS=4plustaskset(or any unpinning). With 4 threads the slowdown is gone on GB10, but 4 cores still spin.@Niko1221 commented on GitHub (Oct 7, 2026):
Thank you for the perf trace. The Stager threads now sleep instead of yield-spinning while they wait (the change from #1057). That is the default on Linux in 0.1.40.2; Windows keeps the old wait, which was 1.2% faster there. STRATA_STAGER_SLEEP=1/0 forces either. We have no GB10 here, so we could not reproduce your numbers (it was reported at IQ3_S 8K: 91 -> 1,222 tok/s); on an RTX 3060 the prompt speed is unchanged. Closing; please reopen if your GB10 does not show the gain.