Fourier Optics for Inference — Presentation 02

Transforms in Inference Workloads

Where a Fourier transform could appear in LLM inference, and how much it would matter: FNet, long convolutions (S4, H3, Hyena), causality at prefill and decode, an Amdahl analysis of prefill FLOP shares, structured weights, transform-domain KV compression, mask capacity, and an honest list of what does not map.

FNet Hyena Causality Amdahl Structured weights Disaggregation
Model → Op mix → Transform share → Amdahl bound → Prefill pool
00

Topics We'll Cover

Concepts used here, and where they are explained. Each links to a glossary entry: this series glossary, or the glossaries of LLM Inference Simulators, FHE Accelerator Simulators and the Simulation Engineering Toolkit for concepts those series already explain.

01

Where a Transform Could Hide in an LLM

Deck 01 showed what a Fourier-optical engine does well: long transforms and convolutions, with the weights held on a mask, at a cost per converted value. The question for inference is whether the work contains such transforms, and how much of the work they are. Three places to look, and two things that are photonics but not Fourier optics:

WhereWhat the transform doesSlides
Token mixingFNet's Fourier mixing; long convolutions (S4's convolution mode, H3, Hyena) computed by FFT03–07
Structured weightsCirculant, block-circulant or Monarch matrices, whose products are transforms08
Transform-domain compressionDCT/Fourier coefficients of the KV cache or hidden states along the sequence09
Optical MACs (not Fourier optics)Matrix multiplies done optically: the simulator's hypothetical optical part02
Photonic interconnect (not Fourier optics)Moving the KV cache between pools over optical links13

Every number from here on comes from analysis/flop_share.py, which counts FLOPs for a model of Llama-3-8B's shape (Llama 3 report) in five variants and writes results.md.

02

A Standard Decoder Has No FFT

A Llama-style decoder is matrix multiplies (projections, the SwiGLU MLP, the LM head) plus attention (QKT and AV), softmax, norms and activations. None of it is a Fourier transform. The analysis reproduces the companion simulator's FLOP count exactly (Disaggregated_Inference_Sim's cost model, checked to the FLOP), and splits it by class:

Llama-3-8B prefillGFLOPDense matmulAttention
512 tokens7,753.699.1%0.9%
2,048 tokens31,839.196.5%3.5%
32,768 tokens773,308.963.6%36.4%
131,072 tokens6,470,935.230.4%69.6%

Source: results.md, section “2. Prefill”. Lengths beyond the model's trained context are shape-only extrapolations.

An optical MAC would help this model

The simulator's HYPOTHETICAL_OPTICAL device is a “what if compute were nearly free” probe: it speeds up every dense FLOP, and, as its comment in hardware.py says, decode barely moves because decode is bandwidth-bound.

A transform engine would not

A Fourier transform engine accelerates only FFT and convolution work and leaves matmuls to a digital part. For this model its share is zero. The rest of the deck asks which other models give it something to do.

03

FNet: Fourier Token Mixing

FNet replaces each self-attention sublayer of a Transformer encoder with an unparameterised 2-D discrete Fourier transform over the sequence and hidden dimensions, keeping the real part. Lee-Thorp et al. report 92–97% of BERT's GLUE accuracy while training 80% faster on GPUs and 70% faster on TPUs at 512 tokens (arXiv:2105.03824).

Why it looks made for optics

  • A 2-D DFT over (sequence × hidden) is exactly what a lens computes.
  • No weights in the mixer: no mask to rewrite.

Why it does not help an LLM

  • It is not causal. Every output mixes every token, including later ones. In the analysis, perturbing the last token changes the first token's mixed output by 64.0 (a 256×64 block): a decoder cannot use it as it stands.
  • It is a tiny share of the work. In a model of Llama-3-8B's shape with FNet mixing, the transform is 0.09% of prefill FLOPs at 2,048 tokens: the MLP dominates.

The FFT is what makes FNet cheap. Making a cheap operation free buys little: the theme of this deck.

04

Long Convolutions: S4, H3 and Hyena

Causal sequence models that mix tokens with a long convolution (a filter as long as the sequence) can compute it by FFT in O(L log L):

ModelMixerConvolution or recurrence?
S4 (Gu, Goel, Ré, arXiv:2111.00396)A structured, time-invariant state-space modelBoth: a long convolution for training, a recurrence for generation (reported 60× faster generation)
H3 (Fu, Dao et al., arXiv:2212.14052)Two SSMs with multiplicative gatingFFT convolution at training and prefill
Hyena (Poli et al., arXiv:2302.10866)N+1 projections, a short depthwise conv, N implicit long convolutions with gating (order 2 for language)FFT convolution, with input and filter zero-padded to 2L − 1 for causality (the paper, section 3)
Mamba (Gu, Dao, arXiv:2312.00752)A selective SSM: parameters depend on the inputRecurrence only: selectivity “prevents the use of efficient convolutions” (the abstract)
05

Causality at Prefill and at Decode

Prefill: one long FFT per channel

  • The whole prompt is known, so each channel's long convolution is one FFT, a multiply and an inverse FFT, zero-padded to 2L so it is linear and causal.
  • Checked in NumPy: padded FFT against direct, 5.6e-16 of the peak; perturbing the last input moves earlier outputs by 7.1e-15. Unpadded, the wrap leaks the future by 2.75.

Decode: one token at a time

  • Direct: cache past inputs, take a dot product with the filter: O(context) per token, no transform. It equals the prefill output (5.8e-16).
  • Distilled: fit each filter with a small SSM and run it as a recurrence, O(1) per token (Laughing Hyena, arXiv:2310.18780).
  • Relaxed tiling: convolve each completed block of 2l inputs by FFT and add it to future outputs: exact, O(L log2 L) in total (Flash Inference, arXiv:2410.12982). Checked: 4.5e-16.
MixerContextGFLOP / tokenMixer FLOPs / tokenTransform share
transformer2,04816.0841,074.3 M0.00%
transformer32,76832.19017,180.4 M0.00%
hyena_direct2,04817.6941,074.3 M0.00%
hyena_direct32,76833.80017,180.4 M0.00%
hyena_distilled2,04816.65333.6 M0.00%
hyena_distilled32,76816.65333.6 M0.00%
hyena_tiled2,04816.877256.9 M1.40%
hyena_tiled32,76817.046425.7 M2.34%
hyena_recompute2,048162.650146,030.5 M85.82%
hyena_recompute32,7683,040.2783,023,658.5 M96.06%

Source: results.md, section “4. Decode”

So the hypothesis needs care: decode can use FFTs, but only in small passes on the latency-critical path. Conversions per token per channel (DAC+ADC pairs): a prefill long convolution converts each input once and each output once, 1 pair per token. Relaxed tiling at decode converts, at each of its tile levels, a block of B inputs and B outputs every 2B steps, 0.5 pairs per token per level: 6 pairs at context 2,048 (12 levels); 8 pairs at context 32,768 (16 levels), in small passes on the latency-critical path.

06

The Amdahl Analysis: Prefill FLOP Shares

Optical share f = FFT FLOPs plus the pointwise multiplies in the Fourier domain (what a 4f mask does), over all prefill FLOPs. If the engine made that work free, prefill would speed up by at most 1/(1−f) (Amdahl's law).

Variant512 tokens2,048 tokens8,192 tokens32,768 tokens131,072 tokens
Transformer (Llama-3-8B)0.00%0.00%0.00%0.00%0.00%
FNet-shaped (non-causal)0.08%0.09%0.10%0.11%0.12%
Hyena-20.17%0.20%0.23%0.26%0.29%
Hybrid 1:3 attention:Hyena0.13%0.15%0.17%0.18%0.15%
Hyena-2 + block-circulant weights13.63%13.99%14.35%14.70%15.05%

Source: results.md, section “2. Prefill”

07

Interactive: Amdahl Explorer

The FLOP ledger of flop_share.py, ported to JavaScript and tested to give identical numbers (js/flop_model.js). Choose a model, a prompt length, where the LM head runs, and how fast a GPU runs FFTs relative to matmuls (r, an assumption).

2,048
Prefill GFLOP
—
Optical share (FLOPs)
—
Amdahl bound (FLOPs)
—
Share of time / bound at r
—

Things to try: switch the block-circulant model's LM head to the last token only, then set r = 1/16. That is the only corner of this space where a transform engine has most of the work.

08

Structured Weights: Circulant and Monarch

If token mixing is too small a share, the transforms would have to come from the weights: matrices whose product with a vector is a transform.

The analysis makes every projection and MLP matrix block-circulant (block 256, illustrative) in the Hyena-2 model. The LM head then dominates, so where it runs decides the answer:

VariantPromptGFLOPOptical shareAmdahl bound
Hyena-22,04831,959.90.21%1.002x
Hyena-232,768511,686.30.28%1.003x
Hyena-2 + block-circulant weights2,048426.684.54%6.469x
Hyena-2 + block-circulant weights32,7687,152.885.47%6.883x

Source: results.md, section “2. Prefill”

Speculative

This is the only variant where a transform engine has most of the work, and it is the least established: phase A of this work found no published LLM of this size with block-circulant weights throughout. Quality at that scale is unknown, and the weights live on the Fourier-plane mask (slide 11).

09

Transform-Domain Compression of the KV Cache

A third place transforms appear: compressing what the model stores, along the sequence, by keeping a few frequency coefficients. This literature exists and is recent:

WorkWhat it transformsReported result
Fourier Transformer (He et al., arXiv:2305.15099)Hidden states, with a DCT computed by FFT, progressively removing sequence redundancyInherits pretrained weights (BART); strong long-range benchmark results
FreqKV (Kai et al., arXiv:2505.00570)The KV cache, iteratively compressed in the frequency domain, keeping low frequenciesExtends LLaMA-2-7B's context to 256K tokens with minimal training at 8K
FourierAttention (Liu et al., arXiv:2506.11886)The long-context-insensitive head dimensions, projected onto fixed-length Fourier basesTraining-free; a fused Triton kernel
10

Precision and Energy per Token

Precision: float workloads need the analogue error to match the number format's own rounding (deck 01, “Precision: ENOB, Noise and Crosstalk”): about 8.0 ENOB for INT8-like error, 6.3 for FP8 E4M3 and 10.3 for BF16. Below that, averaging costs 4× the passes per bit.

Energy: DAC+ADC pairs per prompt token, and their energy at each ENOB, against the digital energy of the transform work they replace, in µJ per prompt token (Walden FoMs 10/20 fJ and 1 pJ/FLOP, both illustrative):

VariantPairs / tokenDigital uJENOB 8 uJENOB 12 uJBreak-even ENOB
FNet-shaped (non-causal)131,07211.11.016.111.5
Hyena-2262,14433.02.032.212.0
Hybrid 1:3 attention:Hyena196,60824.81.524.212.0
Hyena-2 + block-circulant weights2,162,688176.116.6265.811.4

Source: results.md, section “7. Conversion energy”

11

Holding the Weights: Fourier-Plane Mask Capacity

A 4f pass multiplies by one mask. Each Hyena channel's filter spectrum (or each circulant block) must be on the mask while its inputs pass, so the mask is the weight store, and rewriting it costs a frame of the spatial light modulator (deck 01, “Spatial Light Modulators”). Time to rewrite a 2-megapixel mask enough times for one forward pass, at three device rates: a micromirror device at 1-bit depth (20 kHz) and 8-bit depth (1.03 kHz), and a liquid-crystal SLM (30 Hz):

VariantPromptRewritesDMD 20 kHzDMD 1.03 kHzLC 30 Hz
Hyena-22,04826913.4 ms261 ms9.0 s
Hyena-232,7684,296214.8 ms4,167 ms143.2 s
Hyena-2 + block-circulant weights2,04827713.8 ms269 ms9.2 s
Hyena-2 + block-circulant weights32,7684,303215.2 ms4,174 ms143.4 s

Source: results.md, section “8. Holding the filters”

12

What Prefill Hands to Decode

Disaggregated serving moves state from the prefill pool to the decode pool once per request (LLM Inference Simulators 05, “What the KV Transfer Costs”). What that state is depends on the mixer:

Decode styleBytes per prompt tokenBytes for a 2,048-token promptGrows with the prompt
Transformer KV cache (GQA)131,072268.4 MByes
Hyena direct: cached projection inputs524,2881,073.7 MByes
Hyena distilled recurrence staten/a16.8 MBno

Source: results.md, section “9. What prefill hands to decode”

13

Why Disaggregation Fits

Prefill pool (compute-bound) opticaltransformFFT / convmask = filters digitalpartmatmuls, MLP,LM head KV cache or statelink: electrical or photonic(photonic links are notFourier optics) Decode pool (memory-bound) HBM-rich digital devicesone token per stepdirect cache or recurrenceno long transforms
Public material, and this deck's speculation

Optical-computing companies publish little about inference mapping. Several publicly describe photonic computing systems for AI and for FHE, and published optical computing for FHE centres on Fourier transforms (FHESim 04). The mapping in this deck is the author's own analysis and speculation, attributed to no company.

14

What Does Not Map

WorkWhy a Fourier transform engine does not help
Attention (QKT, softmax, AV)A data-dependent, causal, softmax-normalised product: not a convolution. At long context it is the biggest term (69.6% of Llama-3-8B prefill at 131,072 tokens), and none of it is a transform
Dense projections, MLP, LM headGeneral matmuls: work for an optical MAC, not a Fourier engine, unless the weights are structured (slide 08)
Mamba's selective scanInput-dependent parameters rule out the convolution form; it is a recurrence
Decode, generallyOne token per step: direct dot products or recurrences, memory-bound; relaxed tiling uses FFTs only in small latency-critical passes (slide 05)
Norms, activations, softmax, sampling, MoE routingNon-linear or data-dependent; stay digital
FNet mixing in a decoderNot causal (slide 03)
KV-cache readsA bandwidth problem; optics could shrink it only through compression (slide 09) or move it over photonic links

And the hidden costs that apply even where it maps: conversions per value, precision passes, mask rewrites, sign recovery at the detector, and static power whether or not work arrives.

15

What to Take Away