mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 21:08:26 +07:00
[GH-ISSUE #433] We tripled DeepSeek's speed by giving it FEWER CPU threads: 15 → 41 tok/s on one GPU (and --calibrate skipped the test) #175
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#175
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 @talisp on GitHub (Oct 23, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/433
In short
If DeepSeek-V4.1-Flash on Maya is stuck at ~15 tok/s on one GPU with most experts in RAM, check
--cpu-threadsfirst. This was our mistake, not a Maya bug. We ran with the default, one CPU-lane thread per core, which on our VM meant all 32 vCPUs. Nothing was left for the engine's other work. Leaving 4 vCPUs free almost doubled decode, and the DSpark drafter then added another ~1.5×.Why it matters: the update from v1.1.21 to v1.1.25 alone changed nothing (15.0 → 14.2). All of the gain came from the configuration. So "DeepSeek on one card with RAM experts is ~15 tok/s" is not what this hardware does. It is what this hardware does with every core given to the CPU lane.
How we missed it:
./maya.sh --calibratebefore.no experts on the CPU lane here (VRAM holds them all): the CPU threads do not matterand skipped the thread test, although about 60% of each token's experts run on the CPU lane here.What we'd suggest:
--cpu-threadsat 2-4 below your core count, and measure.--calibraterun the thread test whenever the CPU lane holds experts, and consider leaving a few cores free by default, at least under a hypervisor.The details follow, for people and AI agents searching for this.
Technical notes
Setup
maya-ds4). The baseline was v1.1.21.--max-context 262144 --mmap-experts off, vision on./metrics→tiers.now.cpu).Final config:
"args": [..., "--mmap-experts", "off", "--dspark", "on", "--cpu-threads", "28"], with"env": {"MAYA_DS4_SLOT_KEEP": "1", "MAYA_DS4_SLOT_CAP": "8", "DS4_REQUIRE_ALL_RAM": "1"}.How we measured
The same script each time, through the server (
/v1/chat/completions, temperature 0), reading the engine's ownmaya ds4 serve: prompt ...lines:There was one engine start per variant, 8 starts in all.
MAYA_DS4_Q8_BATCH=1--speed-calibration(v1.1.25, default threads): no drafting 14.2, DSpark 16.1 tok/s (+13%), 71% of drafts accepted.Why fewer threads is faster here (our reading)
The engine's own log shows it. Its start-up estimate of a CPU-lane expert stays at ~0.04-0.08 ms, but the decode re-timing (
the CPU lane timed again in decode: an expert X ms) reported:With ~145 CPU-lane experts a token, that is most of the difference between ~70 ms and ~38 ms a token without DSpark (15 → 26.5 tok/s).
Our interpretation:
This matches what #177 found for GLM in a KVM guest, where
STRATA_GLM_CPU_LANE=14on 16 vCPUs gave +20-23%.Why
--calibratedid not catch ittools/calibrate_ds4_tp.py(around L240-255) runs the thread candidates only whenint(info.get("cpu_experts") or 0) > 0 and d_threads > 0. Otherwise it prints "no experts on the CPU lane here (VRAM holds them all)". On our run that branch was taken, although the engine's log for the same run says13941 routed experts on the CPU lane (262.1 GB): 13941 copied into RAM ...; 28 threads(from a later start), and the serve lines report "CPU lane 55-60% of the experts". We have not traced which of the two values was missing frominfo. Either way, a thread test that fails like this could print why it was skipped, rather than say the CPU lane is empty.The DSpark
--speed-calibrationmeasures at the config's current thread count. If threads are tuned after it, DSpark's result can change a lot: +13% at 32 threads, +55% at 28 here.Also tried
MAYA_DS4_Q8_BATCH=1: no gain here (within the noise).DS4_ENGRAM_RAM=1: not possible on this VM. Itmlocks the tables, andulimit -lis ~63 GB against 189 GiB of Engram tables. It is not needed for speed either: Engram reads cost ~1.4 ms a token from the page cache.Takeaway for others
On one GPU with the experts mostly in RAM, if the engine sits at ~100% of every core during decode, try
--cpu-threadsat core count minus 2-4. Then re-run--speed-calibrationfor DSpark, because its verdict depends on the thread count.@talisp commented on GitHub (Oct 23, 2026):
One more detail that likely explains why this hits VMs in particular. Per
docs/SETTINGS.md("a thread per physical core; a core's second thread (SMT) is left to the disk and Engram readers") andsrc/ds4/ds4_model.cu(around L5203: "the siblings are left to the readers"), the default assumes SMT. Our VM exposes 32 vCPUs with one thread per core (lscpu:Thread(s) per core: 1). So the default gives the CPU lane all 32, and nothing is left for the readers, the GPU launches or the server. That matches what we measured. A possible default: when a core has no SMT sibling, leave 2-4 cores free, or let--calibratetreat it as a case to test.@mw00 commented on GitHub (Oct 23, 2026):
Thanks for the thorough write-up - we reproduced it.
Test: one V100 with DeepSeek Maya-XS (most experts on the CPU lane, from RAM), the process held to 20 physical cores without SMT siblings (
taskset), the same shape as your VM:--cpu-threads 20)The engine's own decode re-timing showed what you saw: each CPU-lane expert taking about twice its planned time when the lane has every CPU.
v1.1.26 (released today) already does this by default: when the CPU lane would take every logical CPU (no SMT, as on your VM), it leaves 2 cores free (
MAYA_DS4_LANE_FREE, 0 = as before) - from #359 and #394's follow-up. With SMT nothing changes, since the siblings are free already. Could you try v1.1.26 without--cpu-threadsand tell us where it lands against your 28 threads?--calibrateskipping the thread test: on our setup the engine reports its CPU-lane experts correctly and the test runs, so your combination (unsloth UD-Q8_K_XL,--mmap-experts off,DS4_REQUIRE_ALL_RAM=1) must report 0 somewhere. Rather than depend on that count, v1.1.27 will run the thread test whenever the CPU lane has threads, and say why whenever it skips it.And you're right that DSpark's verdict depends on the thread count: re-run
--speed-calibrationafter changing threads.@talisp commented on GitHub (Oct 24, 2026):
Thanks for reproducing it so quickly. We ran your test on v1.1.26. The new default works well and brings most of the gain. On this VM, 28 threads was still a bit faster, mostly in the first answers after a start.
Same machine and benchmark as above, one engine start per run, alternating:
--cpu-threads)--cpu-threads 28--cpu-threads 28So the new default fixes the big loss for VMs without SMT. On a guest like ours, 3-4 free cores may still be slightly better than 2. We'll keep
--cpu-threads 28here, and we're happy to re-run on v1.1.27 when the thread test in--calibratelands, to see what it picks.A side note on start-up, in case it helps other Linux users. With
--mmap-experts offandDS4_REQUIRE_ALL_RAM=1, the start copies ~262 GB into RAM while the page cache is full (~290 GB on our 504 GB host). We sampled the session's memory pressure (memory.pressure,some avg10) once a second during a start: it peaked at 97% and stayed above 20% for ~290 s. That is far past the 50% / 20 s rule that Ubuntu's systemd-oomd ships for user sessions (/usr/lib/systemd/system/user@.service.d/10-oomd-user-service-defaults.conf). It killed our whole desktop session twice: the terminal, the scripts and the Maya server, even with the server in its ownsystemd-run --userunit. Memory never actually ran out; the kernel was only reclaiming cache. We fixed it with a drop-in settingManagedOOMMemoryPressure=autoforuser@.service. A line about this in the setup docs, or a check at start (oomctl dump), might save someone a confusing afternoon.@mw00 commented on GitHub (Oct 24, 2026):
v1.1.27's
--calibratetests the CPU-lane thread counts whenever the lane has threads, 2 and 4 fewer first where it would take every CPU - the test your 15 -> 41 tok/s showed it was skipping. Thanks for the report.@talisp commented on GitHub (Oct 24, 2026):
Thanks a lot, that was quick! Nice to see it already in v1.1.27.
Also, an open offer: if you ever want something tested on real hardware, we have two VMs you can use.
Just @-mention me (@talisp) in an issue or a PR with what to run, and we'll post the results back there.