Skip to content

trnsci blog

trnblas: the odd-shape cliff that wasn't

An 8191³ GEMM took 1605 s on its first call on Trn2 while 8192³ took 4.4 s, and trnblas blamed three things in turn before finding the cliff in its own benchmark: a lazy torch.randn(device="neuron") inside the timed call. Two fixes from the wrong turns are real and shipped in trnblas v0.6.0 via trnblas#51 — the autotune sweep is opt-in, and unaligned shapes now take their ragged edges inside the kernel, which PSUM accumulation and partition-0 tiles make nearly free. The post is for anyone timing first calls on the native TorchNeuron device, and for CUDA programmers who expect "pad to the tile" to cost nothing.

trnfft: on native PyTorch, the launch is the unit of cost

On the native TorchNeuron device in Neuron SDK 2.33.0, trnfft's N=1024 FFT dropped from 7.56 ms to 0.33 ms. No kernel got faster; there were just fewer launches. When every launch costs a fixed ~0.25 ms, arithmetic barely registers, and the best-fitting shape is one Tensor Engine GEMM accumulating in PSUM, not a sequence of radix stages. The concession comes first: a multithreaded host CPU still beats trnfft at every size and batch measured. For anyone deciding whether a standalone FFT belongs on Trainium: mostly it doesn't, for specific reasons.

trnrand: from byte tiles to full words on Trn2

The byte-tile post argued that storing each Threefry word as four (128, 1) byte tiles was the representation the architecture preferred. On Trn2 with NKI 0.7 that design was correct and slow: the kernel was bound by instruction issue, because every instruction did 128 elements of work. Widening the tiles to (128, F ≤ 512) and moving the 32-bit adds onto GpSimd's native integer path takes trnrand.normal() at 4M elements from 934 ms to 15.9 ms with bit-identical output. That result shipped in trnrand v0.8.0 via PR trnsci/trnrand#62. Aten randn is still about 11× faster, and the host CPU still wins at every size measured.

trnsolver: what torch.compile can't lower, and a 20-second eigh

trnsolver's Cholesky, LU solve and QR now compile under torch.compile(backend="neuron", fullgraph=True) on Trn2, and eigh at n=128 dropped from 20.8 s to 1.17 ms. Neither is the triumph it sounds like: first calls of the compiled factorizations take 13–259 s because their loops unroll, and the 1.17 ms eigh runs on the host CPU, which is where aten's linalg_eigh executes for a neuron tensor. The lesson for anyone putting dense linear algebra inside a compiled Trainium graph: a whole-graph, static-shape compile model turns pivoting into cheap data movement, but has no answer yet for convergence loops.

trnsparse: from 14/30 to 30/30 on NKI 0.7

trnsparse's block-sparse attention and screened-SpMM kernels had run under nki.simulate for six months, then failed 16 of 30 hardware tests the first time they ran on the native neuron device under NKI 0.7.0. The fixes are small: a reciprocal-multiply where a divide used to be, an explicit partition broadcast, and two host-side gather bugs, one of which had been blamed on the simulator since April. The compile fixes say a lot about how the engines want per-row scalars and partition counts expressed. The branch passes 30/30 on Trn2. It shipped in trnsparse v0.7.0 via PR trnsci/trnsparse#31, and anyone moving NKI 0.3-era kernels to the native PyTorch path should read it before starting.

trntensor: the mock all-reduce meets four real ranks

trntensor's reduce-parallel einsum now sums its partials with a real multi-rank all-reduce, either torch.distributed or an NKI nki.collectives.all_reduce kernel, across all four logical NeuronCores of one trn2.3xlarge, shipped in trntensor v0.17.0 from three stacked PRs, and the first write-up of the four-rank result claimed a bit-exactness it didn't have. Architecturally, the collective is an instruction inside an NKI kernel operating on HBM rather than a library beside the compute, and the rules it enforces (which cores may form a group, which HBM buffer type returns correct values) expose the chip's topology. Anyone planning multi-core contractions on Trainium, or arriving from NCCL, will want those rules before writing a launcher.

trnfft: what trn1 and trn2 tell us about the Ozaki frontier

The v0.18 and v0.19 posts claimed hardware precision of O(sqrt(N)·u_bf16²) ≈ 1.6e-5 and O(sqrt(N)·u_bf16⁴) ≈ 2e-9 for the Ozaki modes. The trn1 hardware measurement says those numbers are wrong — both modes deliver ~1.7e-3, equivalent to single-pass BF16. trn2 was then tested with the same characterization. The result is identical. Both generations. The conclusion is still not "Ozaki is a dead end" — but the generational gap theory needs revision.

trntensor v0.16.0: extending the precision contract to multi_einsum

v0.15.0 gave einsum() a target_forward_error= argument — the caller specifies a relative error bound, the library picks the cheapest mode that satisfies it. v0.16.0 extends the same contract to multi_einsum(). A precision API that works for single contractions but silently doesn't apply to batched calls is a leaky abstraction, and this is the patch that closes it.

trnfft: the residual must stay FP32

v0.19 ships precision="ozaki_hq" — six BF16 matmuls that together reach O(sqrt(N)·u_bf16⁴) ≈ 2e-9 relative error, near-FP64 accuracy on the Tensor Engine. The implementation is a 40-line extension of the v0.18 Ozaki scheme. There is one non-obvious constraint that the algorithm turns entirely on. Getting it wrong gives you 1-level accuracy out of a 2-level design, silently, with no error.