AI State of the Art
SOTA/Post-Transformer Architectures/22 min
Section 70

Hyena and Long Convolutions

Listen as a podcast β†’

The DNA problem

Stanford's Hazy Research team asked a very concrete question: can you analyze entire genomic sequences with language models?

An average human gene is ~27,000 bases. A complete chromosome has several hundred million. Standard attention with O(L^2) complexity is completely out of the question at this scale, for a 100 million base chromosome, you'd need to compute 10^16 pairwise interactions. Even SSMs and standard convolutions struggle at this size.

Their answer: Hyena, a mechanism based on convolutions that cover the entire sequence (not just a few neighboring tokens like classic convolutions) while remaining sub-quadratic in complexity.

Hyena Hierarchy: Towards Larger Convolutional Language Models

Convolutions: filters that read the entire sequence

Short convolutions vs long convolutions

In NLP, classic convolutions use short kernels: a filter that looks at 3, 5, maybe 7 tokens at a time. It's like looking at the world through a narrow slit, very effective for local patterns (n-grams, syntactic motifs), but unable to capture a relationship between two words separated by 1,000 tokens.

Attention solves this problem by directly comparing every token to all others, a complete panoramic view. Powerful, but O(L^2) in cost.

Hyena proposes a third way: convolutions whose kernel covers the entire sequence. A kernel of size L can theoretically encode a dependency between any two tokens, no matter how far apart. And thanks to the FFT (the Fast Fourier Transform, presented in detail in the S4 lesson), such a convolution is computed in O(L log L), a cost that grows barely faster than the length itself, much less than quadratic attention.

Four-panel figure. A: GPT-NeoX architecture with rotary positional embeddings feeding a masked multi-head attention block, followed by a feed forward block, repeated N times. B: the same architecture with the multi-head attention block replaced by a Hyena mechanism block, and no rotary positional embeddings. C: the attention operator, where q and k enter a MathMul then Scale, optional Mask, Softmax, producing a, which is combined with v in a second Matmul to give y. D: the Hyena operator, where u passes through a Dense layer to give v, then goes through a diagonal gate D_k, a long convolution S_h with filter h, and a second diagonal gate D_q, the gates being produced by Dense layers applied to u.
Panels C and D capture the difference. Attention (C) builds a score matrix by dot product between q and k, then softmax: that is the mandatory step costing O(L squared). Hyena (D) replaces all of it with an alternation of diagonal gates D_k, D_q and one long convolution S_h. Panels A and B show that the substitution happens block for block inside the Transformer, with nothing else changed.Source : Scavenging Hyena: Distilling Transformers into Long Convolution Models, via ar5iv
FFT: the Swiss army knife of sequential computation

The Fast Fourier Transform (FFT) is an algorithm that computes the convolution between two sequences of length L in O(L log L) instead of O(L^2). For L = 1,000, that's 100 times fewer operations. For L = 1,000,000 (a chromosome), it's 50,000 times fewer. That's why any architecture targeting very long sequences uses FFT at some point, it's the mathematical tool that makes scaling possible.

The Hyena operator: convolutions + hierarchical gating

The basic structure

The Hyena operator of order N combines N long convolutions with interleaved multiplicative gates ("valves" that dose what passes through). It's a systematic alternation: convolve (propagate information along the sequence), then filter (keep only what's relevant), and repeat.

y=x1βŠ™(h1βˆ—(x2βŠ™(h2βˆ—β‹―(xNβŠ™(hNβˆ—v))⋯ )))y = x_1 \odot \bigl(h_1 * \bigl(x_2 \odot \bigl(h_2 * \cdots \bigl(x_N \odot (h_N * v)\bigr) \cdots\bigr)\bigr)\bigr)

In this formula, the vectors v, x_1, ..., x_N are linear projections of the input, meaning different "views" of the same sequence. The filters h_1, ..., h_N are long convolutions of size L. The symbol odot denotes element-wise multiplication (this is the gating operation, which selectively filters information), while * denotes convolution, computed efficiently via FFT.

To read the formula, start from the inside: h_N * v propagates information along the sequence, x_N odot selectively filters this information, then h_(N-1) * propagates again, x_(N-1) odot filters again, and so on. Each layer of this hierarchy refines and enriches the representation.

Two-part diagram. Left, Hyena Recurrence: input u passes through a Dense layer to give v, then travels through an alternating chain of red triangular matrices S_h superscript 1, S_h superscript 2 up to S_h superscript N representing the long convolutions, and diagonal matrices D_x superscript 1 up to D_x superscript N representing the gates, each gate produced by a Dense layer applied to u; the filters h superscript 1, h superscript 2, h superscript N are drawn below the convolution matrices as decaying signals. Right, Hyena Filters: a stack of PositionalEncoding then FFN then Window that generates the filter.
On the left, the alternation described by the formula: the red triangular squares are the long convolutions (Toeplitz matrices, one per filter h), the diagonal squares are the multiplicative gates, and each gate comes from a Dense projection of the input. On the right, the filter factory: a positional encoding enters a small FFN whose output is multiplied by a decaying window, exactly the implicit convolution formula from the next section.Source : Hazy Research blog (Stanford), Hyena Hierarchy paper by Poli et al.

Why gating is crucial

Without gating, stacking convolutions would be useless. The reason is mathematical: linear convolutions are composable. h1 * (h2 * x) is strictly equivalent to (h1 * h2) * x, a single larger convolution. Stacking 10 linear convolutions with nothing between them amounts to having just one.

Multiplicative gating x odot y breaks this linearity and introduces non-linear interactions between sequence positions. That's what gives Hyena expressiveness potentially close to attention, the ability to combine information in a contextually adapted way.

Analogy with attention

An order-2 Hyena can be interpreted as a form of approximate attention: the v projection plays the role of values, the h * convolution propagates information contextually (analogous to attention scores), and the x odot gating plays the role of filtering by queries. Without all three components together, you don't capture complex interactions between positions, it's their combination that creates the expressiveness.

Implicit convolutions: a filter without storing its weights

A convolutional filter of size L covering the entire sequence would have L parameters, potentially millions. Storing all of that in memory would be expensive and inflexible if L changes between training and inference. Hyena uses an elegant solution: implicit convolutions where the filters are generated on demand by a small neural network.

h(t)=Window(t)β‹…MLPΟ•(t)h(t) = \text{Window}(t) \cdot \text{MLP}_\phi(t)

A small MLP (multi-layer perceptron, a neural network of 2-3 layers; the subscript Ο•\phi denotes its learned weights) takes position t as input and produces the filter value at that position. The Window(t) function (typically an exponential decay) ensures that the filter naturally attenuates with distance, encoding the inductive bias that nearby interactions matter more than distant ones.

Advantages of implicit filters

Implicit filters have a remarkable property: they generate kernels of arbitrary length with a fixed number of parameters. The MLP has exactly the same size whether the sequence is 1,000 or 100,000 tokens, only the input changes, not the network. Furthermore, the natural regularity of an MLP "smooths" the filter, avoiding overfitting to noisy patterns. It's elegant and economical.

Implementation via FFT

Each long convolution follows the standard FFT protocol in four steps:

  1. h^=FFT(h)\hat{h} = \text{FFT}(h), transform the filter to frequency domain
  2. x^=FFT(x)\hat{x} = \text{FFT}(x), transform the input to frequency domain
  3. y^=h^βŠ™x^\hat{y} = \hat{h} \odot \hat{x}, point-wise multiplication (convolution in frequency domain)
  4. y=IFFT(y^)y = \text{IFFT}(\hat{y}), back to time domain (IFFT is the inverse FFT, the return trip)

The deep insight: convolution is expensive in the time domain (O(L^2)), but transforms into simple multiplication in the frequency domain. FFT makes the round trip in O(L log L).

Total complexity for an order-N Hyena operator:

OperationComplexity
Linear projectionsO(L * d^2)
Convolutions via FFTO(N * L * log(L) * d)
GatingO(N * L * d)
TotalO(L * d^2 + N * L * log(L) * d)

In this table, L is the sequence length, d the dimension of the representations, and N the operator's order (the number of convolution/gate alternations). Compared to standard attention O(L^2 * d), Hyena is advantageous when the sequence is much longer than the hidden dimension, typically for genomics (L = 100K+) or long-duration audio (L = 500K+).

Two plots titled Benchmarking Hyena. Left, runtime in milliseconds on the vertical axis against sequence length on the horizontal axis from 10 to the 3 to 10 to the 5: the Attention curve climbs steeply beyond 10 to the 4, FlashAttention climbs slightly later, while the Hyena curve stays nearly flat and barely exceeds 10 milliseconds. Right, a zoom on the region 10 to the 3 to 10 to the 3.9 where Hyena starts above FlashAttention and where the Attention and Hyena curves cross around 10 to the 3.3.
Measured wall-clock time, not just theoretical complexity. On the left, the gap becomes dramatic past 10,000 tokens: attention blows up, Hyena stays flat. On the right, the zoom on short sequences tells the other half of the story: below a few thousand tokens, FlashAttention is still ahead of Hyena.Source : Hazy Research blog (Stanford), Hyena Hierarchy paper by Poli et al.

Results and limitations

Where Hyena excels

On standard language modeling benchmarks (~1B parameters), Hyena is competitive with same-size Transformers. The perplexity gap is small on common tasks, proof that long convolutions with gating are a viable alternative.

On very long sequences (genomics, long-duration audio, full document analysis), Hyena truly shines. Its sub-quadratic complexity allows processing sequences of hundreds of thousands of tokens that Transformers simply can't reach without drastic approximations.

Practical limitations of Hyena

Despite its theoretical advantages, Hyena has concrete practical limits. FFTs are not as well optimized on modern GPUs as matrix multiplications (matmul), NVIDIA GPU tensor cores are designed for matmul, not FFT. The theoretical complexity gap doesn't always translate into real speed gains on current-length sequences (< 10K tokens). Moreover, Hyena hasn't been validated beyond ~1B parameters for language. Mamba and selective SSMs have since captured more attention in the community, particularly thanks to better hardware implementations.

Variants and extensions

H3 (Hungry Hungry Hippos): Hyena's direct predecessor. Combines two SSM layers with a multiplicative gate between them. H3 established the fundamental principle: gating between sequential operators drastically increases expressiveness, transforming individually weak components into a powerful ensemble.

StripedHyena (Together AI): a hybrid model alternating Hyena layers with standard attention layers. Competitive at 7B parameters, StripedHyena demonstrates that the hybrid principle (efficient layers + a few attention layers) works just as well with long convolutions as with SSMs.

Hyena for vision: the architecture has been adapted for Vision Transformers, where 2D long convolutions can replace self-attention on high-resolution images, allowing processing of much larger images without quadratic cost.

Hyena's place in the ecosystem

Hyena played an important trailblazer role in exploring alternatives to attention. It proved that long convolutions with hierarchical gating are a viable and performant approach, not just a theoretical curiosity. The ideas of implicit filters (generating the kernel on the fly with a small MLP) and hierarchical gating (alternating convolutions and gates for expressiveness) continue to influence modern architectures.

Position within the sub-quadratic family

Hyena belongs to the family of models based on long convolutions, alongside S4 (which produces its convolutions via state equations) and RWKV (based on linear recurrent attention). All three share the goal of sub-quadratic processing but arrive there via different paths: Hyena uses explicit convolutions via FFT, S4 uses implicit convolutions derived from state equations, and RWKV uses exponential-decay recurrence. This diversity of approaches nurtured a rich research program that culminated in Mamba and hybrid architectures.

Check your understanding0 / 4

1. How does Hyena manage to connect tokens that are very far apart without paying attention's quadratic cost?

2. Why can't you simply stack convolutions on top of each other, without the multiplicative gates?

3. A Hyena filter spans the whole sequence, potentially hundreds of thousands of positions. How does it avoid storing that many weights?

4. In practice, on sequences of common length (under 10,000 tokens), does Hyena beat attention on speed?