Local LLM Inference: Why More CPU Threads Don't Always Mean Faster Tokens
This article explains why increasing CPU thread counts speeds up prompt prefilling but barely improves token generation in local LLM inference. Based on a controlled experiment on a dual-socket server, it compares two quantized models across thread counts, shows where generation throughput plateaus, and explains the memory-bandwidth and synchronization limits behind it. Readers will find reproducible benchmarking steps and practical guidance for thread tuning, memory selection, quantization trade-offs, and when to move inference to a cloud platform.
1. It Started With a Test Where Adding Threads Did Nothing
A reader ran a 4-bit quantized model in the 7B parameter range on a high-thread-count server and set inference threads to 64. Generation speed stayed around 6 tokens per second. His first guess was that the model was too small to keep the machine busy. That sounds plausible, but it points in the wrong direction. The problem was not model size. It was treating thread count as a knob that can be turned up indefinitely in exchange for performance.
To quantify this, I ran a controlled experiment on a dual-socket server. The platform has 20 physical cores and 40 logical threads, the operating system reports 80 available threads, and there is 128GB of memory with no discrete GPU. Using a processor affinity tool, I pinned the process to logical cores 0 through 19 on the first NUMA node to avoid cross-node memory access interference. Every run used the same workload: prefilling a 128-token prompt followed by generating 64 tokens one at a time. Each configuration was repeated twice, and the stable values were recorded. All tests used 4-bit medium-precision quantization.
2. Two Sets of Results: Same Parameter, Different Outcomes
First, the small model (weights around 1.1GB):
| Threads | Prefill tok/s | Generation tok/s |
|---|---|---|
| 1 | 22.27 | 7.83 |
| 2 | 39.70 | 13.46 |
| 4 | 72.28 | 23.10 |
| 8 | 147.88 | 27.48 |
| 16 | 270.58 | 27.73 |
| 20 | 321.27 | 27.71 |
Next, the 7B model (weights around 4.68GB):
| Threads | Prefill tok/s | Generation tok/s |
|---|---|---|
| 1 | 4.66 | 1.74 |
| 2 | 8.33 | 3.25 |
| 4 | 15.22 | 5.55 |
| 8 | 30.48 | 6.64 |
| 16 | 60.50 | 6.73 |
| 20 | 72.46 | 6.67 |
Look at the last two rows of the generation column. For the small model, going from 8 to 20 threads improved throughput by only 0.85%. For the 7B model, the gain was 0.52%. The 12 extra threads delivered improvements that land in the second decimal place, which is effectively noise.
The prefill column in the same tables tells a different story. The small model jumped from 147.88 to 321.27 tok/s, a 117% increase. The 7B model rose from 30.48 to 72.46 tok/s, a 138% increase, and the curve was still climbing at 20 threads. Same parameter, two outcomes. That is the real conclusion of this experiment.
3. Why This Happens: Two Phases With Different Compute Characteristics
CPU inference for large models has two phases, and they respond to parallelism very differently.
The prefill phase processes the entire input at once. The matrix multiplications are large and have high arithmetic intensity, making this a compute-bound task. With more threads, each thread handles a smaller chunk, cache pressure drops, and throughput grows close to linearly until memory bandwidth or core count becomes the limit.
The generation phase advances one token at a time. Every weight has to be read, but only a tiny amount of computation happens. This is a memory-bandwidth-bound task. The performance ceiling is set by weight bytes divided by available bandwidth, not by core count. The 4-bit weights of a 7B model are about 4.7GB. On a dual-channel memory platform, generating each token requires moving all 4.7GB again, and adding threads does not make memory wider.
There is another factor that is easy to overlook: synchronization overhead between threads. Parallelism in the generation phase is fine-grained. As thread count rises, the fixed cost of barrier synchronization and data exchange takes up a larger share, and the gains are quickly eaten up. This explains why the inflection point usually appears near 8 threads, which roughly matches the number of physical cores on this platform and marks the point where synchronization overhead starts to outweigh parallel gains.
4. A Reproducible Benchmarking Method
You do not need any specific toolchain. Standard industry benchmarking practices are enough:
- Fix the workload: keep prompt length and generation length consistent, run multiple rounds, and take the median.
- Fix affinity: use the operating system’s built-in processor binding to keep the process on a single NUMA node.
- Scan one variable: change only the thread count and leave everything else unchanged.
- Record the two phases separately: prefill and generation must be measured independently, because mixing them together will lead to the wrong conclusion.
The execution logic looks like this (command names are shown as generic placeholders):
# Bind to logical cores 0-19 on the first NUMA nodetaskset -c 0-19 <inference-benchmark-command> \--threads 8 \--prompt-tokens 128 \--gen-tokens 64 \--repeat 2
5. Tuning and Selection Recommendations
- Prioritize generation speed: set thread count close to the number of physical cores and do not exceed it. Put the budget into memory channel count and memory frequency. Moving from dual-channel to quad-channel memory pays off far more than adding cores.
- Prioritize document throughput: prefill can take advantage of more threads. Long-document summarization and batch extraction workloads are worth running on high-core-count platforms.
- Bind NUMA: on multi-socket machines, skipping affinity lets cross-node memory access cut generation speed further.
- Quantization trade-offs: lower bit widths reduce the amount of weight data that must be moved, and the improvement in generation speed is often more noticeable than thread tuning, at the cost of some accuracy.
- When to move to the cloud: as concurrent users grow and you need elastic scaling and stable latency, a container platform in the cloud can host the inference service, with object storage distributing model files and monitoring and alerting services tracking latency and throughput. Let the platform handle hardware selection instead of repeatedly tuning single-machine parameters.
The conclusion is simple: thread count is a lever for prefill, not for generation. First determine whether the bottleneck is compute or bandwidth, then decide whether to add threads, switch memory, or change platforms. That is how you avoid being misled by the intuition that more threads always means faster inference.
