Fourier Optics for Training — Presentation 01

Transforms in Training Workloads

What the backward pass and the optimizer step do to a Fourier-domain layer: the gradient of a convolution is a correlation, the weight gradient multiplies two data-dependent spectra, and the masks change every step. A training-step Amdahl analysis for transformer, Hyena-2, hybrid and block-circulant models, with a live explorer.

Backward pass Correlation Weight gradient Amdahl Block-circulant Mask rewrites
Forward → Backward: dX, dW → Optimizer step → Static share → Mask budget
00

Topics We'll Cover

Concepts used here, and where they are explained. Each links to a glossary entry: this series glossary, or the Fourier Optics for Inference glossary and the Simulation Engineering Toolkit's for concepts those series already explain.

01

What a Training Step Adds to Inference

The inference series asked what share of a forward pass a Fourier-optical transform engine could take (FOptInf 02). Training runs the same forward pass and then two more kinds of work:

PhaseFor a layer y = W xFLOPs, matmul layerCounted?
Forwardy = W x, keeping x for later2 per weight per tokenyes
Backward, dXthe activation gradient WT G, passed to the layer below2 per weight per tokenyes
Backward, dWthe weight gradient G XT, summed over every token of the step2 per weight per tokenyes
OptimizerAdamW: a few element-wise operations per parameter, once per stepper parameter, not per tokenno (as norms are not)
02

The 6N Rule, Reproduced

Before trusting the ledger on new layers, check it on the old one. Training a dense model costs about 6N FLOPs per token (2 forward, 2 for dX, 2 for dW), plus an attention term that grows with the sequence (Kaplan et al., arXiv:2001.08361; the same accounting appears in the Chinchilla paper's appendix, Hoffmann et al., arXiv:2203.15556). Here N counts the parameters that multiply activations: the 8,029,995,008 of the untied model less the 128,256 × 4,096 input embedding, which is a lookup.

SequenceThis script (GFLOP/token)6N + attention (GFLOP/token)Ratio
2,04846.6446.641.0000
4,09648.2548.251.0000
8,19251.4751.471.0000
32,76870.8070.801.0000

Source: results.md, section “1. Cross-check: the 6N rule”; the pytest suite checks the ratio to 1e-12.

03

What the Inference Series Found

FOptInf 02 counted the forward pass. The short version:

A standard decoder has no FFT

A Llama-style transformer is matmuls, attention, norms and activations. A Fourier transform engine (as against an optical MAC, which would speed every matmul) has nothing to do; its share is zero, forward or backward.

Where FFTs appear, they are small

Long-convolution models (Hyena, Poli et al., arXiv:2302.10866) mix tokens by FFT. The inference series found that for a Hyena-2 model of Llama-3-8B's shape the transform work is 0.20% of prefill FLOPs at 2,048 tokens: the FFT is what makes Hyena cheap, and the projections and MLP dominate.

This script's forward column agrees: Hyena-2 at 2,048 tokens, 0.20% of the forward pass (slide 08). The physics of the engine (the lens as a Fourier transformer, the 4f system, masks and SLMs, ENOB) is in FOptInf 01 and is not repeated here.

The hope training might raise

Training has three passes for every one of inference, and FFT convolution was introduced for these models to make training affordable at length. Perhaps the backward pass is where transforms pile up? The next slides derive the backward pass of a long convolution, then count. The answer is no: the share goes down.

04

The Gradient of a Convolution Is a Correlation

One channel of a causal long convolution, length L, with the output gradient g = ∂ℒ/∂y arriving from above:

derivation sketch (real signals, indices outside 0..L−1 are zero)
forward      y[i]   = Σk h[k] u[i−k]                    Y  = H · U
input grad   ∂ℒ/∂u[j] = Σi g[i] ∂y[i]/∂u[j] = Σi g[i] h[i−j]
                                         dU = G · conj(H)
filter grad  ∂ℒ/∂h[k] = Σi g[i] u[i−k]          dH = G · conj(U)
Lengthmax abs error dU (spectral vs direct)max abs error dHdU vs finite difference
646.2e-157.1e-151.4e-08
1,0005.7e-145.7e-147.1e-08

Source: results.md, section “6. Numeric checks of the backward formulas”. The spectral formulas agree with direct sums to rounding; the finite-difference column is limited by the difference step, not the formula. Length 1,000 is not a power of two: it is padded to 2,048.

05

Three 4f Passes: Forward, dX and dW

Mapped onto a 4f system (lens, Fourier-plane mask, lens; FOptInf 01, “The 4f System”), one channel of one layer needs three passes per training sequence. What matters is what sits on the mask:

forward input udata lens: FFTU mask × Hweight: fixed forthe whole step lens: IFFTADC out ykeep U backward: dX (input gradient) input gfrom above lens: FFTG mask × conj(H)same weight, mirrored(or phase-flipped) lens: IFFTADC out dUto layer l−1 backward: dW (filter gradient) input gG reused (G fromthe dX pass) mask × conj(U)DATA: new for everysequence and layer Σ overthe step dH1 IFFT/step weight-masked: one mask write per step data-by-data: one write per sequence
06

Weight-Masked and Data-by-Data Products

The ledger splits every Fourier-domain product by its operands, because that decides whether a mask written once per optimizer step can hold it:

conj(H) can be a mask

  • H is the spectrum of a weight, fixed between optimizer steps. So is conj(H).
  • For a real filter, conj(H(f)) = H(−f): the conjugate spectrum is the same mask point-reflected through the optical axis. A modulator that writes complex values can instead write the negated phase.
  • Equivalently, a correlation is a convolution with the time-reversed filter: the classical optical correlator is a 4f system with the conjugate spectrum on the mask (FOptInf 01). In principle, reversing the gradient at the input and output lets the forward mask itself serve the backward pass (this deck's reasoning, not a demonstrated system).

conj(U)·G cannot be a static mask

  • U is the spectrum of this sequence's input to this channel; G is its output gradient. Neither survives to the next sequence.
  • Putting conj(U) on the mask and passing G through works, but costs a mask write per sequence per layer: minutes of frames per step on one illustrative device, and still about a whole digital step for Hyena-2 when spread over one engine per GPU (slide 11).
  • Optics can correlate two live signals without a written mask (a joint transform correlator records the intensity of their joint spectrum and transforms it again), but that intermediate must itself be written to a modulator for every pair: it moves the write, it does not remove it.
Class in the ledgerProductsMask written
transformFFTs and inverse FFTsnone (the lenses)
weight-maskedU·H forward, G·conj(H) backwardonce per step, per direction
data-by-dataG·conj(U) for the weight gradientonce per sequence (per token for block-circulant)

Static share = transforms plus weight-masked products, over all step FLOPs: what an engine whose masks change only at optimizer steps could take. The optical share adds the data-by-data products as well.

07

Block-Circulant Weights in Training

The inference series' one large-share case made every projection and MLP matrix block-circulant (CirCNN, Ding et al., arXiv:1708.08917; block 256 here, illustrative): each block is defined by one vector, so a block product is an FFT, a pointwise product and an inverse FFT. Training applies the same split per block:

PassPer token, per block row and columnClass
ForwardFFT the input blocks; multiply by each weight block's spectrum Wpq; sum over input blocks; IFFT the output blockstransform, weight-masked
Backward dXFFT the gradient blocks; multiply by conj(Wpq); sum; IFFTtransform, weight-masked
Backward dWmultiply Gp by conj(Xq), accumulated over every token of the step; one IFFT per block per stepdata-by-data
Once per stepFFT of every weight block after the update; IFFT of every block gradienttransform, amortised
Speculative

No published LLM of this size is block-circulant throughout, as far as the inference series found. Whether such a model trains to useful quality is unknown, and training it would itself be the experiment.

08

The Training-Step Amdahl Table

Share of FLOPs that is transform work in the forward pass, the backward pass and the whole step; the static share; the data-by-data part of the optical work; and the Amdahl bounds 1/(1−share). The transformer is 0.00% throughout and omitted.

VariantSequenceFwd shareBwd shareStep shareStatic shareData-by-data part of opticalAmdahl (all)Amdahl (static)
Hyena-22,0480.20%0.10%0.14%0.13%2.32%1.001x1.001x
Hyena-24,0960.21%0.11%0.15%0.14%2.15%1.001x1.001x
Hyena-28,1920.23%0.12%0.16%0.15%2.01%1.002x1.002x
Hyena-232,7680.27%0.14%0.18%0.18%1.75%1.002x1.002x
Hybrid 1:3 attention:Hyena2,0480.15%0.08%0.10%0.10%2.32%1.001x1.001x
Hybrid 1:3 attention:Hyena4,0960.16%0.08%0.11%0.11%2.15%1.001x1.001x
Hybrid 1:3 attention:Hyena8,1920.17%0.09%0.12%0.11%2.01%1.001x1.001x
Hybrid 1:3 attention:Hyena32,7680.18%0.09%0.12%0.12%1.75%1.001x1.001x
Hyena-2 + block-circulant weights2,04813.99%11.06%12.06%9.53%20.98%1.137x1.105x
Hyena-2 + block-circulant weights4,09614.18%11.16%12.19%9.66%20.73%1.139x1.107x
Hyena-2 + block-circulant weights8,19214.36%11.26%12.32%9.79%20.49%1.140x1.109x
Hyena-2 + block-circulant weights32,76814.75%11.47%12.59%10.07%19.98%1.144x1.112x

Source: results.md, section “2. A training step”. The hybrid's ratio and the circulant block size are illustrative.

09

Why the Share Falls from Forward to Step

Every row of the table has the same shape: backward share well below forward share, step share in between. The ledger shows why, per Hyena channel and per matmul:

WorkForwardBackwardBackward / forward
Long FFTs per channelFFT(u), IFFT(y)FFT(G), IFFT(dU)the same
Fourier-domain products per channelU·HG·conj(H), G·conj(U)twice
Matmuls (projections, MLP, LM head)W xWT G and G XTtwice
So

Training does not rescue the transform share. FFT convolution makes long-context training cheap, and that is exactly why it is a small part of what a training step spends.

10

Interactive: Training-Step Amdahl Explorer

The FLOP ledger of train_flop_share.py (step_per_sequence for the four variants, its op classes and the section-4 mask budget), ported to JavaScript and tested to give identical numbers (js/train_flop_model.js, checked by analysis/test_js_parity.py). The default state reproduces the results.md section 2 row “Hyena-2 + block-circulant weights, 4,096”: 14.18%, 11.16%, 12.19%, 9.66%, 20.73%, 1.139x, 1.107x.

4,096
1,048,576
Forward share
—
Backward share
—
Step share
—
Static share
—
Data-by-data part
—
Amdahl all / static
—

Things to try: move the step size and watch the shares stay put while the digital step time grows and the weight-mask frames do not; then switch to the transformer and see the bars turn entirely digital. Sequences beyond the model's trained context are shape-only extrapolations, and the 64-GPU cluster and mask device are illustrative.

11

Masks Rewritten Every Optimizer Step

An inference engine writes its filter spectra once and keeps them. A training engine must rewrite every weight spectrum after every optimizer step, for the forward pass (H) and the backward pass (conj(H)). On the inference series' illustrative device, a 2-megapixel micromirror device at 1,031 Hz with 8-bit depth, holding one complex value per pixel (optimistic):

VariantSequenceSequences/stepDigital step timeWeight-mask frames (fwd + bwd)TimeData-by-data framesTime
Hyena-22,0485122.05 s5380.52 s137,507133 s
Hyena-28,1921282.05 s2,1482.08 s137,456133 s
Hyena-2 + block-circulant weights2,0485120.15 s5540.54 s397,218385 s
Hyena-2 + block-circulant weights8,1921280.15 s2,1642.10 s397,168385 s

Source: results.md, section “4. Holding the masks”. Digital step time = step FLOPs on an illustrative 64 GPUs at 400 TFLOP/s sustained each.

12

Layer-Major Order

The frame counts above assume the most favourable schedule: layer-major order, in which every sequence of the step passes through one layer while that layer's mask is loaded, before the mask is rewritten for the next layer.

Layer-major: one write per layer per step

  • Forward: load layer 1's H, stream all 512 sequences (at 2,048 tokens), move to layer 2, and so on.
  • Backward, in reverse layer order: load conj(H), stream all the gradients.
  • Each weight mask is written twice per step, which is the “fwd + bwd” column of slide 11.

What it costs

  • Activation memory: the whole step's activations at a layer boundary must be held at once, where ordinary training holds one micro-batch's.
  • Pipeline parallelism streams micro-batches through stages in sequence order, the opposite schedule.
  • Sequence-major order instead would reload every mask for every sequence, multiplying the weight-mask frames by the sequences per step.

Whether a cluster can run layer-major for the layers that touch the engine, and what that does to memory, parallelism and step time, is the subject of deck 03, “Optical Engines in a Training Cluster”.

13

What Does Not Map in Training

WorkWhy a Fourier transform engine does not help
Attention, forward and backwardData-dependent, causal, softmax-normalised products: not convolutions. The backward pass recomputes or stores the score matrix and does twice the forward's matmul work; none of it is a transform
Dense projections, MLP, LM head (dX and dW)General matmuls, now three times over: work for an optical MAC, not a Fourier engine, unless the weights are structured (slide 07)
Weight gradients of Fourier-domain layersData-by-data products (slide 06): a mask write per sequence, or per token for block-circulant
Norms, activations, softmax and the lossNon-linear; stay digital, forward and backward
The optimizer's element-wise workAdamW (Loshchilov and Hutter, arXiv:1711.05101) updates each parameter from its gradient and two moment estimates: element-wise arithmetic, not a transform
AdamW's statesTwo moments per parameter, kept in memory between steps: a capacity and bandwidth problem. A Fourier-plane mask is not a store for them
MoE routingData-dependent dispatch of tokens to experts, with its own load-balancing gradients: control flow, not a convolution
Gradient all-reduceCommunication. DeMo DCT-compresses the momentum before it is sent, but its transforms are 4.76e-06 of a step's FLOPs: the saving is in bytes, the subject of deck 03 and the Compute in Transit series. That saving has been measured (a 15.8M-parameter GPT on TinyStories, 8 simulated workers): DeMo's fixed DCT band cuts what a worker originates 16× against a dense gradient, but the bytes it puts on the wire only 4×, because an all-gather's traffic grows with the number of workers and an all-reduce's does not. It costs convergence: final validation loss 3.12–3.16 for the fixed band against 1.646 for AdamW (CiT results, what each worker sends; CiT 04)

And the hidden costs that apply even where it maps, now per step instead of once: mask rewrites, conversions per value, and the precision a gradient format asks for (deck 02).

14

What to Take Away