Manuscript Offprint
arXiv:2611.07105NUMA-Torch: Compiler-Driven NUMA-Aware LLM Prefill on Multi-Socket CPUs
Thisara Rathnayaka Weerakoon®, Ishan Dewpura®, Niman Ransindu®, Shavin Anjitha®, Tharindu R. Patabandi®†, Sanath Jayasena®*
*Dept. of Computer Science & Engineering, University of Moratuwa, Sri Lanka {thisara.21, ishandewpura.21, niman.21, shavin.21, sanath}@cse.mrt.ac.lk
†Independent Researcher, San Jose, CA, USA
Abstract—For sufficiently large transformer-based Large Language Models (LLMs), whose parameters cannot be retained in on-chip caches, prefill throughput on multi-socket CPUs is often limited by sustainable DRAM bandwidth rather than peak floating-point throughput. In the standard PyTorch compilation (i.e., TorchInductor) path, model weights are allocated without considering the Non-Uniform Memory Access (NUMA) topology—specifically, the affinity between memory banks and compute cores is disregarded. This causes a substantial fraction of weight accesses to traverse the inter-socket interconnect, severely degrading the effective memory bandwidth available to each socket. We address this bottleneck through a compiler-level solution that makes TorchInductor NUMA-aware. Treating each NUMA socket as an independent tensor-parallel partition, we introduce NUMA-aware Tensor Parallelism (NUMA-TP). This approach transparently shards weights across sockets and schedules compute kernels such that thread pools and memory allocations remain strictly local to their respective sockets using CPU affinity. We evaluate the approach on GPT-2 [1] (117M, 345M, 762M) and BERT [2] (Small, Large), which exercise standard multi-head attention and MLP, as well as Gemma 3 270M [3], which combines Multi-Query Attention with a GeGLU-gated MLP. By strictly enforcing data locality, our approach successfully mitigates cross-socket traffic, achieving prefill speedups of up to 2.63× on a dual-socket Haswell platform, up to 1.87× on a dual-socket Cascade Lake platform, and up to 2.27× on a four-socket Haswell-EX platform.
Index Terms—Compilers, Data Locality, NUMA, Tensor Parallelism, Large Language Models, CPU inference
I. INTRODUCTION
Driven by the necessity of accommodating many cores, modern high-performance servers have universally adopted Non-Uniform Memory Access (NUMA) architectures [4]. There is consequently a tremendous, yet underutilized, potential to deploy Large Language Model (LLM) inference on these multi-socket CPU platforms, given their cost-effectiveness, broad availability, and the frequent absence of GPUs in

Fig. 1. Logical view of a two-socket NUMA CPU treated as a distributed system; the dashed arrow marks a high-cost remote DRAM access across the cross-socket interconnect.
deployment environments. The prefill phase of LLM inference which processes the full input prompt in one forward pass is traditionally assumed compute-bound owing to the high arithmetic intensity of dense matrix multiplications over long sequences. Yet on multi-socket CPUs under the standard TorchInductor compilation pipeline, prefill unexpectedly becomes severely DRAM-bound as NUMA-oblivious memory allocations force massive cross-socket traffic.
As illustrated in Figure 1, we view each socket of a multi-socket NUMA CPU as an independent node owning its locally attached DRAM and memory controller, together with cores that have private L1/L2 caches and share an L3. Sockets are linked by a QPI/UPI interconnect serving as the inter-rank network; accesses to another socket's memory must cross it, incurring substantially higher latency and lower bandwidth than local accesses, and are therefore treated as explicit communication in our compilation model.
In standard execution, compute threads are distributed across all cores without regard to data locality, causing roughly half of all weight accesses to incur remote DRAM latency and saturating the inter-socket link. To empirically validate this, we conducted a Roofline analysis using Intel Advisor [5] on the kernels that dominate the prefill phase of a GPT-2 345M model [1] (batch size 1, sequence length 4096) on a dual-socket Haswell platform (Figure 2). For TorchInductor-compiled unmodified Triton-CPU baseline (circles), these kernels exhibit poor data locality and sit near the main-DRAM bandwidth ceiling, confirming that the prefill operates firmly in the DRAM-bound regime. Our NUMA-Torch path (triangles)
© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works. Accepted for publication in the 2026 IEEE 33rd International Conference on High Performance Computing, Data, and Analytics (HiPC), Bengaluru, India, December 16–19, 2026. This is the authors' accepted version; the final published version will appear in IEEE Xplore.

Fig. 2. Roofline analysis on dual-socket Haswell: baseline Triton CPU kernels (circles) versus the NUMA-Torch path (triangles) for the dominant GPT-2 345M prefill kernels (batch size 1, sequence length 4096). Arrows indicate the per-kernel trajectory from baseline to NUMA-Torch.
improves core-to-memory affinity and, as the trajectory arrows indicate, shifts the kernels toward the higher-bandwidth L3 and L2 cache tiers, increasing overall throughput (GFLOPS).
Despite this architectural reality, existing CPU optimization efforts frequently overlook the NUMA penalty, focusing on intra-core compute optimizations. Addressing this NUMA-induced DRAM bandwidth wall must instead be the primary objective, and the most direct solution is strict enforcement of data locality: explicitly placing weights in socket-local DRAM via NUMA-aware memory allocation, and binding computations to the corresponding cores via NUMA-aware thread scheduling.
While mainstream frameworks for CPU inference, such as llama.cpp [6], deliver high baseline performance, they are not explicitly optimized for NUMA data locality. Recent work such as ArcLight [7] addresses this memory bottleneck through cross-NUMA tensor parallelism. However, because ArcLight is a custom inference engine written entirely in C++, it relies heavily on manual engineering and requires the model code to be meticulously rewritten to support different LLM architectures. In this work, we focus on lifting cross-NUMA Tensor Parallelism into PyTorch 2.0's compiler ecosystem [8] to provide a PyTorch-native implementation. By extending the standard TorchInductor pipeline, our transformations remain entirely transparent to the user, requiring zero modifications to the model code, optimizer, or the inference loop.
We present the first compiler-based, PyTorch-native implementation of NUMA-aware tensor parallelism targeting multi-socket CPUs. We make the following contributions:
- A compiler-driven solution to the NUMA DRAM bottleneck that leverages post-grad FX graph transformations to partition operations across sockets, minimizing manual engineering overhead.
- An extended Triton-CPU backend [9], [10] that emits per-socket buffer allocations and dispatches kernels via a persistent, NUMA-aware thread pool.
- An evaluation of the compiler approach across standard models (GPT-2 [1], BERT [2]) and modern LLMs with complex attention and MLP variants (Gemma 3 [3]),

Fig. 3. Overview of NUMA-Torch: NUMA-Torch extends TorchInductor and Triton-CPU compilation stacks with NUMA-aware tensor parallel graph transformations, per-socket buffer placement, and a NUMA-aware runtime that dispatches kernels to socket-pinned worker groups. The NUMA partitioning schema (folded-corner note) is not a pipeline stage: it is per-block metadata emitted by the NUMA passes at FX-graph level and consumed by the wrapper code generator when materializing socket-local buffers (dashed arrows).
showing up to 2.63× prefill speedup on dual-socket platforms, comparing against process-level NUMA policies (numactl), and assessing scalability from dual-socket to four-socket platforms.
This work targets the prefill phase at fixed shapes. Throughout, “end-to-end prefill” denotes a single prefill forward pass at a fixed shape, not end-to-end serving: we measure prefill in isolation, so decode, continuous batching, KV-cache placement, and serving-level metrics are outside the evaluation.
Figure 3 illustrates the overall design of our approach, which we refer to as NUMA-Torch. NUMA-Torch is built on top of TorchInductor and Triton-CPU, extending the compiler pipeline with NUMA-aware graph transformations, socket-local buffer management, and affinity-aware kernel dispatch. Section II describes each component of this pipeline in detail.
Section III provides a comprehensive evaluation of NUMA-Torch, Section IV discusses related literature, and we present concluding remarks in Section V.
A. Explicit NUMA Placement via Extended Clone Semantics
Effective NUMA-aware tensor parallelism requires precise control over where a tensor's physical memory resides. In standard PyTorch, the clone operator creates a semantically independent copy. However, it does not let callers specify which socket's DRAM will hold the copy. Instead, cloned shards follow the calling thread's first-touch allocation policy [11], so physical pages land in the memory bank of whichever socket's thread first writes each virtual address. This typically concentrates storage in one socket's DRAM, causing severe cross-interconnect traffic during subsequent parallel computation.
To resolve this limitation, we extend the native PyTorch clone operator by introducing an explicit NUMA placement parameter. This modification empowers the runtime to bypass default allocation policies [11] and assign each tensor replica to a specific DRAM socket at the exact moment of creation, leveraging the Linux mbind system call [12].
This extended functionality provides a straightforward, Pythonic interface for tensor sharding across socket DRAMs. For example, a global weight matrix can be easily partitioned along its rows and distributed across multiple sockets using the new numa_node argument:
Global weight matrix; defaults to first-touch allocation
weight = torch.randn(4096, 4096)
Place tensor partitions across distinct DRAM sockets
shard_0 = weight[:,2048, :].clone(numa_node=0) shard_1 = weight[:,2048:, :].clone(numa_node=1)
B. NUMA-Aware Tensor Parallelism
With NUMA-aware data allocation established, the subsequent challenge is NUMA-aware computation scheduling. Rather than relying on manual engineering, we use the compiler to automatically identify and schedule computations, which requires a robust underlying scheduling model. To formulate this model, a multi-socket CPU can be abstracted as a distributed system. Each socket acts as an independent node consisting of its compute cores and local DRAM. The sockets are connected by an interconnect such as Intel's QuickPath Interconnect (QPI) or Ultra Path Interconnect (UPI).
In distributed multi-GPU cluster environments, a fundamental goal is to reduce communication overhead to accelerate both training and inference. To mitigate these bottlenecks, works such as Megatron-LM [13] utilize tensor parallelism to minimize synchronization points within the Multi-Layer Perceptron (MLP) and attention blocks [14]. Similarly, the primary performance bottleneck in our multi-socket CPU topology is the latency and bandwidth limitation of cross-socket communication. Therefore, we adapt this tensor parallelism strategy to our single multi-socket CPU environment to minimize cross-NUMA socket communication.
We now detail how NUMA-aware Tensor Parallelism (NUMA-TP) is applied to the MLP, multi-head attention, and normalization sub-blocks that comprise a transformer layer.
- MLP Block: Consider the MLP block of GPT-2, which consists of two GEMMs separated by a GeLU activation, followed by , where X is the input activation and A, B are the weight matrices. As shown in Algorithm 1, we partition the up-projection A column-wise and the down-projection B row-wise. Each socket i computes its shard of the intermediate activation and the matching partial output entirely from socket-local memory. Because matrix multiplication distributes over addition, the partial outputs are combined with a single cross-socket all-reduce, , confining inter-socket traffic to one activation-sized reduction per block.
Algorithm 1: NUMA-TP MLP Block
Input: activation X; up-projection A; down-projection B; socket count N
Output: output activation Z
1 Partition A column-wise and B row-wise across the N sockets 2 foreach socket i ∈ {0, ..., N - 1} in parallel do 3 Y^i ← GeLU(XA^i) // column-parallel up-proj. 4 Z^i ← Y^i B^i // row-parallel down-proj. 5 Z ← ∑_{j=0}^{N-1} Z^i // cross-socket all-reduce 6 return Z
- Multi-Head Attention Block: The same column-then-row split extends to multi-head attention, following the Megatron-LM [13] decomposition. The query, key, and value projections are partitioned column-wise so that each socket owns a disjoint subset of attention heads, while the output projection is partitioned row-wise. Because heads are independent within scaled dot-product attention, every socket evaluates its local attention without exchanging queries, keys, values, or scores across sockets. The block then closes with a single all-reduce over the per-socket partial outputs, as detailed in Algorithm 2.
Algorithm 2: NUMA-TP Multi-Head Attention Block
Input: activation X; projections ; output bias ; per-head dimension ; socket count N
Output: output activation Y
1 Partition column-wise and row-wise across the N sockets 2 foreach socket i ∈ {0, ..., N - 1} in parallel do 3 Q^i, K^i, V^i ← XW_Q^i, XW_K^i, XW_V^i 4 Z^i ← softmax(Q^i(K^i)^\top / √d_k) V^i // owned heads 5 Y^i ← Z^i W_O^i // row-parallel out-proj. 6 Y ← ∑_{i=0}^{N-1} Y^i + b_O // all-reduce, add bias 7 return Y
- Normalization Block: Layer normalization and RMS normalization require a different strategy. Instead of computing the normalization on a single socket and broadcasting the result, NUMA-TP replicates this computation on every socket, as shown in Algorithm 3. Each socket maintains its own normalized copy and feeds it directly to the next local kernel. This completely eliminates the need for cross-NUMA data movement, such as an all-reduce operation. We selected this strategy empirically on multi-socket platforms, where this redundant computation proved cheaper than the eliminated inter-socket communication.
Algorithm 3: NUMA-TP Normalization Block (Layer-Norm / RMSNorm)
Input: activation ; normalization parameters ; socket count Output: per-socket normalized activations
1 Replicate to all sockets // weights not shared 2 foreach socket in parallel do 3 // local input copy 4 // replicated full norm 5 return // no all-reduce
def forward(self, x): # Input activation 'x' has shape [s, h]
1. Up-projection:
# - linear_1 applies weight A of shape [h, d]
# - Output y expands to intermediate shape [s, d]
y = self.linear_1(x)
2. Element-wise activation
# - Maintains the shape [s, d]
y = torch.nn.functional.gelu(y)
3. Down-projection:
# - linear_2 applies weight B of shape [d, h_out]
# - Output z is projected to the terminal shape [s, h_out]
z = self.linear_2(y)
return z
Fig. 4. Standard PyTorch forward definition of the MLP block.
C. FX Graph Transformation for Tensor Parallelism
Since our approach focuses on applying tensor parallelism within the PyTorch compilation pipeline, the standard PyTorch definition of the MLP block, shown in Figure 4, serves as our starting point. Here, s denotes the sequence length, h the input hidden dimension, d the MLP intermediate dimension, and the output dimension.
As illustrated in Figure 5a, TorchDynamo [8] traces this module (Figure 4) into an FX graph that sequentially projects an input to an intermediate activation, applies a decomposed pointwise GeLU subgraph, and projects it to a final output.
To apply tensor parallelism at FX graph level, we rely on a custom post-grad FX pass that captures the canonical Linear Activation Linear pattern and transforms its execution topology, as illustrated in Figure 5b. To illustrate this transformation, consider a dual-socket CPU (N = 2) similar to the depiction in Figure 1. The parallelization pass injects aten.slice.Tensor nodes into the fx graph (Figure 5b). Fundamentally, aten.slice.Tensor is an Aten library operation [15] that extracts a contiguous sub-region of a tensor along a specified dimension.
As discussed in Section II-B, the up-projection weight matrix is sliced along its columns (the axis) to yield local shards of shape . For a generalized -socket system, this is achieved via the operation:
where denotes the target NUMA socket index for that specific compute shard.
Similarly, for the down-projection, the weight matrix is sliced along its rows (the axis) to produce shards of shape . The corresponding operation is:
As established in Section II-B, yielding the correct final output Z requires an element-wise reduction (addition) of the partial results computed by each socket. However, the N-way reduction node is absent from the transformed FX graph in Figure 5b.
This omission is a deliberate architectural choice, rooted in the fact that the FX graph maintains a “Single-Program, Multiple-Data” (SPMD) representation. The graph does not instantiate N separate matrix multiplication (mm) nodes; instead, there is exactly one logical mm node whose dimension metadata has been scaled down from the global [s, d] to the local [s, d/N]. Because the graph encodes the execution logic for a single generic shard, there are no N distinct partial-sum nodes in the intermediate representation to combine.
Consequently, the physical parallelization and the N-way reduction are deferred entirely to the code-generation phase (discussed in Section II-E). The actual existence of N separate partial outputs only manifests at runtime when the wrapper codegen allocates N independent buffers and launches the identical kernel N times across the hardware domains.
D. The NUMA Partitioning Schema: Bridging Graph Transformations and Code Generation
The NUMA partitioning schema is the metadata bridge between the mathematical rewriting performed in the FX graph and the physical multi-socket allocation performed by the backend code generator. As depicted in Figure 3, it records for each tensor its placement policy (column-parallel, row-parallel, or replicated), which the wrapper code generator later uses to materialize socket-local buffers. In the MLP block above, the up-projection A is column-parallel, the down-projection B row-parallel, and the input activation X replicated across all sockets.
E. Wrapper Code Generation and Buffer Materialization
So far the partitioning exists only as metadata, with no buffer allocated and no page bound to a socket. Both happen in the code TorchInductor generates, which is Triton-CPU kernel code [10] together with the Python wrapper code that drives it. The wrapper function call allocates each buffer, places it, and only then launches the kernels that read it. For every kernel argument it consults the schema, classifies the tensor as a column shard, a row shard, or a full replica, and emits the matching slice with a clone (numa_node=i). That explicit numa_node binds shard i's pages to socket i's DRAM at creation instead of leaving them to first touch. Because each placement finishes before the kernel that reads it is launched, every socket's kernel finds its operands already local. The FX

Fig. 5. FX graph transformation for NUMA-aware tensor parallelism: (a) The baseline AOTAutograd FX graph for the MLP block contains an up-projection, decomposed GeLU activation, and down-projection. (b) The NUMA-TP post-grad pass rewrites the graph by inserting slice nodes that encode per-socket weight shards and shard-plan metadata, allowing physical placement and per-socket execution to be deferred to code generation.
pass therefore states only how a block is partitioned; wrapper code generation is where its shards first acquire physical pages.
This stage also decides which socket-local buffers can be reused across adjacent kernels. When an activation produced on socket is consumed immediately by another NUMA-parallel kernel on the same socket, the wrapper records it in a per-socket cache instead of constructing a global tensor and slicing it again. In the MLP example, the column-parallel up-projection output stays local and feeds the row-parallel down-projection consuming , so the only cross-socket step is the reduction that closes the block.
Because the final reduction is not explicit in the FX graph (Figure 5b), the wrapper must know whether a kernel produces a still-local intermediate or a value closing the NUMA-parallel region. The distinction matters most after fusion, where one lowered kernel may contain both matrix multiplication and pointwise operations. We therefore attach an output tag to each generated value, and the wrapper uses it to choose one of two reconciliation paths, shown for a dual-socket system in Figure 6:
-
Intermediate activations (Figure 6a): Outputs from column-parallel projections and fused pointwise operations remain socket-local. The wrapper stores each shard in the per-socket cache and forwards it to the next local kernel without reduction.
-
Terminal partial sums (Figure 6b): Outputs from row-parallel projections, such as the MLP down-projection or the attention output projection, represent partial values . Before such a value leaves the NUMA-parallel block,
the wrapper inserts the all-reduce loop that sums the per-socket partial outputs into the final tensor .
F. NUMA-Aware Kernel Dispatch and Deferred Reassembly

Fig. 6. The two buffer-reconciliation patterns chosen by the wrapper from each value's semantic output tag. (a) Outputs of column-parallel kernels and fused pointwise ops are tagged as intermediate activations: each per-socket shard stays in socket-local DRAM, is held in the per-socket cache, and is forwarded to the next local kernel with no cross-socket communication. (b) Outputs of row-parallel kernels are tagged as terminal partial sums ; before the value leaves the NUMA-parallel block, the wrapper emits a single cross-socket all-reduce that sums the partials into the final tensor .
After the wrapper has placed each tensor shard in its socket-local memory, execution is handed to the Triton-CPU launcher. In the unmodified backend, this launcher runs a kernel as a single program replicated across many parallel work items, but it treats the machine as one flat pool of cores with no notion of NUMA locality. As a result, even when a shard lives in a particular socket's DRAM, the default launcher gives no
Algorithm 4: NUMA-Aware Kernel Launch
Input: kernel K; its set of parallel work items G; when NUMA-tagged, the per-socket local operands and the socket each shard belongs to; thread budget T
Output: K executed, with every socket writing its output shard into local memory
1 if K is tagged for NUMA execution then 2 N ← number of sockets in the per-socket operands 3 T ← max(T, N) 4 Split the T threads into N groups of , one per socket 5 foreach socket in parallel do 6 ← cores belonging to socket 7 foreach worker j in socket i's group of threads do 8 bind worker j to a core in 9 run K on worker j's share of G, reading 10 wait for all groups to finish 11 else 12 run K through the default, NUMA-oblivious launch
guarantee that the threads using that shard run on cores of the same socket. Many instead run on a remote socket, paying the interconnect penalty and undoing the placement the wrapper performed.
We therefore extend this launch path with a NUMA-aware dispatch layer, summarized in Algorithm 4. Each time a kernel is launched, the layer checks whether the compiler has marked it for NUMA execution (i.e., whether the wrapper has attached the per-socket operands together with a note of which socket each shard belongs to). If this annotation is absent, the kernel is launched through the original NUMA-oblivious path, and hence, ordinary non-sharded operations are left untouched. If it is present, the launcher takes the NUMA-aware path described next.
On this path, the launcher turns the single-program, multiple-data view of the FX graph into execution along two levels of parallelism. Across sockets, every socket runs its own copy of the kernel over the full set of work items, reading only that socket's local shards, so no socket reaches across the interconnect for data. Within a socket, the work is shared among a group of threads. The launcher first fixes a total thread budget, taking either the parallelism the kernel requests or the available hardware threads, but never fewer than one thread per socket. It then splits that budget into N roughly equal groups, one for each socket, and binds every group's threads to cores of its own socket as reported by the OS topology. No thread therefore drifts onto another socket. The launcher waits for every group to finish, so the per-socket kernels complete together. With this binding in place, each thread runs on the socket that physically holds the shard it touches. This is what closes the locality gap left by the default launcher.
This dispatch policy completes the path from graph rewriting to execution: the FX pass marks an operation as shardable, the schema records how each of its tensors should be placed, the wrapper prepares the socket-local operands, and the launcher runs one kernel instance per socket. Reassembly is left to the wrapper rather than the launcher and is deferred until a value actually needs to be combined (Figure 6). A value consumed
only by another NUMA-aware kernel stays split, so the wrapper keeps the per-socket buffers and forwards them as they are. A value that is a final partial sum, or that is about to leave the parallel region, is closed with the cross-socket all-reduce described earlier, after which the reassembled tensor re-enters the ordinary PyTorch program.
III. EXPERIMENTAL EVALUATION
A. Experimental Setup
We evaluate NUMA-Torch, on three Intel Xeon platforms: two dual-socket machines (CascadeLake and Haswell) and one four-socket machine (Haswell-EX), the last sharing the Haswell microarchitecture with the dual-socket Haswell server so that comparing the two isolates the number of NUMA domains. Table I summarizes the hardware and Table II the software stack.
TABLE I HARDWARE SPECIFICATIONS OF THE THREE EVALUATION PLATFORMS
| Specification | CascadeLake | Haswell | Haswell-EX |
|---|---|---|---|
| Processor | Xeon Gold 6253CL | Xeon E5-2620 v3 | Xeon E7-4820 v3 |
| Microarchitecture | Cascade Lake | Haswell | Haswell |
| Total vCPUs | 60 | 24 | 80 |
| Cores per socket | 15 | 6 | 10 |
| Sockets / NUMA nodes | 2 | 2 | 4 |
| Clock speed | 3.10GHz | 2.40GHz | 1.90GHz |
| L3 cache | 49.5 MiB | 30 MiB | 100 MiB |
| Environment | GCP c2-standard-60 | Server (bare metal) | Server (bare metal) |
TABLE II SOFTWARE CONFIGURATION
| Component | Dual-socket | Four-socket |
|---|---|---|
| Operating system | Ubuntu 20.04 LTS | Ubuntu 24.04 LTS |
| Linux kernel | 5.15 | 7.0 |
| Python | 3.8 | 3.9 |
| PyTorch | 2.6.0a0 (torch.compile / TorchInductor) | |
| Triton-CPU | commit 7e394470 | |
| LLVM (Triton-CPU backend) | 19 (commit adba14a) |
B. Models and Configurations
We evaluate three model families, summarized in Table III. GPT-2 [1] (decoder-only) and BERT [2] (encoder-only) exercise the core column- and row-parallel FX passes with standard multi-head attention, while Gemma 3 270M [3] additionally tests the KV-replication path for Multi-Query Attention (MQA) [16] () and the GeGLU-gated MLP pass.
TABLE III ARCHITECTURAL PARAMETERS OF EVALUATED MODELS
| Family | Model | Params | Layers | d_model | Heads () | n_kv | MLP type |
|---|---|---|---|---|---|---|---|
| GPT-2 [1] | 117M | 117M | 12 | 768 | 12 | 12 | GeLU |
| 345M | 345M | 24 | 1024 | 16 | 16 | GeLU | |
| 762M | 762M | 36 | 1280 | 20 | 20 | GeLU | |
| BERT [2] | Small | 29M | 4 | 512 | 8 | 8 | GeLU |
| Large | 340M | 24 | 1024 | 16 | 16 | GeLU | |
| Gemma 3 [3] | 270M | 270M | 18 | 640 | 4 | 1 | GeGLU |
For each model we measure the mean prefill latency (ms) across a representative sweep of batch-size and sequence-length configurations. Each latency data point discards 10 warm-up iterations and averages the wall-clock time of 50 timed iterations, ensuring that compilation artifacts and cold-cache effects are excluded from reported figures.
On CPU, TorchInductor generates C++/OpenMP code by default [8]. We instead select Triton-CPU [10] as the CPU code-generation backend through torch._inductor.config.cpu_backend, because NUMA-TP needs control of the kernel launch path in order to bind thread groups to sockets. Both configurations below use it, so reported speedups are relative to Triton-CPU and do not transfer as absolute latencies to the default C++/OpenMP backend.
The baseline is torch.compile with unmodified TorchInductor and the unmodified Triton-CPU backend. NUMA-Torch modifies both, as described in Section II.
C. Performance Results
The mean prefill execution times of NUMA-Torch are presented as per-configuration heatmaps in Figure 7, spanning every evaluated model across the full sweep of batch sizes and sequence lengths on both the Haswell and Cascade Lake architectures.
We evaluate the end-to-end prefill speedup of the NUMA-Torch compiler extension relative to the baseline. As established by our initial roofline analysis, the baseline prefill phase is bottlenecked by main memory bandwidth. By strictly enforcing data locality via our NUMA-aware tensor parallelism passes, NUMA-Torch successfully mitigates cross-socket interconnect traffic, unlocking speedups of up to 2.63× on Haswell and 1.87× on Cascade Lake for all evaluated transformer architectures (Figure 8).
-
Architectural Impact (Haswell vs. Cascade Lake): The gain tracks the number of cores per socket. On Haswell (Figure 8a), with just 6 cores per socket, speedups frequently exceed 2.0× at sequence lengths of 1024 and above: with few cores, NUMA-oblivious scheduling drives a high volume of remote traffic through each core, so threads stall on QPI fetches and the baseline is highly inefficient. Cascade Lake (Figure 8b), with 15 cores per socket, spreads that traffic across more threads, dampening the baseline's cross-socket bottleneck; speedups are accordingly more moderate but highly consistent, ranging from 1.10× to 1.87×.
-
Impact of Model Scale and Architecture: Larger hidden dimensions and weight matrices yield higher relative speedups, placing a heavier burden on the memory sub-system: on Haswell at batch size 8, GPT-2 [1] (345M) peaks at 2.63× (sequence length 256) against 2.10× for the smaller BERT [2] (Small) under identical conditions. Gemma 3 [3] (270M) combines Multi-Query Attention with a GeGLU-gated MLP. It improves robustly as well, reaching 1.96× on Haswell and 1.76× on Cascade Lake, which confirms that the FX transformations generalize to heterogeneous sub-layers without model code rewrites.
-
Batch Size and Sequence Length Scaling: The optimizations scale efficiently as workload size grows. For long-

(a) Haswell (Intel Xeon E5-2620 v3, 6 cores/socket)

(b) Cascade Lake (Intel Xeon Gold 6253CL, 15 cores/socket)
Fig. 7. Mean prefill execution time of NUMA-Torch, for every evaluated model across the full sweep of batch sizes (rows) and sequence lengths (columns), on the dual-socket (a) Haswell and (b) Cascade Lake platforms. Each cell is annotated with the mean wall-clock time of one prefill call in seconds; the logarithmic color scale, shown above each heatmap, is set independently per platform. Over all measured configurations, the coefficient of variation of prefill time has mean 1.58% (max 6.74%) on Haswell and mean 4.43% (max 26.23%) on Cascade Lake.
context workloads intermediate activations dominate the prefill footprint.
Figures 7 and 8 together report every evaluated configuration in absolute and relative terms, where the savings at the longer sequence lengths reach multiple seconds per prefill call.
D. Comparison with Process-Level NUMA Policies
Do the operating system's own placement knobs already recover this benefit? We re-ran the full 144-configuration Cascade Lake sweep under three numactl policies [17], each measured against default first-touch allocation (Table IV).
None of the three comes close, and each falls short for a different reason. Interleaving reaches a geometric-mean speedup of only 1.08× and a median speedup of 1.02×. Round-robin placement equalizes which memory controller serves a request, but no access becomes local. It removes bandwidth imbalance and leaves the interconnect volume that Figure 2

(a) Haswell (Intel Xeon E5-2620 v3, 6 cores/socket)

(b) Cascade Lake (Intel Xeon Gold 6253CL, 15 cores/socket)
Fig. 8. End-to-end prefill speedup of NUMA-Torch over the unmodified Triton-CPU baseline for every evaluated configuration, grouped by model, batch size, and sequence length, on the dual-socket (a) Haswell and (b) Cascade Lake platforms.
identifies as binding. It is also the least reliable policy, running slower than default in 44 of 144 configurations.
localalloc is the best of the three by geometric-mean speedup, at 1.12×, and still recovers little. Two limits explain why. No process-level policy can shard a tensor, so each weight matrix lands whole on one socket and the other socket reads all of it remotely. First-touch locality also fails to survive execution, because TorchInductor's NUMA-oblivious thread pool means the thread that first touches a buffer is rarely the one that reads it. NUMA-Torch removes both limits, pairing clone (numa_node=i) placement with thread-group binding.
Single-socket execution is the most informative control. Its locality is perfect by construction, yet its geometric-mean speedup is only 0.59×, making it the worst option by a wide
margin; it runs slower than default in 143 of 144 configurations. It trades all remote traffic for half the cores and half the bandwidth.
NUMA-Torch reaches a geometric-mean speedup of 1.38× and a median speedup of 1.44×, and it is alone in never running slower than default, doing so in 0 of 144 configurations. The goal is not locality alone, but locality without sacrificing the machine's full compute and memory bandwidth.
TABLE IV PROCESS-LEVEL NUMA POLICIES ON CASCADE LAKE
| Policy | Geo. mean | Median | Worse than default |
|---|---|---|---|
| --interleave=all | 1.08× | 1.02× | 44/144 |
| --localalloc | 1.12× | 1.06× | 19/144 |
| Single socket (--cpunodebind=0 --membind=0) | 0.59× | 0.59× | 143/144 |
| NUMA-TP (this work) | 1.38× | 1.44× | 0/144 |

Fig. 9. End-to-end prefill speedup of NUMA-Torch over the unmodified Triton-CPU baseline on the four-socket Haswell-EX platform, as the geometric mean over all models and batch sizes at each sequence length. The dashed line marks parity; in the shaded region the geometric mean exceeds 1.0×.
E. Scaling to Four NUMA Domains
We repeat the evaluation on the four-socket Haswell-EX platform of Table I, sweeping the same six models over same batch size and sequence length configurations. Figure 9 reports the resulting speedups.
Speedup rises monotonically with sequence length, from a geometric mean of 0.48× at s=128 to 1.56× at s=4096, crossing 1.0× between s=1024 and s=2048. Every measured configuration at s ≥ 2048 is faster than the baseline, with a geometric mean of 1.38× and a peak of 2.27× for BERT Small at B=2 and s=4096, where the mean prefill time falls from 25.8 s to 11.3 s. No configuration at s ≤ 512 is faster than the baseline. Lower speedups at the shorter sequence lengths are expected on this platform, for two compounding reasons. Both reasons are already present on the dual-socket platforms and simply combine unfavourably here. The first is amortization. Thread-group binding, the barrier (Algorithm 4), and the all-reduce cost about the same per kernel whatever the kernel computes, while the work each socket does shrinks as domains are added. A socket here takes a quarter of the partitioned intermediate width rather than a half, and every reassembly point closes with a four-way all-reduce rather than a two-way one. At short sequence lengths the per-socket GEMM is then too small to cover that fixed cost. The second reason is how much there was to recover in the first place. The Haswell and Cascade Lake comparison already showed the gain shrinking as cores per socket rise, because more threads spread the baseline's remote traffic (Figure 8b). With 10 cores per socket against dual-socket Haswell's 6, the baseline here is less stressed to begin with.
Figure 10 reports every individual configuration. Of the 144, the 120 shown are measured; the remaining 24 could not be measured on this 64 GB host, as the per-socket sharing of activations places their working set beyond available memory.

Fig. 10. End-to-end prefill speedup of NUMA-Torch over the unmodified Triton-CPU baseline on the four-socket Haswell-EX platform, for every evaluated model, batch size and sequence length. Cells are colored about 1.0×, so green cells are faster than the baseline and red cells slower.
IV. RELATED WORK
A. LLM Inference Optimizations on CPUs
A substantial body of work has sought to alleviate the compute and memory bottlenecks of executing large language models (LLMs) on CPU architectures. Foundational software efforts like llama.cpp deliver high baseline performance for CPU inference through highly optimized, manually engineered C/C++ backends [6]. Similarly, specialized frameworks such as ArcLight address the memory bottleneck via cross-NUMA tensor parallelism on many-core CPUs [7]. However, because these are custom inference engines written entirely in C++, they rely heavily on manual engineering and require meticulous rewriting of model code to support different LLM architectures [7]. In contrast, our compiler-driven approach integrates seamlessly into the standard TorchInductor pipeline, remaining entirely transparent to the user without requiring modifications to the model code or inference loop.
Algorithmic and hardware-aware optimizations have also been extensively explored to maximize CPU efficiency. Shen et al. proposed an automated INT4 weight-only quantization flow paired with tailored runtime kernels to accelerate CPU deployment [18]. He et al. introduced KV cache size reduction techniques and distributed inference optimizations relying on the oneAPI Collective Communications Library (CCL) [19]. At the architectural level, Dice and Kogan detailed software-level scaling optimizations for Transformer execution on CPUs without degrading model accuracy [20]. Furthermore, recent innovations such as NoMAD-Attention replace traditional multiply-add (MAD) computations with ultra-low-latency in-register lookups utilizing CPU Single-Instruction-Multiple-Data (SIMD) capabilities [21].
B. Efficient Attention Mechanisms
Several of the CPU strategies above target memory directly. Weight-only quantization [18] and KV-cache compression [19] shrink the memory footprint and reduce bandwidth use. These approaches reflect that memory bandwidth, rather than raw compute, is the dominant constraint for LLM inference. IO-aware attention restructures computation around the memory hierarchy. On GPUs, FlashAttention uses aggressive tiling to minimize intermediate transfers between HBM and on-chip SRAM [22]. FlashAttention-2 further optimizes thread-block parallelism and work partitioning [23]. Although these algorithms are tailored to the GPU memory hierarchy, they underscore the importance of strict data locality. Our compiler-based methodology applies this principle to multi-socket CPU topologies by minimizing cross-socket interconnect traffic.
C. Distributed Execution and Tensor Parallelism
To mitigate synchronization overhead and manage massive parameter scales, distributed paradigms like Megatron-LM introduced tensor parallelism to minimize synchronization points within both the Multi-Layer Perceptron (MLP) and attention blocks [13]. Generalizing distributed tensor computations, Mesh-TensorFlow established a flexible language for compiling Single-Program-Multiple-Data (SPMD) graphs across high-performance supercomputing clusters [24]. Extending these compiler abstractions to modern primitives, Triton-distributed augmented the Triton compiler with OpenSHMEM. This enables native overlapping of computation and communication for distributed AI workloads [25]. Our methodology adapts large-scale tensor parallelism principles to the PyTorch FX graph. Specifically, it uses column- and row-parallel decompositions within a single multi-socket CPU to localize DRAM access and avoid inter-socket bottlenecks.
Beyond these foundational techniques, production distributed frameworks expose tensor and data parallelism as first-class runtime services. PyTorch's native torch.distributed stack organizes execution as per-device processes that exchange shards through collective primitives. Its APIs include DistributedDataParallel [26], Fully Sharded Data Parallel (FSDP) [27], and a DTensor-based tensor-parallel interface. DeepSpeed combines ZeRO-style state partitioning across ranks [28], [29] with tensor-parallel inference kernels. These systems delegate data movement to collective communication libraries such as NCCL [30], oneCCL [31], Gloo [32], or MPI. Their all-reduce and all-gather routines are tuned for NVLink, PCIe, or InfiniBand and scheduled to overlap with computation.
Our setting differs along three axes that make these frameworks a poor direct fit for intra-node CPU inference. Process model: these frameworks launch one OS process per device. NUMA-TP instead runs in a single process and treats each socket as a rank executed by an affinity-pinned thread group. Communication: these frameworks invoke a collective library over a network or device interconnect. By contrast, our cross-socket reduction directly sums socket-local buffers across the QPI/UPI link. Partitioning interface: these frameworks expose partitioning through user-facing APIs or model wrapping, often with architecture-specific configuration. NUMA-TP instead uses a compiler FX pass and requires no model-code changes. It recasts distributed tensor parallelism as an intra-node, compiler-level transformation tailored to the low-latency, high-bandwidth cross-socket interconnect.
D. NUMA-Aware Execution Strategies
Several NUMA-aware deep learning optimizations are close in spirit to our work. We describe their similarities and differences below.
NUMA-Caffe restructures layer-level parallelism into a multi-solver design to improve CNN training throughput on NUMA hardware [33]. Like our work, it treats NUMA locality as important on multi-socket machines. However, its workload and mechanism differ from ours. NUMA-Caffe targets CNN training with data parallelism, using per-node model replicas over a partitioned batch. It implements this approach as a framework-level Caffe modification. In contrast, we target Transformer inference with tensor parallelism applied as a compiler transformation. A second line of work characterizes the bottleneck rather than removing it. Studies of cache contention and NUMA remote accesses for Transformer inference on many-core processors [34] confirm that remote-DRAM traffic dominates. However, they stop at analysis and do not provide a transparent mechanism to eliminate it.
Closest to our setting is Sandwich [35], a hardware-centric LLM serving engine. Like NUMA-TP, Sandwich partitions models across NUMA nodes to reduce cross-socket traffic and tailors execution to the prefill and decode phases. The key differences are integration and binding time. Sandwich is a standalone engine that partitions models statically using ahead-of-time, per-phase execution plans. NUMA-TP instead runs inside the standard TorchInductor pipeline as a post-grad FX pass that reuses the Triton-CPU backend. Sandwich, like the C++ engine ArcLight [7], requires adopting a separate runtime and porting models to it. NUMA-TP instead dispatches kernels dynamically through a NUMA-aware thread pool and works with unmodified PyTorch model code.
V. CONCLUSION
This paper introduces a compiler-driven, PyTorch-native solution to the DRAM bandwidth bottleneck of the Large Language Model (LLM) prefill phase on multi-socket CPUs. Extending the TorchInductor compilation path, it implements NUMA-aware Tensor Parallelism (NUMA-TP) via post-grad
FX graph transformations, coupled with an extended Triton-CPU backend for per-socket buffer allocation and NUMA-aware kernel dispatch. The transformation strictly enforces data locality, remains entirely transparent to the user, and yields prefill speedups of up to 2.63× on dual-socket Haswell and 1.87× on Cascade Lake platforms, exceeding what process-level numactl policies achieve on the same sweep.
Three directions follow from this work. First, NUMA-Torch should extend beyond the transformer sub-layers treated here to other locality-critical compute blocks, so that any block whose cost is dominated by remote memory traffic can be partitioned by the same passes. Second, the transformation should be chosen rather than applied unconditionally, with the compiler determining the communication-computation tradeoff for each block from dataflow analysis and the characteristics of the target platform, such as its socket count and interconnect bandwidth. The four-socket result makes the case for the second directly, since the same transformation that pays at high arithmetic intensity does not pay at low. The third sits on a separate track within LLM inference optimization. This work targets prefill, and carrying NUMA-aware partitioning into decode needs its own treatment of KV-cache placement and reduction scheduling rather than a direct reuse of these passes.
The TorchInductor NUMA-TP FX passes and the extended Triton-CPU backend are publicly available at https://github.com/LLM-Compiler/numa-torch.
ACKNOWLEDGMENT
The authors sincerely acknowledge the financial assistance provided by the University of Moratowa to cover the publication fees. Furthermore, the authors extend their gratitude to the anonymous reviewers for their thorough and insightful feedback.
REFERENCES
[1] A. Radford et al., “Language models are unsupervised multitask learners,” OpenAI, Tech. Rep., 2019.
[2] J. Devlin et al., “BERT: Pre-training of deep bidirectional transformers for language understanding,” in Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, 2019, pp. 4171–4186.
[3] Gemma Team, “Gemma: Open models based on gemini research and technology,” Google DeepMind, Tech. Rep., 2024.
[4] I. Calciu et al., “Black-box concurrent data structures for NUMA architectures,” in Proceedings of the Twenty-Second International Conference on Architectural Support for Programming Languages and Operating Systems, 2017, pp. 207–221.
[5] Intel Corporation, Intel Advisor, Intel Corporation, Santa Clara, CA, USA, 2024, available at: https://www.intel.com/content/www/us/en/developer/tools/oneapi/advisor.html.
[6] G. Gerganov, “llama.cpp: Port of Facebook’s LLaMA model in C/C++,” https://github.com/ggml-org/llama.cpp, 2023.
[7] Y. Xu et al., “ArcLight: A Lightweight LLM Inference Architecture for Many-Core CPUs,” in Proceedings of the Annual Meeting of the Association for Computational Linguistics: System Demonstration, 2026.
[8] J. Ansel et al., “PyTorch 2: Faster machine learning through dynamic python bytecode transformation and graph compilation,” in Proceedings of the 29th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, 2024, pp. 929–947.
[9] P. Tillet, H. T. Kung, and D. Cox, “Triton: An intermediate language and compiler for tiled neural network computations,” in Proceedings of the 3rd ACM SIGPLAN International Workshop on Machine Learning and Programming Languages, 2019, pp. 10–19.
[10] Triton Contributors, “Triton CPU: Experimental CPU backend for the triton compiler,” GitHub repository, 2024, experimental compiler backend. [Online]. Available: https://github.com/triton-lang/triton-cpu
[11] Linux Kernel Developers, “Numa memory policy,” The Linux Kernel Documentation, 2026. [Online]. Available: https://www.kernel.org/doc/html/latest/admin-guide/mm/numa_memory_policy.html
[12] Linux Programmer's Manual, "mbind(2)," kernel.org, 2026. [Online]. Available: https://man7.org/linux/man-pages/man2/mbind.2.html
[13] M. Shoeybi et al., “Megatron-LM: Training multi-billion parameter language models using model parallelism,” in arXiv preprint arXiv:1909.08053, 2019.
[14] A. Vaswani et al., “Attention is all you need,” in Advances in Neural Information Processing Systems, vol. 30, 2017.
[15] A. Paszke et al., “PyTorch: An imperative style, high-performance deep learning library,” in Advances in Neural Information Processing Systems, vol. 32, 2019.
[16] N. Shazeer, “Fast transformer decoding: One write-head is all you need,” arXiv preprint arXiv:1911.02150, 2019.
[17] Linux Programmer's Manual, "numactl(8)," man7.org, 2026. [Online]. Available: https://man7.org/linux/man-pages/man8/numactl.8.html
[18] H. Shen et al., “Efficient llm inference on cpus,” arXiv preprint arXiv:2311.00502, 2023.
[19] P. He et al., “Inference performance optimization for large language models on cpus,” arXiv preprint arXiv:2407.07304, 2024.
[20] D. Dice and A. Kogan, “Optimizing inference performance of transformers on cpus,” arXiv preprint arXiv:2102.06621, 2021.
[21] T. Zhang et al., “Nomad-attention: Efficient llm inference on cpus through multiply-add-free attention,” 2024.
[22] T. Dao, D. Simpson, and C. Ré, “Flashattention: Fast and memory-efficient exact attention with io-awareness,” arXiv preprint arXiv:2205.14135, 2022.
[23] T. Dao, “Flashattention-2: Faster attention with better parallelism and work partitioning,” arXiv preprint arXiv:2307.08691, 2023.
[24] N. Shazeer et al., “Mesh-tensorflow: Deep learning for supercomputers,” arXiv preprint arXiv:1811.02084, 2018.
[25] S. Zheng et al., “Triton-distributed: Programming overlapping kernels on distributed ai systems with the triton compiler,” arXiv preprint arXiv:2504.19442, 2025.
[26] S. Li et al., “PyTorch distributed: Experiences on accelerating data parallel training,” Proceedings of the VLDB Endowment, vol. 13, no. 12, 2020.
[27] Y. Zhao et al., “PyTorch FSDP: Experiences on scaling fully sharded data parallel,” Proceedings of the VLDB Endowment, vol. 16, no. 12, 2023.
[28] J. Rasley et al., “DeepSpeed: System optimizations enable training deep learning models with over 100 billion parameters,” in Proceedings of the 26th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining, 2020.
[29] S. Rajbhandari et al., “ZeRO: Memory optimizations toward training trillion parameter models,” in Proceedings of the International Conference for High Performance Computing, Networking, Storage and Analysis (SC), 2020.
[30] NVIDIA, “NVIDIA collective communications library (NCCL),” https://developer.nvidia.com/nccl, 2024.
[31] UXL Foundation, “oneAPI Collective Communications Library (oneCCL),” https://github.com/uxlfoundation/oneCCL, accessed: Oct. 31, 2026.
[32] Meta Platforms, Inc., “Gloo: Collective Communications Library,” https://github.com/pytorch/gloo, accessed: Oct. 31, 2026.
[33] P. Roy et al., “Numa-caffe: Numa-aware deep learning neural networks,” ACM Transactions on Architecture and Code Optimization, vol. 15, no. 2, pp. 1–26, 2018.
[34] J. Jiang et al., “Characterizing and optimizing transformer inference on arm many-core processor,” in Proceedings of the 51st International Conference on Parallel Processing, 2023.
[35] J. Zhao et al., “Sandwich: Separating prefill-decode compilation for efficient cpu llm serving,” arXiv preprint arXiv:2507.18454, 2025.