Yes, people have tried “pure” hard-routing—i.e. pick a Top-K set of experts with a discrete arg-max/arg-top-k and then let gradients flow through that choice by using a straight-through estimator (STE). But in large-scale MoE models almost everybody ended up backing away from this and instead uses the now-standard “Top-K with soft weights” trick (Switch, GShard, Mixtral, etc.).
Below is a quick recap of what exists and why the community converged on the current practice.
────────────────────────────────────────
1 What a true STE Top-K gate looks like
────────────────────────────────────────
logits = W x (E experts)
indices = topk(logits, K) (hard choice)
onehot = zeros_like(logits); onehot[indices]=1
output = Σ_e onehot[e] · Expert_e(x) (hard mask)
Back-prop:
∂L/∂logits := ∂L/∂onehot (identity STE) (no softmax)
The whole forward path is piece-wise constant; the gradient of the gate is simply “passed through” as if the arg-max were the identity.
Papers that tried it
• Hard Mixture-of-Experts for Speech (Yan et al., Interspeech 2014)
• Conditional Computation for NN (Bengio et al., 2013)
• Hard MoE with STE (Wang et al., ICLR 2020 poster)
• Several student projects / repos: “ST-MoE,” “hard-routing-MoE,” etc.
────────────────────────────────────────
2 The hybrid that won: Top-K soft mask
────────────────────────────────────────
Most modern MoE routers do
s = softmax(logits) (continuous)
indices = topk(s, K) (hard choice)
mask = 0; mask[indices] = s[indices] (keep weights)
output = Σ_e mask[e] · Expert_e(x)
During back-prop the gradient of output w.r.t. logits flows through
the softmax (for the chosen experts) but not through the Top-K op.
This is effectively an STE on the arg-max part, but it keeps a usable
Jacobian thanks to the soft weights.
────────────────────────────────────────
3 Why pure STE Top-K is rarely used
────────────────────────────────────────
| Reason | What goes wrong |
|---|
| Dead experts | Non-selected experts get zero gradient → never improve → router never sends them tokens → collapse. |
| High-variance / biased gradients | STE ignores how the selection boundary moves; optimisation becomes noisy, especially when K≪E. Training is unstable or diverges. |
| Load-balancing tough | Because unused experts get no signal, you have to fall back on REINFORCE-style baselines or entropy regularisers, which add even more noise. |
| Router “flip-flop” | A tiny update in logits can suddenly reroute thousands of tokens → loss spikes, making large-batch training delicate. |
| Hardware utilisation | Instability in routing pattern hurts batching/fusion; soft-mask gates give a smoother evolution, so you can keep static kernels and memory layouts. |
Empirically, all of the above show up much earlier (and more severely) once you scale to
• many experts (E≥64),
• long sequences,
• data-parallel + expert-parallel sharding.
────────────────────────────────────────
4 What people use instead
────────────────────────────────────────
| Variant | Still discrete? | Smooth gradient? |
|---|
| Top-K soft mask (Switch, etc) | Yes | Via softmax on kept experts |
| Gumbel-Softmax / Gumbel Top-K | Sampled hard | Reparameterised, differentiable expectation |
| Sinkhorn / Optimal Transport | Fully soft | Yes |
| SoftMoE (Riquelme 2023) | No hard step | Yes, 100 % differentiable |
These methods keep most of the efficiency (tokens still hit ≤K experts) while giving the router a low-variance signal and letting us add an auxiliary load-balancing loss (usually ∑_e q_e · p_e from Shazeer 2017).
────────────────────────────────────────
5 Bottom line
────────────────────────────────────────
• “Hard Top-K with straight-through” definitely exists, but you’ll almost never see it in modern large-scale MoEs because it collapses experts and destabilises training.
• The de-facto standard is “Top-K with soft weights + auxiliary balance loss,” which can be viewed as a partial STE (the non-differentiable selection is kept, but the softmax provides gradients for the chosen experts and the aux-loss keeps everyone alive).
• If you really need fully hard, you can add Gumbel-Softmax or REINFORCE, but expect slower convergence and lots of tuning.