ELLMEngineering Large
Language Models
Download PDF

OPTIONAL COMPANION

All supplements

Accelerator platform notes

Source baseline: September 13, 2026. These are dated implementation entry points; validate exact compiler, runtime, and model support for a deployment.

Google TPU: compile the graph and design the tile schedule

A TPU is not a GPU with different branding. Its TensorCores combine matrix-multiply, vector, and scalar resources; the precise organization varies by generation. The matrix units favor well-filled matrix work, but attention also needs reductions, masking, and memory movement. Those operations remain part of the latency budget. Google's TPU architecture guide describes the hardware model.

XLA compiles framework computations for the target, handling transformations such as fusion and buffer planning. Pallas provides explicit custom-kernel control within JAX when automatic compilation does not produce the desired schedule. Pallas supports TPU and GPU work but exposes hardware-specific APIs; common notation does not mean an optimized GPU kernel can be carried over unchanged. See XLA architecture and the Pallas guide.

TPUs can serve autoregressive models as well as train them. Google's current inference documentation uses the tpu-inference plugin for vLLM, with JAX and PyTorch model paths. Start from that integration's supported model and feature set, not an assumption that every CUDA engine flag is meaningful on TPU. See Run inference on Cloud TPU.

For this workload, prefill presents many query rows and opportunities for matrix reuse. Decode exposes weight and KV reads, small operations, scheduling, and collective latency. The accelerator's matrix peak alone cannot predict either request-level TTFT or token cadence. Ragged lengths, paged KV, and dynamic arrivals require a serving implementation that manages those states efficiently; they do not make TPU serving impossible. Compilation buckets, attention layouts, and host/device boundaries become concrete review items.

Choose a Pallas window and count its live values

Begin with a dtype-matched JAX RMSNorm reference, then choose a window for the custom kernel. Suppose the input is (128, 4096), weights are presented as (1, 4096), and each program handles eight complete rows. The input and output windows advance along rows; every program sees the same weight window.

Example status: Source-only Pallas window specification; kernel body and launch omitted.

from jax.experimental import pallas as pl

rows, width, rows_per_program = 128, 4096, 8
grid = (rows // rows_per_program,)
x_window = pl.BlockSpec((8, width), lambda p: (p, 0))
w_window = pl.BlockSpec((1, width), lambda p: (0, 0))
y_window = pl.BlockSpec((8, width), lambda p: (p, 0))

Under blocked indexing, program p=3 selects input rows 24 through 31: the index map returns block coordinates, which are multiplied by the block shape. The 16 programs cover all 128 rows. These windows satisfy the documented two-dimensional TPU block-size rules; that is only one part of a valid kernel. The Grids and BlockSpecs guide also describes full-dimension exceptions and out-of-bounds padding. Such padding has unspecified values; explicitly mask it when a reduction could read it.

The FP32 input window alone contains 8 * 4096 * 4 = 128 KiB. An equally sized output adds 128 KiB of logical values, and a single FP32 weight row adds 16 KiB. Temporaries, layout padding, and extra pipeline buffers are additional costs; live ranges determine how much must coexist. This byte ledger narrows the design, but the target compiler and memory report decide whether the schedule fits VMEM.

For a custom TPU kernel, the next question is how HBM rows and weights become on-chip working tiles. TPU Pallas exposes vector memory (VMEM), scalar memory (SMEM), and synchronization mechanisms for staged work. A Ref is a mutable memory view; its name alone does not identify its memory space. The TPU pipelining guide shows how block windows and pipelines arrange transfers. The matrix-multiplication guide is a concrete example of a grid, an accumulating dimension, and reuse.

Eight complete rows keep each normalization local to a program. Splitting one row across two programs changes the dependency: their partial squared sums must be combined before either fragment can normalize. The implementation must then retain or reload the row values and use a supported multi-stage schedule. The global denominator alone cannot repair a fragment-local numerator.

Fragmenting a row creates a full-row reduction dependency. The arrows describe required information, not a universally available cross-program barrier.
Open full diagram ↗

Fragmenting a row creates a full-row reduction dependency. The arrows describe required information, not a universally available cross-program barrier.

Pallas offers pallas_call(..., interpret=True) for CPU-accessible semantic debugging. It lowers the grid/body into JAX execution; it does not run TPU instructions or establish VMEM fit, legal TPU layouts, DMA overlap, or speed. A separate TPU-specific interpreter models more of those mechanisms, but remains a simulator. Read the Pallas call contract before interpreting a passing test as hardware support. Pallas is experimental; pin JAX and jaxlib together and consult its changelog when adapting older examples.

AWS accelerators: Neuron is the stack, not the chip

Trainium and Inferentia are AWS accelerator families. Inferentia targets inference; Trainium supports training and inference. Neuron is their software stack, including compiler, runtime, framework integrations, libraries, and profiling tools. Native PyTorch through TorchNeuron is a closed-beta path in the checked SDK 2.32 documentation; PyTorch NeuronX and JAX are distinct integrations. Confirm access as well as feature support. See the Neuron SDK overview and native PyTorch access note.

For a new serving evaluation, begin with the vLLM Neuron plugin's supported models and targets. The checked announcement describes a beta path for Trn2 and Trn3 that no longer depends on NxD Inference; NxD entered maintenance mode with SDK 2.32. The migration guide separates a supported model move from custom-modeling work. Check the service's attention, quantization, sampling, and cache features against that path, including target generation: support in the umbrella SDK does not establish plugin support for older Inferentia hardware.

NKI: follow the tile between memory spaces

NKI, the Neuron Kernel Interface, exposes tiled custom computation and explicit data movement. HBM holds large tensors, SBUF holds on-chip working tiles, and PSUM provides distinct accumulation storage for applicable matrix results. Partition dimensions, tile constraints, and lifetimes determine the schedule. The memory hierarchy guide is the conceptual starting point.

The checked SDK 2.32 pairs with NKI 0.6 and uses the nki, nki.language, and nki.isa namespaces. Use the migration guide when adapting older examples, especially for returned-buffer and runtime-loop rules.

Use this schedule to read the maintained RMSNorm implementation. It is intentionally pseudocode: supported tile shapes, reduction operations, and dtype conversions must come from the selected SDK and target.

Example status: Explanatory pseudocode; NKI tile schedule.

For a bounded tile containing complete rows:
    load input and weight tiles from HBM into SBUF
    reduce squared values across each actual row width
    compute the inverse RMS and scale the working tile
    store the output into shared HBM
If a row spans tiles, combine its partial sums before normalizing it.

SBUF is software-managed working storage, not merely a hardware cache. PSUM is distinct accumulation storage used for matrix results; it should not be drawn as an obligatory stop for every scalar reduction. Returning an output tensor also has a buffer contract: modern NKI uses shared HBM for returned tensors. Read the memory hierarchy guide with the SDK 2.32 nki.language.rms_norm reference. That API's documented targets and input contract are narrower than a universal framework operator; an old tutorial with a similar name may use a different namespace or SDK.

Make the operator arguments concrete. For an FP32 (128, 512) input tile already in SBUF, dimension zero identifies the 128 partitions and dimension one contains each row's 512 values. Present the learned scale as a same-shaped FP32 weight tile repeating the row weights. This explicit layout is easy to read; reusing or broadcasting a smaller weight tile is a separate implementation choice.

Example status: Source-only NKI 0.6 API fragment; no simulator or device run recorded.

import nki.language as nl

y_sbuf = nl.rms_norm(x_sbuf, w_sbuf, axis=1, n=512,
                    epsilon=1e-6, compute_dtype=nl.float32,
                    dtype=nl.float32)

Here axis=1 selects the reduction dimension and n=512 specifies its actual width. Passing n=4096 for one 512-element fragment of a wider row would still omit the other fragments' squared values. The experimental API's official source reference documents the tile operation; the surrounding implementation must supply loads, a legal target schedule, and the shared-HBM output store.

The NKI CPU simulator, invoked through nki.simulate(kernel), is a functional/debug aid. Sequential host simulation cannot establish instruction scheduling, engine overlap, latency, or bandwidth. After it passes, compile for the named accelerator generation, compare device outputs, and inspect a device trace with Neuron Explorer. These are separate gates. A simulator result should never appear in a chart labeled Trainium performance.

Porting question Triton / HIP on GPU Pallas on TPU NKI on Neuron
Who owns a row? Program tile or block Grid program and block window Program/tile schedule
Where does working state live? Compiler-managed registers; explicit shared storage in HIP VMEM/SMEM selected by the TPU schedule SBUF; PSUM for applicable accumulation
What must a tail preserve? Masked loads, actual divisor, valid stores Legal bounded windows and full reduction semantics Legal tile/partition shapes and full reduction semantics
What establishes speed? Warm device execution and engine replay TPU execution/profile and engine replay Neuron execution/profile and engine replay

This is a comparison of questions to answer, not equivalence between memory spaces or a hardware support matrix. The common mathematical reference stays above the implementation boundary.