WorkerPool indexes subpool-sized vector by physical NUMA ID
Environment
- KTransformers /
kt-kernel:v0.7.0.post4 - CPU: dual-socket AMD EPYC 7443, 24 physical cores per NUMA node
- Runtime: SGLang KTransformers integration, one RAWINT4 CPU expert pool
- Relevant arguments:
--kt-threadpool-count 1 --kt-cpuinfer 24 --kt-numa-nodes 1
Symptom
A single 24-thread pool on physical NUMA node 1 logs missing cores:
WorkerPool[...] 1 subpools, [numa:threads][1:24]
In Numa Worker Pool at NUMA 1, 24 threads
Core 19 inside NUMA node 1 not found
Core 20 inside NUMA node 1 not found
Core 21 inside NUMA node 1 not found
Core 22 inside NUMA node 1 not found
Core 23 inside NUMA node 1 not foundThe equivalent pool on NUMA node 0 binds all 24 threads correctly.
Inspecting /proc/<pid>/task/*/status showed that the NUMA-1 worker names began
at numa_1_t_6: 18 workers were singularly pinned to physical cores 6-23
within the node, while five retained the broader node-local affinity.
Cause
WorkerPool::init() sizes numa_threads_count by config.subpool_count but
indexes it by the physical NUMA ID:
std::vector<int> numa_threads_count(config.subpool_count, 0);
// ...
auto this_numa = config.subpool_numa_map[i];
auto this_thread_id_start = numa_threads_count[this_numa];For one subpool mapped to NUMA ID 1, this reads and later writes element 1 of a one-element vector. The resulting undefined value became 5 in this process, which explains the shifted affinity and missing-core messages.
Suggested fix
Size the counter array for the largest configured physical NUMA ID (or use a map keyed by NUMA ID), for example:
std::vector<int> numa_threads_count(
*std::max_element(config.subpool_numa_map.begin(), config.subpool_numa_map.end()) + 1,
0);I am testing this backport against the AVX2 RAWINT4 path and can add the before/after result once complete.
Source: kvcache-ai/ktransformers