Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
The OpenMP team is the whole ballgame on a many-core host
omp_tune.h has carried the physical-core sizing since #718, where it measured
+2.3x on a 16C/32T part from the thread count alone. Four engines call it:
colibri.c, inkling.c, kimi_k3.c, olmoe.c. Four were written afterwards and
never did: glm53.c, qwen36.c, qwen38.c, deepseek_v41.c.
Nothing failed when that happened, which is why it lasted. The symptom is not an
error. The engine simply runs one thread per logical CPU, and on a host where the
logical/physical ratio is large, the per-region barrier cost swallows the arithmetic.
On a 208-logical-CPU machine: deepseek-v41 spent 93% of its cycles inside libgomp
and decoded 18.7x slower than it does with a sane team.
This is the same shape as the mirror and O_DIRECT gaps next door -- a mechanism in a
shared header that reached some engines and not their siblings -- and it is the
largest of them by an order of magnitude.
Machine
| CPU | 2x Intel Xeon Platinum 8555C, 52 cores/socket, 2 threads/core = 104 physical cores, 208 logical CPUs, 4 NUMA nodes |
| RAM | 1007 GiB |
| Storage | nvme0n1 Samsung MZQL2960HCJR (894 GB, ext4, noatime) |
| commit | 941d5fe9 on fix/omp-team-sizing (rebased onto dev at f4aff21) |
| OS / toolchain | Ubuntu 24.04, kernel 6.8.0-31-generic, gcc 13.3.0, -O3 -march=native -fopenmp, libgomp |
Container and method
deepseek-ai/DeepSeek-V4.1-Flash, released checkpoint, no conversion: 48 shards,
510.3 GB, 88 files verified against the upstream manifest. The engine's one-shot
oracle mode (SNAP=<dir> ./deepseek_v41 8 ref.json), 25 prompt tokens, 16 generated,
cap=8, page cache evicted before every run. ref.json carries the 16 reference ids,
so every run below is token-exact 16/16 -- the team size changes scheduling, not
results.
The profile, first
Before touching anything, perf record on a short run:
| overhead | where |
|---|---|
| 38.65% | libgomp.so.1.0.0 +0x256c0 |
| 35.85% | libgomp.so.1.0.0 +0x258a0 |
| 4.91% + 4.63% + 4.35% + 4.05% + ... | the same two instruction streams, sampled at successive IPs (skid) |
| 1.24% | [k] native_queued_spin_lock_slowpath |
93% of cycles in the OpenMP runtime, not one percent in the math. The engine issues ~720 parallel regions per decoded token -- three per expert application, 240 applications a token -- and every region is only a few thousand rows wide. At that size the barrier is the work.
The thread sweep
Same container, same prompt, same reference, cold cache, one variable:
OMP_NUM_THREADS |
expert disk | expert matmul | attention | prefill | decode | tok/s | exact |
|---|---|---|---|---|---|---|---|
| 8 | 15.93 s | 5.91 s | 4.61 s | 14.02 s | 17.34 s | 0.92 | 16/16 |
| 16 | 16.11 | 3.68 | 2.54 | 11.60 | 13.89 | 1.15 | 16/16 |
| 32 | 16.12 | 3.16 | 1.91 | 10.51 | 13.24 | 1.21 | 16/16 |
| 52 | 16.35 | 3.83 | 1.56 | 10.64 | 13.31 | 1.20 | 16/16 |
| 64 | 16.73 | 9.14 | 3.33 | 10.72 | 21.57 | 0.74 | 16/16 |
| 104 (physical cores -- what the helper picks) | 16.53 | 10.45 | 2.61 | 11.56 | 21.05 | 0.76 | 16/16 |
| 208 (the default) | 20.32 | 185.26 | 108.62 | 141.26 | 247.23 | 0.06 | 16/16 |
The default is 18.7x slower on decode than 32 threads and 11.7x slower than the 104 physical cores the shared helper selects. The 208 row was measured four separate times (185.26, 185.26... and 188.98 / 189.82 / 190.64 in other sessions), so it is not a fluke of one run.
Two details worth keeping:
- The disk phase moves too (20.32 s at 208 threads versus ~16 s at any sane size). A team of 208 spinning threads steals the memory bandwidth the expert reads need. The pathology is not confined to the arithmetic it appears in.
- Fewer than physical cores is faster still on this host. 32 threads beat 104 by
1.6x. That is why the fix is the documented, conservative setting (physical cores,
no SMT) and not a hard-coded 32: the helper's job is to remove the SMT doubling and
to respect an explicit
OMP_NUM_THREADS; finding this machine's optimum is whatOMP_NUM_THREADS=<n>is for.
The shipped default, before and after
The fix is #include "omp_tune.h" plus coli_omp_tune_threads("<engine>") as the
first statement of main -- the same call the four engines that already had it make.
No other change.
| shipped default | decode | whole turn | tok/s |
|---|---|---|---|
| before (208 logical threads) | 247.2 s | 409.9 s | 0.06 |
after (omp_tune.h -> 104 physical) |
18.6 s | 43.5 s | 0.86 |
Three cold runs after the change: wall 43.3 / 43.5 / 47.7 s, decode 18.64 / 18.55 /
20.96 s, 16/16 tokens each, and each run logging
[OMP] deepseek-v41: 104 physical-core threads instead of 208 logical CPUs.
13.3x on decode, 9.4x on the turn, 14.3x on tokens/second, identical output.
And the bottleneck moves back to where the other V4.1 work was aimed: at the fixed default the disk is 16.5 s of a 43.5 s turn (38%), against 5% before. That number was the whole basis of a separate negative result about multi-SSD streaming; it was measured in the pathological regime and does not survive the fix.
What this does not show
- One host. The ratio that makes this bite is logical:physical. A 16C/32T desktop is the #718 case (+2.3x); a 104C/208T server is this one. An engine on a host with no SMT sees nothing either way, which is why the helper stays silent there.
- The other three engines were not run.
glm53,qwen36andqwen38got the same one-line call and are covered by the source gate, but their containers were not available here, so their numbers are not claimed. The defect is identical by construction -- none of them called anything -- but "identical by construction" is not a measurement. deepseek_v4.cis not in this change. It already resizes its team (it reserves loader workers viaomp_set_num_threads(logical - COLI_V4_EXPERT_LOADER_COUNT)), so it is not the same omission. Whether that reservation should also be a physical-core sizing is a separate question, and it needs its own measurement rather than an assumption.
Reproduce
make -C c deepseek_v41
# the sweep: one variable, cold cache, token-exact gate on every run
for t in 8 16 32 52 64 104 208; do
SNAP=<container> OMP_NUM_THREADS=$t ./c/deepseek_v41 8 ref.json
done
# the profile
sudo perf record -F 299 -o /tmp/perf.data -- \
env SNAP=<container> ./c/deepseek_v41 8 ref.json
sudo perf report --stdio -i /tmp/perf.data --sort dso,symbol
Raw per-run engine stderr for the sweep and the before/after runs is attached to the
PR. The gate is python3 -m unittest tests.test_omp_engine_wiring.