Shared experts: keep common computation separate from routed choice
Account for always-active shared experts and fine-grained routed experts while distinguishing architecture changes from equivalent parameter or FLOP budgets.
On this page
The question for today
What you’ll understand
- Write an explicit shared-plus-routed forward rule.
- Compare stored and active expert weight budgets under stated widths.
- Design architecture ablations without assuming equal budgets imply equal functions.
A shared expert executes for every eligible token, while routed experts execute only for selected assignments. Combining them can separate common computation from conditional computation, but it introduces a new forward rule and resource budget. The original DeepSeekMoE architecture combines shared-expert isolation with finer expert segmentation. Treat that specific design and its ablations as evidence about a variant, not a universal definition of sparse models.
An always-active path has its own parameters and semantics
In the teaching variant here, sum shared expert outputs with a gate-weighted selection of routed outputs and a residual input. Shared experts have no top-k membership decision for each token. Their outputs are not automatically the mean of routed experts, and they need not share parameters with them. Some architectures add gates or other transformations to a shared path, so write its coefficient explicitly. DeepSeekMoE's original formulation uses deterministic shared participation while its routed candidates retain their defined score and selection rule.
Always-active shared computation changes both modeling and systems behavior. Every token contributes to its gradient under the applicable loss, while each routed expert sees its selected population. This does not prove an expert learned general knowledge or that routed experts learned disjoint concepts; those are empirical hypotheses requiring ablations. A shared branch can also become a substantial compute cost. Replication, sharding, optimizer-state storage, and overlap depend on the training layout rather than on the word shared alone.
Fine-grained segmentation preserves a budget only under assumptions
Splitting one feed-forward expert into smaller-width experts increases the number of combinations a router can select. If widths scale inversely with the split factor and the number of active experts scales with it, a simple matrix-weight and leading-FLOP budget can remain comparable. That accounting does not establish functional equivalence: different nonlinearities, parameter partitioning, and selection combinations define another model. Router cost, permutation metadata, small-group efficiency, and communication can also change even when the dominant expert arithmetic is matched.
DeepSeekMoE isolates some of the smaller experts as shared and reduces the number of active routed experts to retain its stated activation budget. Other systems may add shared computation on top of an existing routed budget instead, increasing active work. Distinguish those choices. Count shared and routed widths, their parameter storage, and actual accepted token rows. Do not compare only the number of expert objects because a narrow expert and a wide expert do not carry the same weight or matrix-work budget.
Ablate the architecture and profile the shared path separately
Compare no-shared, additive-shared, and budget-reallocated shared variants with explicit stored parameters, active arithmetic, token budget, and training objective. Disable or replace a branch only under a clearly described intervention; extra routed experts are not guaranteed to reproduce a trained shared branch. Inspect task quality, expert specialization metrics, accepted routing counts, and per-path time. Megatron-Core 0.15.0 documents an optional overlap path for shared experts with specific dispatcher and runtime requirements. Its availability does not guarantee that all shared compute is hidden.
The cache lab illustrates a repeated working-set pattern only. Reset, set C=4 and s=1, predict zero hits among the initial sixteen requests, then Play or Step. Separately Reset, set C=4 and s=4, predict twelve initial hits, then Play or Step. The second modulo-sixteen stream revisits four addresses and fits the toy LRU cache. It does not represent shared experts, weight residency, gradients, or hardware caches. Use it to ask what data is actually reused, then measure the real shared and routed weight traffic rather than inferring reuse from an architecture label.
Work it through
Reallocate an equal leading weight budget
Begin with four two-linear-layer experts of d=8 and width 16, activating two per token. Replace them with eight width-eight experts, isolate one as always shared, and activate three of the seven routed experts.
Originally, each expert has 2×8×16=256 matrix weights. Stored expert weights total 4×256=1,024, and two active experts expose 512 weights per token under this proxy.
Each smaller expert has 2×8×8=128 weights. Eight store 1,024 weights, matching the original leading storage count.
One shared plus three routed experts activate four smaller experts, or 4×128=512 weights. The matched proxy does not make their nonlinear functions, router costs, communication, or quality identical.
The two stated architectures match this stored/active matrix-weight budget while remaining different models and potentially different systems workloads.
The living notebook
Explore the model
Interactive lab · cache
Measure the actual repeated working set
Reset, set C=4 and s=1, predict zero hits in the initial 16 requests, then Play or Step. Separately Reset, set C=4 and s=4, predict 12 initial hits, then Play or Step. The modulo-16 LRU model does not simulate experts, model parameters, hardware weight caching, or gradients.
- Hits / requests
- 0 / 16
- Hit rate
- 0%
- Address-stream period
- 16 addresses
A fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA shared-path label does not establish a particular memory-reuse benefit.
Pause & reason
Check your understanding
Your turn
Try it yourself
Use the stated scalar teaching rule with residual input 10, one shared output 2, routed outputs 3 and 5, and routed weights 0.25 and 0.75. Find the result and explain why the shared output is not renormalized with these routed weights.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The shared coefficient is explicitly one in this variant.
Compare with the solution
The result is 10+2+0.25×3+0.75×5=16.5. The routed weights apply only to their respective routed branches; the shared branch has its separate stated coefficient. A model that jointly normalizes all branches would define a different operation.
Keep the idea
Take it with you
- Always-active shared experts and selected routed experts have distinct semantics.
- Fine-grained expert counts require width-aware budget accounting.
- Matched budgets enable an ablation but do not prove equivalent behavior or speed.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.