Skip to content

trnfft

FFT and complex-valued tensor operations for AWS Trainium via NKI.

Trainium has no native complex number support and ships no FFT library. trnfft fills that gap with split real/imaginary representation, complex neural network layers, and NKI kernels optimized for the NeuronCore architecture.

Part of the trnsci scientific computing suite (github.com/trnsci).

Features

  • torch.fft-compatible API — fft, ifft, rfft, irfft, hfft, ihfft, the 2 / n variants of each (fft2, ifftn, hfftn, ...), fftshift, ifftshift, fftfreq, rfftfreq, stft, istft. The transforms take torch.fft's n / s, dim and norm arguments with the same meaning. stft(window=None) uses a Hann window, where torch.stft uses ones; pass window to match it.
  • ComplexTensor — split real/imaginary representation with full arithmetic
  • Complex NN layers — ComplexLinear, ComplexConv1d, ComplexBatchNorm1d, ComplexModReLU
  • NKI acceleration — DFT-GEMM, four-step and six-step FFTs, Stockham and butterfly stages, complex GEMM, ComplexLinear, and fused multiply kernels for Trainium. Validated on Trn2 (Neuron SDK 2.33, native TorchNeuron) and on trn1.2xlarge (XLA). See Benchmarks and the CHANGELOG.
  • Plan-based caching — FFTW-style plan creation and reuse

trn-* suite

trnfft is one of six packages (plus an umbrella meta-package) in the trnsci scientific computing suite for AWS Trainium:

Quick example

import torch
import trnfft

signal = torch.randn(1024)
X = trnfft.fft(signal)
recovered = trnfft.ifft(X)

License

Apache 2.0 — Copyright 2026 Scott Friedman