Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

deepseek_v4: the physical cores by default on an SMT machine (#1906)

JustVugg578e9e817990
diff --git a/c/deepseek_v4.c b/c/deepseek_v4.c
index 1302ce94..48b430a9 100644
--- a/c/deepseek_v4.c
+++ b/c/deepseek_v4.c
@@ -16217,19 +16217,33 @@ static int v4_serve_main(void) {
#ifndef COLI_V4_SKIP_GENERATE_MAIN
#ifdef _OPENMP
+#include "omp_tune.h"
/* Size the OpenMP team so the block pipeline's persistent expert-loader
* workers keep whole CPUs. The OpenMP default team spans every logical CPU,
* which schedules compute threads onto the CPUs the loaders need -- and on a
* disk-bound decode the loaders are doing the rate-limiting work (the same
* rationale omp_tune.h records for the spin-wait half of the GLM tuning: a
- * busy team steals cores from the I/O pool). An explicit OMP_NUM_THREADS or
- * COLI_NO_OMP_TUNE=1 wins, exactly like the other engines' tuning. */
+ * busy team steals cores from the I/O pool). With SMT the team is the physical
+ * cores (the loaders take the siblings): the kernels are bound by memory
+ * bandwidth, and siblings contend for it (#718; on a Threadripper PRO 3975WX,
+ * 32 cores and 64 threads, 61 threads decoded 0.675 tok/s and 32 0.745, #1906).
+ * An explicit OMP_NUM_THREADS or COLI_NO_OMP_TUNE=1 wins, exactly like the other
+ * engines' tuning. */
static int v4_omp_reserve_loader_cpus(void) {
if (getenv("COLI_NO_OMP_TUNE")) return 0; /* family-wide kill-switch */
if (getenv("OMP_NUM_THREADS")) return 0; /* the user already chose */
int logical = omp_get_max_threads();
int team = logical - COLI_V4_EXPERT_LOADER_COUNT;
if (team < 2) return 0; /* tiny machine: leave the OpenMP default alone */
+ int phys = coli_physical_cores(); /* 0: not known, and then no guess */
+ if (phys > 0 && phys < logical && phys < team) {
+ omp_set_num_threads(phys);
+ fprintf(stderr, "[OMP] deepseek-v4: %d compute threads (the physical cores of %d logical "
+ "CPUs; the %d expert-loader workers take the SMT siblings); "
+ "OMP_NUM_THREADS=<n> overrides, COLI_NO_OMP_TUNE=1 disables\n",
+ phys, logical, COLI_V4_EXPERT_LOADER_COUNT);
+ return 1;
+ }
omp_set_num_threads(team);
fprintf(stderr, "[OMP] deepseek-v4: %d compute threads (%d logical CPUs "
"minus %d expert-loader workers); OMP_NUM_THREADS=<n> "
diff --git a/c/tests/test_cli_output.py b/c/tests/test_cli_output.py
index 9a973483..f6a6b592 100644
--- a/c/tests/test_cli_output.py
+++ b/c/tests/test_cli_output.py
@@ -362,8 +362,9 @@ class OmpThreadsForEveryEngineTest(unittest.TestCase):
"""Launchers size shared engines; V4 delegates to its loader-aware runtime.
#805's physical-core default still covers the memory-bound sister engines.
- DeepSeek V4 instead reserves logical CPUs for its expert-loader workers in
- v4_omp_reserve_loader_cpus(), unless the operator overrides or disables it.
+ DeepSeek V4 sizes its own team in v4_omp_reserve_loader_cpus() (the physical
+ cores with SMT, the loaders on the siblings; else the logical CPUs less its
+ expert-loader workers), unless the operator overrides or disables it.
"""
@classmethod