Skip to content

trnsci blog

trnsci: compile on a CPU host, run on Trainium. Neuron compile caches carry over

A feasibility test in trnsci#118 found that NEFFs compiled on a machine with no Neuron device are reused by a Trn2 box's persistent compile cache, with no neuronx-cc run, a fast first call and the same results. That works because the cache key is a pure function of the program and the compiler configuration, so compiling can move to cheaper CPUs ahead of a hardware window. The window that proved it also failed to keep most of its own cache, which is the practical half of this post. It is for anyone who pays for Trainium time and watches the first call compile.

trnsparse and trnsolver: a million-point Gaussian process on one Trn2 chip, and what the hardware actually limits

An exact Gaussian-process posterior mean at n = 10⁶ now converges on one trn2.3xlarge chip in 813 s. It rests on trnsparse's fused K(X, Y) @ V kernel, which never writes the kernel matrix anywhere: squared distances as one Tensor Engine matmul into PSUM, the exponential on the Scalar Engine reading PSUM directly, then the product with V. The profile then showed that the planning number, 10¹² kernel entries per second per chip, was about 4× too optimistic for fp32 even with perfect engine overlap. This post is for anyone running kernel methods or attention-shaped workloads who wants to know which Trainium engine is the real limit.

trnsci: the suite's silent wrong answers, and the float64 rule that came out of them

Across three Trn2 hardware windows, correctness audits found about 60 silent wrong-result bugs in released versions of all six trnsci libraries. Most were wrong on every backend, so the suite's own pytorch-vs-NKI tests had passed them for months. The fixes taught the suite two things about Trainium: what float64 actually means on a device whose arithmetic is fp32, and that a test is only as independent as its reference. This post is for anyone who has shipped numerical code on Trainium, and for anyone deciding whether to trust ours.

trnfft: spherical harmonic transforms, and how close plain PyTorch gets on Trainium

trnfft's new spherical harmonic transform, trnfft.sht, runs its forward 8.5–28× faster than fp64 ducc0 on the same Trn2 box, while its inverse is 26× slower than its own forward at L = 511, F = 1024, nearly all of the gap spent in two torch.flip calls. The Legendre stage is a ragged batch of matmuls against fixed tables, and the hand-written NKI kernel that holds those tables stationary in SBUF beats a carefully padded plain-PyTorch version by only 1.2–2.2× at large batch, and loses to it by 1.5–1.6× at one field: what plain PyTorch can't do on the device is the FFT, and the naive per-m loop never gets past compile. This is for anyone weighing Trainium for spectral-transform models in weather and climate, and for anyone deciding how much of that work needs a library at all.

trnblas: the 92× that was 1.8×, and the DF-MP2 win that holds up

trnblas published a 92× speedup for its fused pair-energy kernel on Trn2, and it was wrong: the aten baseline had slowed because device memory was filling up, and against a fair baseline the kernel is 1.8× faster. What survives is narrower and more useful. GEMM routes to aten, a fused kernel keeps the energy step where it avoids work aten can't, and the metric Cholesky moves to the host, which makes density-fitted MP2 1.1–1.8× faster than aten on the molecules where the device beats the CPU at all. The post is for anyone benchmarking TorchNeuron eager code, and for chemists deciding which DF-MP2 stages belong on Trainium.

trnfft: batch fusion, and the first FFT result that beats the CPU

trnfft's four-step FFT now runs a whole batch in one NKI launch. At N=4096 with 1,024 rows, the device goes from 10.1 ms to 0.93 ms, against 11.0 ms for a 2-thread host CPU. The previous post found the CPU winning every cell and called batch fusion "the next lever". It was, though the time it recovered wasn't launches: it was a DMA transpose repeated on every tile of every GEMM. The CPU still wins at B ≤ 128 and at N=256, so this matters for batched transforms on device-resident data, not for single calls.

trnrand: the 2× floor of bit-identical Threefry

trnrand v0.9.0 takes the full-word Threefry kernel from 5.0 to 2.5 ms at 4M normals on Trn2. It also brings trnrand.normal(4M), measured end to end to a host tensor, to 5.5–8.1 ms, below CPU randn at 11.5–15.6 ms. Most of that gain came from moving host work off the critical path and from noticing the kernel had been running twice. The part worth writing about is the kernel's floor, which sits at about 2× aten randn for a reason the four-engine post did not anticipate: on this silicon, GpSimd and the Vector Engine cannot overlap. Anyone planning to spread an integer workload across Trainium's engines and expecting the engine times to overlap should read the profile below first.

trnsolver: Jacobi on hardware, six months after the argument

trnsolver's batched block-Jacobi eigh on one Trn2 core runs 1.5–2.2× faster than batched 2-thread CPU LAPACK for FP32 batches at n = 64 and 128 with B ≥ 64–256, and at n = 32 with B = 1024. Against a fairer CPU baseline, the batch split across the same threads, the margin shrinks to about 1.13× (see the correction below). Getting there meant first measuring the design the library had picked over Jacobi in April, batched Householder tridiagonalization, losing to the CPU by 6–17×. The April post argued that Trainium wants Jacobi, then the library deleted its Jacobi kernels two days later; this post is the hardware verdict on both decisions, for anyone with thousands of small symmetric eigenproblems, such as SCF inner loops.

trnsparse: the crossover density, with the sparsity pattern compiled in

Before trnsparse#34, no sparse path in trnsparse beat plain dense aten on Trn2 (matmul, or unmasked SDPA), and about 60% of each BSR SpMM call went to padding and gathering on the device. The fix is to treat the block structure, which TorchNeuron already forces onto the host, as compile-time constants: the kernel unrolls exactly the stored 128×128 blocks with fixed DMA addresses and no gather, at the cost of one compile per distinct structure. The result is a measured crossover density by matrix size, which anyone choosing between BSR and dense on Trainium can read off a table.

trntensor: on Trn2 the planner earns its keep, the kernels don't

On the native TorchNeuron path, trntensor's hand-written NKI kernels did not beat aten on the device at any size measured, so trntensor v0.18.0 now routes plain and fused contractions to aten by default. What the library does add on Trn2 sits one level up, in the host-side planner: contraction order, batching and precision modes. That planner had a bug that built a 4-index outer product, which cost 70 ms on a contraction that should take about 1 ms. Anyone writing contraction code for Trainium, or deciding whether a hand-written kernel is worth it, may find the measured split between "plan" and "kernel" more useful than any single speedup.