AI Infra
0%
Part I · Chapter 9

Beyond Dense Transformers: MoE, SSMs, Hybrids

AuthorChangkun Ou
Reading time~29 min

Chapter 8 described a causal decoder with two dense sublayers: attention mixes positions, and a feed-forward network (FFN) transforms each position. This chapter varies those two sublayers along independent axes.

A mixture-of-experts (MoE) FFN stores many expert networks but evaluates only a selected subset for each token. It changes parameter activation; it does not make attention sparse. A state-space or linear-recurrent layer changes how the sequence is mixed and what state is retained during decoding; it does not by itself add expert routing. A hybrid can use either change, or both, in one stack. Keeping the axes separate prevents three quantities from being confused: stored parameters, arithmetic executed for one token, and state retained for one sequence.

Two independent architecture axes

For a dense Transformer block, every token evaluates the same FFN weights, and every attention layer retains keys and values for every cached position. That is a specific design, not a definition of a language model. Alternatives ask two different questions:

Axis Dense choice Alternative Resource primarily changed
FFN parameter activation Evaluate one dense FFN Route each token through a few experts Stored parameters relative to expert-path arithmetic
Sequence mixing Attend to cached positions Update a recurrent state Work and persistent state as context grows

These substitutions introduce new costs. MoE routing creates dispatch, imbalance, and communication. A recurrence compresses history into a state whose width is fixed by the architecture, so past positions are no longer individually represented in a growing key-value cache. The relevant comparison is therefore a workload-level one: quality, training arithmetic, memory, communication, batch shape, and serving latency all count.

MoE routes tokens through conditional FFNs

Sparse expert models predate Transformers. Shazeer et al. introduced a sparsely gated MoE layer at large scale in 2017 inside recurrent language models (Shazeer et al. 2017). GShard then combined conditional experts with Transformer models and automatic sharding (Lepikhin et al. 2020), while Switch Transformer studied top-1 routing and trillion-parameter models (Fedus et al. 2022). The durable idea is narrower than the surrounding scale claims: store more expert weights than one token evaluates.

Routing is a defined mathematical operation

In one common top-kk formulation, used by Mixtral, the first two terms score and select experts (Jiang et al. 2024):

zt=Wrht,St=TopK(zt,k).z_t=W_rh_t, \qquad \mathcal{S}_t=\operatorname{TopK}(z_t,k).

The normalized gate for each selected expert is

gt,e={exp(zt,e)jStexp(zt,j),eSt,0,eSt,g_{t,e}= \begin{cases} \dfrac{\exp(z_{t,e})} {\sum_{j\in\mathcal{S}_t}\exp(z_{t,j})}, & e\in\mathcal{S}_t,\\[6pt] 0, & e\notin\mathcal{S}_t, \end{cases}

Each selected expert then contributes to the output:

mt=e=1Egt,eFe(ht).m_t=\sum_{e=1}^{E}g_{t,e}F_e(h_t).

Here htRdh_t\in\mathbb{R}^{d} is the hidden vector at token position tt; EE is the number of routed experts; WrRE×dW_r\in\mathbb{R}^{E\times d} is the router matrix; zt,ez_{t,e} is expert ee's routing logit; St\mathcal{S}_t is the set of kk selected expert indices; gt,eg_{t,e} is the selected expert's normalized gate weight; Fe:RdRdF_e:\mathbb{R}^{d}\rightarrow\mathbb{R}^{d} is expert ee; and mtRdm_t\in\mathbb{R}^{d} is the MoE output. A residual connection and any shared expert are outside this equation.

This is one router contract, not a universal definition. Switch uses top-1 routing; some systems apply softmax before selection, some after it, and some use sigmoid affinities. The gate value may or may not be renormalized after top-kk. These choices change gradients and checkpoint semantics, so a model description must state them.

moe h token state h_t r router W_r E scores h->r shared optional shared expert (always evaluated) h->shared k top-2 selection r->k e1 routed expert i k->e1 g_i e2 routed expert j k->e2 g_j idle other experts not evaluated k->idle mix g_i F_i(h_t) + g_j F_j(h_t) e1->mix e2->mix out MoE output mix->out shared->out add
Figure 9.1. One top-2 MoE path. The router scores all routed experts, selects two, and combines their FFN outputs with gate weights. An optional shared expert is evaluated separately and added without a routed gate.

Stored parameters, selected weights, and runtime are different

Suppose every expert is a bias-free SwiGLU FFN with model width dd and expert hidden width dfd_f. From Chapter 8, one expert contains approximately

Pe=3ddfP_e=3dd_f

parameters, where PeP_e counts the gate, value, and down projections; dd is the input and output width; and dfd_f is the expert's intermediate width. With EE routed experts and no shared expert, the layer stores and evaluates

Pstored=EPe+Ed,Pevaluated(t)=kPe+Ed.P_{\mathrm{stored}}=EP_e+Ed, \qquad P_{\mathrm{evaluated}}(t)=kP_e+Ed.

Here EdEd is the router matrix, whose EE scores are all evaluated for token tt; EPeEP_e counts every stored expert; and kPekP_e counts only the selected expert weights. Biases and always-on block parameters are omitted. Reported "active parameter" counts often include additional embeddings, attention, normalization, and shared experts, so the reporting convention must be stated.

Figure 9.2 evaluates these equations for d=4096d=4096, df=14336d_f=14336, and k=2k=2. The selected-expert term stays fixed as EE grows, but the router term grows, and neither line measures wall-clock time. Runtime also depends on token dispatch, padding or ragged kernels, all-to-all communication, memory traffic, and the slowest expert shard.

2026-08-03T21:31:41.827069 image/svg+xml Matplotlib v3.11.0, https://matplotlib.org/ 10 20 30 40 50 60 Routed experts E (k = 2 selected) 0 2 4 6 8 10 Parameters in one MoE layer (billions) Stored parameters Parameters evaluated per token
Figure 9.2. Stored versus evaluated parameter values for one bias-free SwiGLU MoE layer with model width 4096, expert width 14336, and top-2 routing. Stored parameters include every expert and the router. Evaluated parameters include two experts and all router scores. Attention and other always-on weights are excluded.

The runnable cell prints the same accounting without requiring plotting libraries. Change EE, kk, or either width to inspect another layer.

model_width = 4096
expert_width = 14_336
selected_experts = 2

def moe_parameter_counts(experts):
    if not 1 <= selected_experts <= experts:
        raise ValueError("selected_experts must be between 1 and experts")
    per_expert = 3 * model_width * expert_width  # bias-free SwiGLU
    router = experts * model_width
    stored = experts * per_expert + router
    evaluated = selected_experts * per_expert + router
    return stored, evaluated

for experts in (8, 16, 32, 64):
    stored, evaluated = moe_parameter_counts(experts)
    print(
        f"E={experts:2d}, k={selected_experts}: "
        f"stored={stored / 1e9:.3f}B, "
        f"evaluated/token={evaluated / 1e9:.3f}B, "
        f"ratio={stored / evaluated:.2f}x"
    )

Routing creates a dispatch problem

Expert weights are commonly partitioned across an expert-parallel group. A forward pass then has four stages: compute router scores, group token copies by destination expert, exchange those copies to the expert owners, and return the expert outputs to their original token order. Implementations often use one all-to-all collective for dispatch and another for the return path, but an all-to-all is not intrinsic when all experts are local or the placement differs.

The arithmetic saved inside expert FFNs can therefore be replaced by network time or small, poorly utilized matrix multiplications. Useful measurements include bytes dispatched, tokens per expert, padded versus useful expert slots, collective time, overlap with computation, and tail latency. "Active parameters" alone proves none of these.

For a routing group with TT tokens, EE experts, and kk assignments per token, the even-share load is kT/EkT/E assignments per expert. A fixed-capacity implementation may reserve

Ce=ckTEC_e=\left\lceil c\frac{kT}{E}\right\rceil

slots per expert, where c>0c>0 is the capacity factor; CeC_e is the assignment capacity of expert ee; TT is the number of tokens in the routing group; kTkT is the total number of routed assignments; and EE is the expert count. An overflow policy may skip, reroute, or defer assignments. Switch's published formula is the k=1k=1 case (Fedus et al. 2022). Other systems use dropless ragged or block-sparse execution instead of a fixed cap (Gale et al. 2023).

Figure 9.3. A toy top-2 dispatcher with six experts. Balanced mode spreads assignments; collapsed mode concentrates them. The dashed line is a fixed capacity factor times the current even-share assignment count. Assignments above that illustrative limit are marked dropped. Production routers and dropless kernels can use different policies.

Balance losses change optimization, not just utilization

Unregularized routing can concentrate assignments, under-train some experts, and make overloaded expert ranks into stragglers. Shazeer et al. used separate importance and load objectives (Shazeer et al. 2017). Switch introduced a simpler top-1 auxiliary loss

Lbal=αEe=1Efeqe,fe=1Tt=1T1 ⁣[argmaxjpt,j=e],qe=1Tt=1Tpt,e.\mathcal{L}_{\mathrm{bal}} =\alpha E\sum_{e=1}^{E}f_eq_e, \qquad f_e=\frac{1}{T}\sum_{t=1}^{T} \mathbf{1}\!\left[\arg\max_j p_{t,j}=e\right], \qquad q_e=\frac{1}{T}\sum_{t=1}^{T}p_{t,e}.

Here pt=softmax(zt)p_t=\operatorname{softmax}(z_t) is the full router distribution for token tt; fef_e is the realized fraction of tokens sent to expert ee; qeq_e is its mean router probability; TT is the routing-group token count; EE is the expert count; α0\alpha\ge0 is the loss coefficient; and 1[]\mathbf{1}[\cdot] is an indicator. The product penalizes jointly large traffic and probability mass. Top-kk systems use related but not identical definitions.

The coefficient is a real optimization choice: too little balance can create poor utilization, while too much pressure can override task-driven routing. DeepSeek-V3 primarily steers top-kk selection with per-expert biases that are adjusted from recent load, while retaining a small sequence-wise auxiliary loss to prevent extreme imbalance (DeepSeek-AI 2024; Wang et al. 2024). The bias affects selection, not the gate weight used to combine expert outputs. This is more precise than saying the model removed all balancing losses.

ST-MoE also introduced a router z-loss (Zoph et al. 2022):

Lz=βTt=1T(loge=1Eexpzt,e)2.\mathcal{L}_{z} =\frac{\beta}{T}\sum_{t=1}^{T} \left(\log\sum_{e=1}^{E}\exp z_{t,e}\right)^2.

Here zt,ez_{t,e} is the router logit defined earlier; the log-sum-exp term is the router log-partition for token tt; TT and EE retain their earlier meanings; and β0\beta\ge0 controls the penalty. Switch also reported selectively using float32 for router computations inside a bfloat16 model (Fedus et al. 2022). Those are experiment-backed stabilizers, not proof that hard top-kk selection or low precision is the sole cause of every MoE failure.

Refinements solve different routing problems

Several named designs are alternatives, not a single progression toward one default:

  • Top-1 and top-kk. Switch evaluates one expert; Mixtral evaluates two. Increasing kk raises expert arithmetic and communication, approaching dense expert evaluation only as kk approaches EE.
  • Expert-choice and balanced assignment. Expert Choice gives each expert a fixed token bucket, eliminating expert-side overflow but giving tokens a variable number of selected experts, possibly zero (Zhou et al. 2022). BASE Layers instead formulate routing as a balanced assignment problem (Lewis et al. 2021).
  • Fine-grained and shared experts. DeepSeekMoE divides expert capacity into smaller routed experts and adds always-evaluated shared experts (Dai et al. 2024). In that construction, shared outputs are added without a routed gate. The paper reports improved specialization in its experiments; the label "shared" does not guarantee that a network has learned only general knowledge.
  • Sparse upcycling. A dense FFN can be copied into several experts, followed by continued training with a new router (Komatsuzaki et al. 2023). This changes initialization cost, not the eventual dispatch and serving contract.

GLaM and Mixtral demonstrate other points in the design space (Du et al. 2022; Jiang et al. 2024). Their results do not establish a universal best expert count, kk, capacity factor, or routing loss. Those values depend on the training budget, batch shape, topology, memory, kernels, and target latency.

State-space layers replace a growing history with a recurrence

The second axis concerns sequence mixing. State-space models (SSMs) originate in dynamical-systems and control formulations, long before their use in neural sequence models. S4 showed in 2022 that a structured linear state-space layer could model long sequences efficiently (Gu et al. 2022). Mamba then made key parts of the recurrence input-dependent and supplied a hardware-aware selective scan (Gu and Dao 2024).

From a continuous system to a discrete layer

A linear time-invariant state-space system is

dh(t)dt=Ah(t)+Bx(t),y(t)=Ch(t)+Dskipx(t).\frac{dh(t)}{dt}=Ah(t)+Bx(t), \qquad y(t)=Ch(t)+D_{\mathrm{skip}}x(t).

Here continuous time is tt; x(t)Rdinx(t)\in\mathbb{R}^{d_{in}} is the input; h(t)Rnh(t)\in\mathbb{R}^{n} is the state; y(t)Rdouty(t)\in\mathbb{R}^{d_{out}} is the output; ARn×nA\in\mathbb{R}^{n\times n} is the state transition; BRn×dinB\in\mathbb{R}^{n\times d_{in}} writes the input into state; CRdout×nC\in\mathbb{R}^{d_{out}\times n} reads the state; and DskipRdout×dinD_{\mathrm{skip}}\in\mathbb{R}^{d_{out}\times d_{in}} is a direct input path. The dimensions dind_{in}, nn, and doutd_{out} are fixed by the layer.

After discretization at a fixed step, the same layer can be written

ht=Aˉht1+Bˉxt,yt=Cht+Dskipxt.h_t=\bar A h_{t-1}+\bar Bx_t, \qquad y_t=Ch_t+D_{\mathrm{skip}}x_t.

Here integer tt is a token position; xtx_t, hth_t, and yty_t are the sampled input, state, and output; and Aˉ\bar A and Bˉ\bar B are the discretized transition and input matrices. They are not the continuous matrices AA and BB, even when an implementation derives them from those parameters.

Fixed coefficients give recurrence-convolution equivalence

With h0=0h_0=0 and fixed Aˉ\bar A, Bˉ\bar B, and CC, the terms in the unrolled recurrence are

Ki=CAˉiBˉ,yt=j=1tKtjxj+Dskipxt.K_i=C\bar A^{i}\bar B, \qquad y_t=\sum_{j=1}^{t}K_{t-j}x_j+D_{\mathrm{skip}}x_t.

Here i0i\ge0 is a lag; KiRdout×dinK_i\in\mathbb{R}^{d_{out}\times d_{in}} is the convolution kernel at that lag; Aˉi\bar A^i is the ii-th matrix power; jj is an earlier token position; and all other symbols retain their definitions above. The recurrent and convolutional views compute the same linear operator. S4 exploits structure in AA to generate and apply long kernels efficiently; its theoretical filter-generation and FFT costs should not be collapsed into a blanket claim that every SSM implementation is simply O(S)O(S).

Mamba makes the recurrence selective

For one simplified Mamba channel, the token-dependent terms produced by the selection mechanism are

(Δt,Bt,Ct)=sθ(xt),Aˉt=exp(ΔtA),Bˉt=0Δtexp ⁣((Δtτ)A)Btdτ,(\Delta_t,B_t,C_t)=s_\theta(x_t), \qquad \bar A_t=\exp(\Delta_tA), \qquad \bar B_t= \int_{0}^{\Delta_t}\exp\!\bigl((\Delta_t-\tau)A\bigr)B_t\,d\tau,

These terms define the discrete recurrence:

ht=Aˉtht1+Bˉtxt,yt=Ctht+Dskipxt.h_t=\bar A_th_{t-1}+\bar B_tx_t, \qquad y_t=C_th_t+D_{\mathrm{skip}}x_t.

Here sθs_\theta is a learned projection with parameters θ\theta; Δt>0\Delta_t>0 is an input-dependent discretization step; BtB_t and CtC_t are input-dependent write and read maps; AA remains a learned but input-independent continuous transition; exp\exp is the matrix exponential; τ\tau is the integration variable; and Aˉt\bar A_t and Bˉt\bar B_t are the token-dependent discrete maps. Production Mamba layers batch many channels and use structured parameterizations, but the distinction is the same: Δt\Delta_t, BtB_t, and CtC_t are selective; continuous AA is not (Gu and Dao 2024).

Input dependence removes the single stationary convolution kernel KK from the previous section. Mamba recovers parallel training through a fused associative scan over affine recurrence updates, then uses the recurrent form for autoregressive decoding. Mamba-2 relates a restricted class of SSM transitions to semiseparable mixing matrices and uses chunked matrix multiplication; its paper reports a 2 to 8 times faster core layer than Mamba's selective scan in the tested settings (Dao and Gu 2024). That is a measured result under those implementations, not an architecture-independent speed ratio.

Linear attention is another fixed-state route

Kernelized causal attention can also reorder its computation into a recurrent state. A simplified gated form is

St=λtSt1+ϕ(kt)vt,zt=λtzt1+ϕ(kt),yt=ϕ(qt)Stϕ(qt)zt+ε.S_t=\lambda_tS_{t-1}+\phi(k_t)v_t^{\top}, \qquad z_t=\lambda_tz_{t-1}+\phi(k_t), \qquad y_t=\frac{\phi(q_t)^{\top}S_t} {\phi(q_t)^{\top}z_t+\varepsilon}.

Here qtq_t, ktk_t, and vtv_t are query, key, and value vectors; ϕ\phi is a feature map that makes the kernel factorable; StS_t is a fixed-shape key-value summary matrix; ztz_t is its normalizer state; λt[0,1]\lambda_t\in[0,1] is an optional learned forgetting gate; ε>0\varepsilon>0 prevents division by zero; and yty_t is the output. The associative factorization, not merely removing softmax, eliminates the need to form every query-key pair. Gated DeltaNet adds targeted delta-rule updates to this family (Yang et al. 2025).

Linear sequence scaling is not automatic speed

With model dimensions fixed, dense full-sequence attention forms a number of query-key relationships proportional to S2S^2, while a recurrent scan performs a number of state updates proportional to SS. Figure 9.4 plots only that sequence-length growth, normalized at 1,000 tokens. It does not plot FLOPs or measured runtime; projection width, state size, kernel fusion, memory traffic, and hardware determine the constants.

2026-08-03T21:24:58.265881 image/svg+xml Matplotlib v3.11.0, https://matplotlib.org/ 1 2 4 8 16 32 64 128 Context length (thousands of tokens) 1 0 0 1 0 1 1 0 2 1 0 3 1 0 4 Growth relative to 1K tokens Attention relationships (quadratic) Recurrent updates (linear)
Figure 9.4. Growth of the dominant sequence-length term, normalized at a 1,000-token context. Dense attention relationships grow quadratically with context length; recurrent state updates grow linearly when model dimensions are fixed. The curves are asymptotic accounting, not a runtime benchmark.

During decode, one dense attention layer compares a new query with a retained key for each cached position. A recurrent layer instead updates a state whose shape is independent of context length. "Independent of context length" does not mean small or free. In the original Mamba implementation, a useful approximation for persistent decode state is

Mrec=BbatchLrecdinner(nstate+dconv)bbytes.M_{\mathrm{rec}} =B_{\mathrm{batch}}L_{\mathrm{rec}}d_{\mathrm{inner}} \bigl(n_{\mathrm{state}}+d_{\mathrm{conv}}\bigr)b \quad\text{bytes}.

Here BbatchB_{\mathrm{batch}} is the number of resident sequences; LrecL_{\mathrm{rec}} is the number of recurrent layers; dinnerd_{\mathrm{inner}} is the number of recurrent channels; nstaten_{\mathrm{state}} is the SSM state width per channel; dconvd_{\mathrm{conv}} is the short-convolution buffer length; and bb is bytes per stored element. Exact layouts vary by implementation. The state scales with batch, layers, channel width, state width, convolution width, and precision, but not with cached context length.

Figure 9.5. Persistent decode-state shape as sequence length changes. An attention layer retains one key-value record per cached position. A recurrent layer keeps a fixed number of state slots chosen by its architecture. This figure compares storage structure only; it makes no claim that attention retrieves perfectly or that every recurrent model forgets distant tokens at a fixed rate.

The trade is representational. Attention retains a separate cached representation for each past position and permits direct content-based access. A recurrent layer repeatedly compresses prior information into a fixed-shape state, so information can interfere or be lost. Neither mechanism guarantees recall. Retrieval quality must be measured on the target distribution, at the target length, after matched training.

Hybrids choose a layer schedule

MoE and recurrent sequence mixing compose because they occupy different block slots. A hybrid may use attention in some layers, a recurrence in others, and either dense or expert FFNs after each mixer. There is no required ratio.

hybrid x input residual stream r1 recurrent mixer 1 x->r1 f1 MoE FFN 1 r1->f1 r2 recurrent mixer 2 f1->r2 f2 MoE FFN 2 r2->f2 r3 recurrent mixer 3 f2->r3 f3 MoE FFN 3 r3->f3 a causal attention mixer f3->a f4 MoE FFN 4 a->f4 y next residual group f4->y
Figure 9.6. An illustrative 3:1 hybrid cycle. Three recurrent mixers and one attention mixer each feed an MoE FFN. The mixer schedule and FFN choice are independent configuration fields, not a universal block order.

Released models illustrate different schedules and reporting conventions:

Model Sequence mixers FFN sparsity Scope of the reported evidence
Jamba One attention layer per seven Mamba layers in its main configuration 16 experts, top-2 in selected layers The authors report stronger throughput and lower KV memory than named baselines under specified hardware and context settings (Lieber et al. 2024)
MiniMax-01 Seven Lightning Attention blocks per softmax-attention block 32 experts, top-2; 456B total and 45.9B activated The report trained to 1M-token contexts and evaluated extrapolation to 4M (MiniMax 2025)
Qwen3-Next-80B-A3B Twelve repetitions of three Gated DeltaNet layers and one gated-attention layer 512 routed experts, 10 selected, plus one shared expert The official card reports 80B total, 3B activated, and a native 262,144-token context (Qwen Team 2025)
Nemotron-H Mamba-2, attention, and dense FFN layers Dense FFNs The authors report 8B, 56B, and distilled 47B variants, with throughput comparisons scoped to their benchmark setup (NVIDIA 2025)

These examples prove that the components can be trained and implemented at large scale. They do not prove that a hybrid dominates full attention on every quality measure or serving workload. MiniMax later chose full attention for M2 and reported that hybrid weaknesses appeared on complex multi-hop tasks at larger scale, while low-precision state, prefix caching, speculative decoding, kernel maturity, and evaluation remained practical concerns (Sun 2025). That first-party retrospective is one team's evidence, not a universal verdict against recurrent or hybrid models.

What's contested

The open question is not whether subquadratic mixers can run. It is where their quality, state capacity, and implementation costs cross the full-attention baseline for a particular workload. Small or saturated benchmarks can hide retrieval and multi-step reasoning deficits; theoretical linear work can still be memory-bound; and an attention-heavy software stack may erase an architecture's nominal advantage. Comparisons need matched data, tokens, parameters, training compute, kernels, hardware, context lengths, and serving features.

Constraint arrow

Architecture now fixes two contracts for Chapter 10. MoE fixes expert placement, dispatch volume, and load imbalance across the device topology. Recurrent and hybrid mixers fix scan kernels, state precision, and which layers still allocate a KV cache. Those choices then constrain batching, prefix reuse, speculative decoding, and memory scheduling in Chapter 31. An asymptotic saving is useful only if the distributed and serving implementations can realize it.

Record sparse and recurrent architecture as a contract

A reproducible architecture description should name at least:

  • which layers use attention, an SSM, linear attention, or another mixer;
  • every attention mask, head layout, position rule, and KV-cache data type;
  • recurrent state shapes, discretization or gate parameterization, convolution width, reset semantics, and state precision;
  • expert count, shared-expert count, selected routed experts, expert FFN shapes, and which layers are sparse;
  • router scoring, normalization, top-kk tie-breaking, gate renormalization, and output-combination rule;
  • balance and z-loss equations with coefficients, plus any bias-update rule;
  • routing-group size, capacity factor, overflow or dropless policy, and token ordering after combine;
  • expert placement, expert-parallel group, dispatch collective, router precision, and reported total/activated-parameter convention.

Names such as "MoE," "Mamba hybrid," or "80B-A3B" leave most of this contract undefined. Checkpoint tensors, training code, inference kernels, and model cards must agree on it.

Validate each axis before scaling

  1. Check parameter accounting. Reconcile stored, selected, shared, router, and always-on parameters with the serialized checkpoint.
  2. Test routing exactly. On a small batch, compare sharded dispatch and combine with a single-device reference, including ties, overflow, padding, and zero-token experts.
  3. Measure the load distribution. Report assignments per expert, imbalance, dropped or rerouted assignments, padding, entropy, and the slowest expert rank over training and evaluation data.
  4. Measure communication. Record dispatch and combine bytes, collective time, compute overlap, and end-to-end tokens per second at realistic batch sizes.
  5. Compare scan and recurrence. Confirm the parallel training path and token-by-token recurrent path agree within declared numerical tolerances.
  6. Test state boundaries. Reset state at document and sequence boundaries; test packed samples, prefix reuse, state copying, and speculative rollback.
  7. Stress retrieval and state tracking. Evaluate direct lookup, order, repeated keys, distractors, and multi-hop use across the deployed length, rather than relying on one needle test.
  8. Benchmark the complete workload. Compare quality, training throughput, prefill, decode, memory, batch capacity, and failure recovery against dense and attention-only baselines under matched budgets.

MoE and recurrent layers each remove one dense assumption, but neither removes resource accounting. The useful abstraction is a contract: which weights a token evaluates, where those weights live, how sequence state evolves, and which costs move into communication or serving.

Further reading

  • Shazeer et al., “Outrageously Large Neural Networks: The Sparsely-Gated Mixture-of-Experts Layer” (Origin of top-k gating and the auxiliary balancing loss), 2017. arXiv:1701.06538
    This paper introduces a Sparsely-Gated MoE layer with up to thousands of feed-forward experts and a trainable gating network, achieving over 1000x model capacity gains with minor computational overhead on language modeling and translation tasks.
  • Lepikhin et al., “GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding,” 2021. arXiv:2006.16668
    GShard introduces lightweight annotation APIs and an XLA compiler extension enabling automatic SPMD sharding of a 600B-parameter MoE Transformer trained on 2048 TPU v3 devices for multilingual translation across 100 languages.
  • Fedus et al., “Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity” (Top-1 routing at trillion-param scale), 2022. arXiv:2101.03961
    Switch Transformer simplifies MoE routing to a single expert per token, enabling trillion-parameter sparse models that achieve up to 7x pre-training speedup over T5 at equal FLOPs.
  • Du et al., “GLaM: Efficient Scaling of Language Models with Mixture-of-Experts,” 2022. arXiv:2112.06905
    GLaM scales a decoder-only language model to 1.2T parameters via sparsely activated MoE, matching or exceeding GPT-3 on 29 NLP tasks while using one-third the training energy.
  • Zhou et al., “Mixture-of-Experts with Expert Choice Routing” (Balance by construction), 2022. arXiv:2202.09368
    Expert Choice MoE proposes letting each expert select its top-k tokens instead of each token choosing experts, guaranteeing perfect load balancing and achieving over 2x faster training convergence than Switch Transformer and GShard.
  • Zoph et al., “ST-MoE: Designing Stable and Transferable Sparse Expert Models” (Router z-loss, stability), 2022. arXiv:2202.08906
    ST-MoE-32B is a 269B sparse MoE model that resolves MoE training instability and fine-tuning transfer gaps, achieving state-of-the-art results across diverse NLP benchmarks.
  • Komatsuzaki et al., “Sparse Upcycling: Training Mixture-of-Experts from Dense Checkpoints,” 2023. arXiv:2212.05055
    Sparse upcycling initializes a MoE model from a pretrained dense checkpoint, outperforming both dense continuation and MoE training from scratch at roughly 50% of the original pretraining cost.
  • Jiang et al., “Mixtral of Experts,” 2024. arXiv:2401.04088
    Mixtral 8x7B is a sparse MoE decoder-only model with 46.7B total parameters that activates only 12.9B per token, outperforming Llama 2 70B with 6x faster inference under an Apache 2.0 license.
  • Dai et al., “DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language Models” (Fine-grained + shared experts), 2024. arXiv:2401.06066
    DeepSeekMoE proposes fine-grained expert segmentation and shared expert isolation in MoE language models to achieve stronger expert specialization, matching dense model performance with far less computation.
  • DeepSeek-AI, “DeepSeek-V3 Technical Report” (Auxiliary-loss-free (bias-based) load balancing at scale), 2024. arXiv:2412.19437
    Reports DeepSeek-V3, a 671B-parameter Mixture-of-Experts model with 37B active per token, trained on 14.8T tokens with fp8 matmuls and auxiliary-loss-free load balancing, rivaling closed models at low cost.
  • Lewis et al., “BASE Layers: Simplifying Training of Large, Sparse Models” (Routing as assignment, for contrast), 2021. arXiv:2103.16716
    BASE layers replace MoE routing heuristics and auxiliary balancing losses by formulating token-to-expert assignment as a linear assignment problem, guaranteeing equal load across experts with no new hyperparameters.
  • Wang et al., “Auxiliary-Loss-Free Load Balancing Strategy for Mixture-of-Experts” (The standalone loss-free balancing method, distinct from the DeepSeek-V3 report), 2024. arXiv:2408.15664
    Loss-Free Balancing maintains balanced expert load in MoE models by dynamically updating per-expert routing biases, eliminating auxiliary-loss interference gradients and improving model performance.
  • Gu et al., “Efficiently Modeling Long Sequences with Structured State Spaces” (S4), 2022. arXiv:2111.00396
    S4 uses a structured state matrix to make long state-space convolution kernels practical, with near-linear filter generation and strong results on long-range sequence benchmarks.
  • Gu & Dao, “Mamba: Linear-Time Sequence Modeling with Selective State Spaces,” 2024. arXiv:2312.00752
    Mamba introduces selective SSMs with input-dependent parameters and a hardware-aware parallel scan, achieving Transformer-quality language modeling with linear-time inference and training.
  • Dao & Gu, “Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality” (Mamba-2), 2024. arXiv:2405.21060
    Mamba-2 unifies selective SSMs and attention via a structured state space duality (SSD) framework over semiseparable matrices, yielding a 2-8x faster SSM layer competitive with Transformers on language modeling.
  • Yang et al., “Gated Delta Networks: Improving Mamba2 with Delta Rule” (Gated DeltaNet), 2025. arXiv:2412.06464
    Gated DeltaNet combines a gated forgetting mechanism with delta-rule state updates in a linear-attention recurrence, surpassing Mamba2 and DeltaNet on language modeling and long-context tasks.
  • Lieber et al., “Jamba: A Hybrid Transformer-Mamba Language Model,” 2024. arXiv:2403.19887
    Jamba interleaves attention and Mamba layers with MoE; under the paper's stated hardware and context settings, it reports lower KV-cache memory and up to three times Mixtral's throughput.
  • MiniMax, “MiniMax-01: Scaling Foundation Models with Lightning Attention” (456B lightning-attention hybrid), 2025. arXiv:2501.08313
    MiniMax-01 interleaves Lightning Attention with softmax attention in a 456B-total, 45.9B-activated MoE model trained at one-million-token context and evaluated with extrapolation to four million tokens.
  • Qwen Team, “Qwen3-Next-80B-A3B-Instruct Model Card” (Gated DeltaNet and gated attention at roughly 3:1), 2025. huggingface.co
    Qwen3-Next is an 80B-total, 3B-active MoE model whose 48 layers alternate three Gated DeltaNet linear-attention layers with one gated full-attention layer.
  • NVIDIA, “Nemotron-H: A Family of Accurate and Efficient Hybrid Mamba-Transformer Models” (Mamba-attention hybrids at 8B and 56B), 2025. arXiv:2504.03624
    Nemotron-H combines Mamba-2, attention, and dense FFN layers in 8B and 56B models; the paper reports competitive task accuracy and up to three-times throughput in specified long-context H100 comparisons.
  • Sun, “Why Did M2 End Up as a Full Attention Model?” (a frontier lab's case for reverting to full attention), 2025. minimax.io
    MiniMax's pre-training lead explains why M2 dropped the hybrid lightning-attention design: hybrid deficits surfaced only at scale on multi-hop reasoning, and the inference and evaluation stack around efficient attention is not yet production-mature.

Comments

Log in to comment