Skip to content

AI Engineer Interview Drill — 2026-12-01: Deep Learning & NLP

Dec 1, 202611 min
TL;DRA MoE router picks experts with top-k plus softmax; if the training-time balance loss is only computed on a single micro-batch, it can be fooled by how the data is packed, and only adds up to a real signal when counted across the whole training step. At serving time, that same imbalance resurfaces as a GPU hotspot problem, which is why Expert Parallelism needs EPLB to dynamically reshuffle experts.

Look up & save

Loading dictionary…

中文版

Today's Focus

Tuesday's fixed slot is Deep Learning & NLP, and today's focus is Mixture-of-Experts (MoE) — the architecture behind Mixtral, Qwen's MoE models, and DeepSeek-V3 that decouples a model's total capacity from how much compute each token actually pays for. Interviewers like MoE because it touches three layers at once: the architecture layer (how the router picks experts), the training layer (why load balancing often looks fine on paper but isn't), and the serving layer (how Expert Parallelism avoids hammering a handful of GPUs across a multi-node deployment). Today's drill chains all three into one diagnostic story — exactly the kind of follow-up that shows up in ML infra and LLM training onsites.

Core Concepts

Why MoE exists: decoupling total knowledge from per-token compute

In a dense transformer, every token runs through the entire feed-forward block, so compute per token grows linearly with model size. MoE splits that block into several independent smaller blocks (experts) and adds a router that only picks a few of them per token. The model keeps all the knowledge stored across every expert, but each token only pays for a slice of it. The numbers make this concrete: Mixtral 8x7B stores 46.7B parameters total but only runs about 12.9B per token; DeepSeek-V3 pushes this further with 256 routed experts plus one shared expert that every token always uses, selecting just 8 of the 256 per token. That's also why comparing MoE model "size" needs two numbers: total parameters, which sets your memory footprint, and active parameters, which sets your inference speed.

How the router picks: one linear layer, top-k, then softmax

The router itself is just a single linear layer. It scores every expert for a given token, keeps the top-k highest-scoring ones, then runs softmax over just those k scores to get gate weights — which always sum to 1. The layer's output is the gate-weighted sum of the selected experts' outputs. Mixtral keeps 2 of 8 experts; DeepSeek-V3 keeps 8 of 256 routed experts plus the always-on shared expert. The router's own parameter count is negligible — typically on the order of a thousandth of the experts it's choosing between.

Training-time load balancing: the scope of the balance loss matters more than its value

Early in training, the router finds a few experts slightly better by chance and routes more tokens to them. Those experts train more, get better, and win even more tokens — left unchecked, the rest stop learning entirely. The standard fix is a balance loss: let f_i be expert i's share of routed tokens and p_i its mean router probability; the balance loss equals the number of experts times Σ(f_i × p_i), which hits its minimum — exactly top-k — when routing is perfectly even. But the trap is in the scope this loss is computed over. If it's computed on each GPU's own micro-batch (the default behavior in Hugging Face transformers), and pretraining data is packed by document so a micro-batch is often entirely one language or topic, the loss ends up forcing that narrow slice of same-topic tokens through every expert — making each expert look like it's serving all topics evenly, when really it's just being chased into uniformity by one batch's worth of data, never getting the chance to actually specialize. The Qwen team's fix was to all-reduce each GPU's per-expert token counts first, computing the loss over the whole training step's distribution instead — a change that beat the micro-batch version at every model scale they trained up to 43B parameters. DeepSeek-V3 takes a gradient-free route instead: it maintains a per-expert routing bias that gets nudged up or down each step based on the token counts, affecting only which experts get picked, never the gate weights themselves.

Imbalance resurfaces at serving time as a GPU hotspot, under a different name

The same problem that shows up during training — the router favoring a handful of experts — comes back at serving time wearing different clothes. Large MoE models deploy different experts across different GPUs using Expert Parallelism (EP); if a batch of requests happens to route heavily toward a small set of experts, the GPUs holding those experts get overloaded while the rest sit idle. It's the same imbalance problem, just translated into hardware scheduling. Inference engines like vLLM address this with an Expert Parallel Load Balancer (EPLB): it continuously collects per-expert load statistics every engine step, periodically recomputes which EP rank each expert should live on, and replicates especially hot experts across multiple GPUs as "redundant experts" to spread the traffic — trading extra GPU memory for a more even load.

Fine-grained vs. coarse-grained experts: capacity bought with communication cost

Mixtral takes the coarse-grained approach (8 relatively large experts, keeping 2), while DeepSeek-V3 goes fine-grained (256 relatively small experts, keeping 8, plus a shared expert). Splitting experts finer and running more of them lets the router divide labor more precisely, which at the same active-compute budget tends to buy a lower loss — but the cost is more routing decisions per token and more cross-GPU data movement (dispatch and combine: sending tokens to the experts they need and sending results back), which raises the demands on network bandwidth and all-to-all communication. Choosing coarse versus fine-grained is really about picking a point on two curves — model quality per unit of compute, versus communication overhead per unit of deployment complexity — not a question with one universally correct answer.

How a token moves through a MoE layer, and how the router decides which experts to run
How a token moves through a MoE layer, and how the router decides which experts to runA token first passes through a linear router that scores every expert, keeps the top-k highest scores, runs softmax over just those k scores to get gate weights, and sums the selected experts' outputs weighted by those gates. Without any extra constraint, the router tends to keep favoring the same handful of experts, which is why a balance loss or bias correction is needed to push the probability back away from overheated experts. Router scores one linear layer Keep top-k experts e.g. 8 of 256 Softmax gating gate weights sum to 1 Favors same few rest never train balance loss / bias pushes off overheated experts
  1. Token enters the router (a single linear layer), which scores every expert
  2. Keep the top-k highest-scoring experts; without a constraint, the router tends to keep picking the same few
  3. Softmax over the k kept scores gives gate weights (summing to 1), weighted-summed into the output; a balance loss or bias correction pushes probability away from overheated experts

Simplified for clarity — a real deployment like DeepSeek-V3 keeps 8 of 256; this diagram uses smaller numbers to show the same flow.

Today's Practice Question

The question

Your team is continuing pretraining on a Mixtral-style MoE model using Hugging Face transformers. The training dashboard shows the load balancing loss sitting steadily near its theoretical minimum (close to top-k) — it looks healthy. But a separate per-expert usage analysis by language and topic shows that almost every expert gets used at roughly the same rate across every topic, with no expert showing any sign of specialization, and validation perplexity is slightly higher than expected. Explain what might be causing this contradiction, and propose how you'd diagnose and fix it.

Source: self-devised (synthesizing the Qwen team's published findings on MoE training load balancing) Difficulty: Intermediate Round: onsite / ML infra deep dive

How to break it down

  1. Clarify first: Ask how the data is batched — whether pretraining data is packed by document so a micro-batch is often one language or topic, how large the global batch is and across how many GPUs, and exactly which tensor the balance loss is computed on: a single GPU's micro-batch, or the aggregated distribution across the whole training step.
  2. Build a framework: Separate "the balance loss number looks healthy" from "experts are actually specializing" into two independent claims to verify — the balance loss only guarantees even routing within whatever scope it's computed over, not global evenness, and these two can completely decouple when the data isn't uniformly mixed.
  3. Go deep on the core: Point out that if a micro-batch is usually single-topic, computing the balance loss at that scope forces that batch's same-topic tokens through every expert, making each expert look like it serves every topic evenly — when it's really just being chased into uniformity by one batch, never getting a chance to specialize, which also explains the slightly elevated perplexity. The fix: all-reduce each GPU's per-expert token counts first, then compute the balance loss over the whole training step's distribution instead of a single micro-batch, or switch to DeepSeek-V3's gradient-free approach — a per-expert routing bias updated from the same counts that only affects which experts get picked, not the gate weights.
  4. Close it out: Flag that this change isn't free — if the experts are deployed with Expert Parallelism across GPUs, a single micro-batch's imbalance is still the real load the hardware feels in that moment. Optimizing purely for global balance can leave specific GPUs hammered during specific steps, so the more mature approach keeps the global balance loss as the primary constraint while layering in a small-coefficient micro-batch-level penalty on top.

Sample answer (say this out loud in the interview)

I'd separate "the loss looks healthy" from "experts are actually specializing" as two independent claims. The scope of the balance loss calculation is the key variable here — if it's computed per-GPU on each micro-batch, which is the default in Hugging Face transformers, and pretraining data is packed by document, a micro-batch is often entirely one language or topic. In that case, the balance loss ends up forcing that batch's same-topic tokens through every expert, making each expert look like it's serving every topic evenly — but that's really just the router being chased into uniformity by one narrow slice of data, not real specialization. That lines up exactly with what we're seeing: a healthy-looking loss, no expert showing specialization, and perplexity a bit higher than it should be.

I'd start by confirming how the data is split and what scope the loss is computed over. I'd check how the global batch gets sharded across GPUs, how topically diverse a single micro-batch tends to be, and which tensor the current balance loss is calculated from. If it turns out to be scoped to a single micro-batch, the fix is to all-reduce each GPU's per-expert token counts first, then compute the loss over the whole training step's distribution — the Qwen team's published results show this beat the micro-batch-only version at every model scale they trained, up to 43B parameters. If I wanted to avoid the extra gradient noise from a loss term entirely, I'd switch to DeepSeek-V3's approach instead: maintain a gradient-free per-expert routing bias, nudged up for underused experts and down for overused ones each step based on the counts, affecting only which experts get selected, not the gate weights.

But I wouldn't treat global balance as the whole answer. If this model is going to be deployed with Expert Parallelism across multiple GPUs down the line, a single micro-batch's imbalance is still the real load the hardware has to absorb in that moment — optimizing purely for global balance could leave specific GPUs hammered on specific steps. So I'd recommend keeping the global balance loss as the primary constraint, and layering a small-coefficient micro-batch-level penalty on top rather than treating it as an either-or choice.

Self-check

Use this table to check whether your answer hit the key points:

Check itemCovered?
Identified the balance loss's computation scope (micro-batch vs. whole training step) as the key variable, not the loss value itself
Explained how document-packed pretraining data makes a micro-batch single-topic, producing a false sense of "evenness"
Proposed a fix: all-reduce expert counts across GPUs before computing the loss, or switch to bias-based loss-free routing
Noted that under Expert Parallelism, a single micro-batch's imbalance is still the hardware's real moment-to-moment load, so a small micro-batch-level penalty should still be kept
Bonus: mentioned auditing per-expert token counts by topic/source after the fact, instead of trusting the loss value alone

Further Reading

References

All three sources below sit in the deep learning / NLP corner of large language model architecture.