Attention, Dynamic Wave and Hybrid Sequence Mixers in Language Models
Organizations: Kharkiv National University of Radio Electronics Kharkiv, Ukraine · Military Law Institute Yaroslav Mudryi National Law University Kharkiv, Ukraine
Abstract
Large Language Models (LLMs) rely on Multi-Head Attention (MHA) for sequence modeling, but scaling to long contexts is constrained by the quadratic cost of attention, motivating sub-quadratic recurrent alternatives. This paper formalizes a Dynamic Wave recurrent layer, based on input-dependent exponential damping and cosine phase modulation, and evaluates three 10.94M-parameter configurations (Pure Transformer, Pure Wave, and Hybrid Wave-Attention) on TinyStories under perplexity, latency, throughput and peak VRAM profiling up to 4096 tokens. The Hybrid configuration reaches the best perplexity, 5.95 on the full held-out split against 6.93 for the Transformer and 7.26 for Pure Wave. The efficiency picture, however, is governed by implementation rather than by architecture. Against an unfused attention baseline, Pure Wave uses 78.7% less peak VRAM at a 4096-token context (1404.3 MB vs. 6601.6 MB); against a fused scaled-dot-product attention kernel the same comparison yields no advantage at all (1404.3 MB vs. 1403.6 MB), and in training mode Pure Wave is 8.3% more expensive than the Transformer. Likewise, hoisting elementwise terms out of the recurrence loop speeds the layer up 2.53-fold with no custom kernel, reducing its latency gap to attention from 2.48-fold to 1.12-fold. A hybrid stack is found to inherit the cost of its more expensive mixer rather than the advantage of its cheaper one, its peak VRAM matching the Pure Transformer to within 0.1%. A closed-form memory model reproduces these measurements and predicts the context length beyond which attention overtakes the vocabulary projection. The findings indicate that reported efficiency gains for recurrent attention replacements must be stated relative to a named attention backend and a named implementation, and that hybridization is best justified on quality grounds.
Figures & tables
| Mixer | Training time | Training memory | Generation memory (per step, ideal) |
|---|---|---|---|
| Multi-Head Attention, unfused [ 3 ] | (KV cache) | ||
| Multi-Head Attention, fused [ 4 ] | (KV cache) | ||
| Dynamic Wave (proposed) | (fixed state), not realized—see Section VII-H |
| Configuration | Layer 1 | Layer 2 | Layer 3 | Layer 4 | Parameters |
|---|---|---|---|---|---|
| Pure Transformer | Attention | Attention | Attention | Attention | 10.94M |
| Pure Wave | Wave | Wave | Wave | Wave | 10.94M |
| Hybrid Wave-Attention | Wave | Wave | Attention | Attention | 10.94M |
| Model | PPL | Latency, reference impl. (ms) | Latency @512 | Activation memory @512 (MB) | |||
|---|---|---|---|---|---|---|---|
| (quick) | 128 | 256 | 512 | optimized (ms) | full model | mixer only | |
| Pure Transformer | 6.75 | 15.8 | 32.8 | 72.6 | 63.3 | 324.5 | 265.0 |
| Pure Wave | 7.05 | 46.1 | 89.2 | 180.2 | 71.2 | 324.5 | 120.0 |
| Hybrid Wave-Attention | 5.79 | 24.1 | 50.0 | 114.2 | 67.3 | 324.5 | 265.0 |
| Model | Avg. Cross-Entropy Loss | Perplexity |
|---|---|---|
| Pure Transformer | 1.9357 | 6.93 |
| Pure Wave | 1.9818 | 7.26 |
| Hybrid Wave-Attention | 1.7831 | 5.95 |
| Model | Unfused attention | Fused attention | ||||
|---|---|---|---|---|---|---|
| 1024 | 2048 | 4096 | 1024 | 2048 | 4096 | |
| Pure Transformer | 565.4 | 1801.5 | 6601.6 | 429.9 | 755.5 | 1403.6 |
| Pure Wave | 430.6 | 756.2 | 1404.3 | 430.6 | 756.2 | 1404.3 |
| Hybrid Wave-Attention | 566.3 | 1802.3 | 6602.5 | 430.8 | 756.3 | 1404.5 |
| Configuration | Predicted | Measured | Error | ||
|---|---|---|---|---|---|
| Wave, with head | 16 | 512 | 324.5 | 324.5 | |
| Wave, with head | 8 | 1024 | 324.5 | 324.5 | |
| Wave, with head | 8 | 2048 | 649.0 | 650.0 | |
| Wave, with head | 8 | 4096 | 1298.0 | 1298.0 | |
| Fused attn., with head | 8 | 4096 | 1298.0 | 1298.0 | |
| Fused attn., mixer only | 8 | 4096 | 480.0 | 480.0 |
| Model | Unfused attention | Fused attention |
|---|---|---|
| Pure Transformer | 789.2 | 573.6 |
| Pure Wave | 621.2 | 621.2 |
| Hybrid Wave-Attention | 705.2 | 597.4 |
| Model | Bounded window, 100 tok (tok/s) | Unbounded context, 1500 tok (tok/s) | Slowdown |
|---|---|---|---|
| Pure Transformer | 526.22 | 102.31 | 5.1 |
| Pure Wave | 49.55 | 3.96 | 12.5 |
| Hybrid Wave-Attention | 80.25 | 7.75 | 10.3 |
| Model | Training time (min) | torch.compile |
|---|---|---|
| Pure Transformer | 18.36 | Yes |
| Pure Wave | 328.27 | No |
| Hybrid Wave-Attention | 174.99 | No |