Repository navigation
v18.4 — QRFFT1D, a real-input FFT at about twice the speed, and LSTM import from PyTorch
v18.4 — QRFFT1D, a real-input FFT at about twice the speed, and LSTM import from PyTorch
Real-input FFT: QRFFT1D (#281, #282)
QRFFT1D<N>takes N real int16 samples and returns the N/2 + 1 distinct bins, scaled by 1/N likeQFFT1D<N>::forward, from the samebuildQFFTTwiddles(N)table. Audio, vibration and IMU front ends no longer pay for a zeroed imaginary buffer and a mirrored half spectrum.- Measured on the boards (cycles per forward transform,
-O3, median of 33 runs, output bit-exact with the host): 2.25 to 2.32 times faster thanQFFT1Don a Cortex-M4F (NUCLEO-F411RE, N = 64 to 1,024) and 1.99 to 2.47 times on a Cortex-M0+ (NUCLEO-L031K6, N = 64 to 512). At N = 256 it takes 0.47 ms instead of 1.07 ms on the 100 MHz M4F, and 2.4 ms instead of 5.2 ms on the 32 MHz M0+. - No int16 input can saturate it. Packing two real samples into one complex value lets an inner component reach √2 times full scale;
QRFFT1Dtakes that headroom in the first inner stage, whose twiddle is exactly 1. The cost is a largest bin error about 1.3 to 1.7 timesQFFT1D's, a few LSB of the 16-bit spectrum. - Tests check every bin against an exact DFT and against
QFFT1Dfor N = 4 to 256; eight planted defects each fail them. The FFT fuzz harness checks it on every input, with six new corpus inputs that trap a layout that saturates. - New
benchmarks/fft_onboardreproduces the timings on both boards at-O2and-O3, with the twiddle tables in flash or RAM, and refuses to record a run whose output differs from the host's.
PyTorch importer: models that start with one nn.LSTM (#279)
LSTM.from_state_dictturns annn.LSTMstate dict into a descriptor that maps ontoQLSTMCell, with int16 (default) or int8 cell state, per-gate symmetric int8 weights in PyTorch's gate order, and biases quantized the wayquantizeQLSTMBiasesdoes. Stacked, bidirectional and projected LSTMs are refused, as is an LSTM anywhere but first.- New
examples/import_lstm_demoimports a 3-input, 8-unit LSTM with a linear head and compares 16 held-out 24-step sequences against a float reference written apart from the importer: max output error 0.063 with the int16 cell and 0.074 with the int8 cell.
Smaller fixes (#280)
- The FFT bit-reversal tables use the narrowest index type that fits: at N = 256 each table drops from 1,024 to 256 bytes of memory. The permutation is unchanged.
q15Mul's comment wrongly said its -32768 × -32768 corner overflows and never occurs; both claims are corrected and the corner is now tested.examples/air_qualitystops at the first epoch in which no sample trains (epoch 28 instead of 15,000). Its forecast is byte-identical and the run drops from 18.4 s to 0.04 s.
Docs
docs/architectures/fft.mddocumentsQRFFT1Dwith the on-board timing table; README lists the LSTM descriptor in the importer entry (#283).
Documentation, architecture guides, and example gallery: https://danmcleran.github.io/tinymind/
Full changelog: v18.3...v18.4