What this part does
Anchored Plug-in MoE extends a capable dense language model without silently changing it. The original model remains an immutable anchor, while specialist MLPs, routers, calibration data, and lifecycle metadata are carried in independently managed packages.
The framework is a research system for comparing modular composition strategies. It is not one fixed Mixture-of-Experts recipe, and a validated standalone primitive is not automatically available through the complete model lifecycle.
Where it fits
The MLP-expert path sits around a Hugging Face causal language model:
- a backend locates selected MLP layers;
- each selected MLP is wrapped while preserving its original module as the anchor;
- installed package metadata and expert payloads are validated;
- an explicit synchronization step attaches the supported runtime;
- routing chooses the anchor or compatible specialists for each token;
- export records a reproducible composition without duplicating the anchor in every package.
In this MLP-expert path, attention, embeddings, normalization, and the language-model head remain part of the frozen shared backbone.
The Needle branches path instead shares a frozen prefix and specializes complete last-layer suffixes, selecting one response branch per request. Its browser deployment uses a generative router with recent conversation context and downloads one base plus router/specialist patches. Both paths preserve an explicit frozen fallback.
Implemented approaches
The status describes how far each strategy travels through the package-to-model lifecycle.
| Approach | Integration label | What the label means here |
|---|---|---|
| Needle shared-prefix branches | Composable | Independent router and specialist suffixes support isolated training, cached JAX decoding, and native export. |
| Browser base-plus-patch deployment | Composable | Recent-context generative routing and separate official WASM models share base downloads through verified byte patches. |
| Exact anchor conversion | Integrated | Conversion, forward, generation, and equivalence checks work through the model façade. |
| Packaged anchored top-1 | Integrated | Package installation, explicit synchronization, sparse execution, export, and reload form a complete lifecycle. |
| Weighted top-2 and adaptive routing | Composable | Selection, combination, capacity, and dispatch primitives are tested, but automatic package-driven model attachment is not available. |
| Always-on anchor with routed deltas | Composable | Explicit routed execution supports compatible anchor-relative experts; package-driven delta materialization remains separate work. |
| Hierarchical, dynamic-k, retrieval, and expert-choice strategies | Research primitive | The strategies are validated in isolation for controlled experiments. |
| Automatic model-level top-2 attachment and capacity estimation | Planned | The behavior is documented but not implemented as an end-to-end runtime. |
These labels describe lifecycle integration, not research value or test quality. The Python feature tracker separately records whether each underlying implementation has passed its own acceptance criteria.
How it works
For every converted layer, the dense MLP becomes candidate zero. Specialist scores are calibrated against that fixed baseline rather than against an implicitly learned “default” expert.
In the conservative top-1 path:
- the anchor begins with score zero;
- each installed specialist produces a calibrated score;
- stable anchor-first tie-breaking chooses the largest score;
- a specialist runs only when it has strictly positive winning evidence;
- unavailable or overflowing work falls back to the anchor;
- the selected output is reconstructed in the original token order.
Installing, unloading, upgrading, or rolling back a package changes registry state. Model execution changes only after the caller explicitly synchronizes that state, which keeps lifecycle operations auditable.
Mathematical intuition
g₀(h) = 0; r(h) = arg maxₖ∈{0,…,K} gₖ(h)h- One token's hidden representation before the routed MLP.
gₖ(h)- The calibrated utility score for candidate k.
k = 0- The immutable dense anchor, whose score is fixed at zero.
r(h)- The candidate selected for this token, with the anchor winning exact ties.
Practical consequenceWhen every specialist score is negative—or exactly tied at zero—the original dense MLP runs unchanged.
For a specialist winner k, the routed layer returns Eₖ(h). For an anchor
winner, it returns A(h) with coefficient one. This is why exact fallback is a
runtime invariant rather than an approximate regularization goal.
Minimal usage
The smallest offline conversion uses an already loaded Qwen3 model:
from anchored_moe import AnchoredMoEConfig
from anchored_moe.backends import Qwen3Backend
report = Qwen3Backend().convert(
model,
AnchoredMoEConfig(converted_layers="upper_half"),
)
The conversion starts in forced-anchor mode. It should preserve every hidden state and output logit before any specialist is explicitly attached.
Verified implementation details
Show the source-backed dense-equivalence invariant
with torch.no_grad():
dense = model(input_ids=input_ids, output_hidden_states=True)
Qwen3Backend().convert(
model,
AnchoredMoEConfig(converted_layers="upper_half"),
)
with torch.no_grad():
converted = model(input_ids=input_ids, output_hidden_states=True)
assert_tensors_equivalent(converted.logits, dense.logits, name="logits")Its invariant is exact logit equality; the complete source also checks every hidden state and prints the converted layer indices.
Show the explicit package lifecycle boundary
model.install(package)
model.synchronize_registry()
routed = model(input_ids=input_ids).logits
model.unload(package.identity)
model.synchronize_registry()
anchor = model(input_ids=input_ids).logitsThe complete source verifies installation, routed execution, exact anchor restoration, composition export, and reload.
Current limitations
- Qwen3 is the first implemented backend; the backend contract is broader than the currently validated model-family set.
- Package-driven top-2, adaptive, hierarchical, shortlisted, and delta-expert attachment are not model-level configuration paths.
- Composition checkpoints reference a pinned anchor and do not yet support remote transfer, optional anchor bundling, or inactive rollback history.
- Capacity estimation, fallback beyond an already selected pair, and distributed production validation remain future work.
- Several advanced strategies target experiments, training, or prompt prefill and should not be described as autoregressive serving paths.
References
Edward J. Hu et al. · 2021
LoRA: Low-Rank Adaptation of Large Language Models
arXiv:2106.09685- Why it matters here
- Motivates compact anchor-relative expert parameterizations.
- How Mutations differs
- Mutations keeps those experts behind its own immutable-anchor and explicit lifecycle contracts.
William Fedus, Barret Zoph, and Noam Shazeer · 2021
Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity
arXiv:2101.03961- Why it matters here
- Motivates sparse routing and load-balancing comparisons.
- How Mutations differs
- Mutations adds permanent dense fallback and does not treat its anchor policy as a Switch Transformer mechanism.
Chuan Guo, Geoff Pleiss, Yu Sun, and Kilian Q. Weinberger · 2017
On Calibration of Modern Neural Networks
arXiv:1706.04599- Why it matters here
- Motivates temperature calibration.
- How Mutations differs
- The repository applies per-head binary utility calibration and explicit activation thresholds rather than reproducing the paper's multiclass setup.
The project-specific system design and its departures from prior work are defined in the architecture blueprint.
Related pages
- Return to the documentation index.
- Inspect the feature implementation tracker for the acceptance status of individual Python features.
- Read the repository overview for development setup and the full executable example inventory.

