Open PyTorch infrastructure for looped mixture-of-experts (MoE) language models.
- One model, every design. Loop position, visit count, what a visit shares, residual scale, input re-entry and depth rule are fields of one readable PyTorch model; each configuration names its parent and the fields it changes (lineage).
- Equal budgets before you train. Unique parameters, training FLOPs and KV cache come from the configuration on a CPU in one command; two configurations match when all three are within 5% (cost contract).
- Checked against independent code. The model matches the official Transformers Qwen3-MoE in logits, gradients, optimizer steps and cache (check); two published looped checkpoints convert with the same logits (#199, #201).
- Every path on the record. Each study and each run is a public issue, failures included, written by agents (open record).
Clone, install the Torch-free core with uv, print the lineage of every configuration, run the tests:
git clone https://github.com/datamllab/LoopTitan && cd LoopTitan
uv sync --frozen
uv run --frozen python scripts/lineage.py
uv run --frozen python -m pytest -qThen compare the loop of Phase 1 with its untied twin on a CPU, before any training; the command prints one JSON record (format), whose three budgets are drawn below:
uv run --frozen python scripts/compare_recipes.py compare \
recipes/phase1/m3-adamw.json recipes/phase1/m4-adamw.json --seq-len 4096
In Python
The model itself needs Torch 2.14.0 (the CPU build here):
uv pip install 'torch==2.14.0' --index-url https://download.pytorch.org/whl/cpu
uv pip install '.[data,hf]'import torch
from moeloop import LoopedLM, ModelConfig
from moeloop.costs import estimate_cost
# one outer layer, two middle layers that run twice (shared weights, attention per visit), one outer layer
config = ModelConfig(vocab_size=128, dim=32, hidden_dim=64, num_heads=4, num_kv_heads=2, num_experts=4, top_k=2,
prefix_cells=1, num_cells=2, suffix_cells=1, num_visits=2, attention_per_visit=True, max_seq_len=64)
print(LoopedLM(config)(torch.randint(0, 128, (2, 16))).logits.shape) # torch.Size([2, 16, 128])
print(estimate_cost(config, seq_len=16)["calls"]["forward_cells"]) # 6 = 1 + 2 Γ 2 + 1
A looped MoE is a standard MoE with a few decisions changed. Each decision is a field of ModelConfig or of the training recipe.
Fields and references
| Mechanism | Field | Designs |
|---|---|---|
| Where the loop sits and how often it runs | prefix_cells, num_cells, suffix_cells, num_visits |
[1ββ 4,Β 6ββ 10] |
| Experts per region | prefix, core, suffix (num_experts, hidden_dim, top_k) |
[1,Β 4] |
| What a visit shares | attention_per_visit, router_per_visit, norm_per_visit |
[4,Β 8] |
| Residual scale, global or per visit | core.residual_scale, visit_residual_scales |
[1,Β 2] |
| Input re-entry | input_injection |
[6,Β 7] |
| Initial state and state update | initial_state, state_update |
[6ββ 8] |
| Depth: fixed, sampled or learned | depth_rule, grad_visits, exit_distribution |
[6,Β 9] |
| Low-rank delta per visit | lora_attention_rank, lora_ffn_rank |
[10] |
| Experts tied across layers | order="layer" with attention, router and norms per visit |
[5] |
A reference number marks a published design that uses the mechanism and is implemented here.
Each frozen configuration names its parent and the fields it changes. An excerpt of the one-change chain, in the real order (a line β¦ stands for lines left out, and β¦ in brackets for fields left out):
$ python scripts/lineage.py
phase1/m0
β¦
phase1/m3 [dim, hidden_dim, num_heads, num_experts, β¦, num_visits, core]
phase1/m4 [num_cells, num_visits, core]
phase1/m4-elr
shape/u [prefix_cells, num_cells, suffix_cells, num_experts, core]
shape/r [core]
β¦The command prints the whole tree. Each configuration in plain words: Phase 1 results; what each keeps from its source and what it adapts: method map.
compare writes one record that sorts each quantity into matched, controlled, measured-different or unknown, and allocates no GPU. The controls of a study ship as configurations: the untied twin of the quick start and the one-change chain of Phase 1. scripts/recipe_atlas.py sweeps the shapes of a configuration and marks those that match a reference on all three budgets. Definitions and the CLI: cost and comparison.
Evidence: method, CPU record, reference tests, conversion tests. The conformance check tests a configuration against the model's own contracts (parameter ownership, shared gradients, cost-model calls, cache, export round trip, identity) on a CPU in seconds (details):
from moeloop.recipe_spec import RecipeSpec, TrainingRecipe
from moeloop.testing import check_recipe
spec = RecipeSpec(name="my-loop", model=config, training=TrainingRecipe(num_visits=2))
report = check_recipe(spec) # raises ConformanceError if a check fails
print({name: check["status"] for name, check in report["checks"].items()})
# {'ownership': 'pass', 'shared_gradients': 'pass', 'cost_calls': 'pass',
# 'cache': 'pass', 'hf_roundtrip': 'pass', 'identity': 'pass'}Here config is the model of the quick start's Python example.
Training runs on TorchTitan with AdamW or Muon. Initial weights, data order and validation samples do not depend on the GPU count (architecture, #175). Resume is bit-exact in model and optimizer state (validation). Export writes a standalone Hugging Face model (export).
Training needs a CUDA build of Torch 2.14.0 and the train extra (setup):
python scripts/recipe_experiments.py run --spec recipes/phase1/m3-muon.json \
--manifest "$MOELOOP_DATA/manifest.json" --output runs/m3-muon --gpus 8 --evaluateThe command trains the Phase 1 loop with Muon, exports the final checkpoint to runs/m3-muon/hf and measures BPB on the full validation and test splits. Data preparation, resume and generation: Training and data.
The paper, LoopTitan: What Does Parameter Revisit Buy a Mixture-of-Experts?, reports this study. Its code is this repository, and its models are on Hugging Face.
The study walks one change at a time from a standard MoE to a looped MoE, at equal budgets, under two optimizers.
The table
| Step | Configuration | AdamW | Ξ | Muon | Ξ |
|---|---|---|---|---|---|
| 0 | Standard MoE: 12 layers of 64 experts | 0.9995 | 0.9744 | ||
| 1 | Finer experts: 72 smaller experts, top-9 | 0.9953 | β4.2 | 0.9735 | β0.9 |
| 2 | Deeper and narrower: 18 layers at width 1056 | 0.9926 | β6.9 | 0.9702 | β4.2 |
| 3 | Expert layout: 88 experts in the 6 outer layers, 44 in the 12 middle | 0.9936 | β5.9 | 0.9710 | β3.4 |
| 4 | Residual scale: middle residual Γ0.5 | 0.9906 | β8.9 | 0.9710 | β3.3 |
| 5 | The loop: the 12 middle layers become 6 layers of 88 experts, run twice | 0.9905 | β9.0 | 0.9707 | β3.7 |
Test bits per byte (BPB) after 5.0B tokens of DCLM (4,769 updates of 1,048,576 tokens, seed 42); lower is better. Ξ is the difference to step 0 with the same optimizer, in mBPB; a negative Ξ is a gain. Parameters, training FLOPs and KV cache of every step are within 5% of step 0. Learning rate: tuned once per optimizer on the standard MoE (AdamW 1.2e-3, Muon 1.7e-3); the loop of step 5 selects the same value under the same grid; every other configuration inherits it.
- The loop itself adds almost nothing. At equal budgets the loop is level with its untied twin (step 5 against step 4); most of the gain comes from shape.
- More than half of the gain disappears under Muon. The whole chain gains 9.0 mBPB under AdamW and 3.7 under Muon.
- Beyond equal budgets, one more visit gains as much as twice the experts under Muon. The visit costs 31% more training FLOPs and no new weights (outside matched budgets).
Every configuration, the controls and both optimizers: Phase 1 results (data). The record of the study: #177, #216, #225.
Later phases join this list when they are released.
Every path is a GitHub issue. A paper records the path that worked. Issues and code record every path, for any agent to build on. Failed runs and refuted predictions stay in the public issues, beside the results (#243).
Many agents, many directions, one record. Agents planned, built, ran and reviewed every study here. The rules they follow and their four skills (plan, implement, review, run) ship with the code (AGENTS.md). Branch from any result, since every configuration names its parent (lineage).
Send your agents. An agent from outside enters a result by pull request, following the contributing guide.
Each study is an issue that declares its arms, controlled settings and budget before the runs (#225). scripts/results.py checks the runs of a study against its declared design (#232). Short checks stay in the record as well (protocol). The issues are a copy of the development record under the original issue numbers, with pull-request records among them (#199).
The benchmark is a frozen protocol of four tracks (eval/bench/tracks.json). A checker binds a submission folder to its files and lists what it cannot check (benchmark). Anyone can enter a result by pull request; the bench workflow checks it, and every complete record is merged (contributing).
A new configuration is a recipe: change the fields of an existing one, cost it, run the conformance check and find its place in the lineage. Extensions walks through the four steps, and through a new forward pass.
| Document | Contents |
|---|---|
| Architecture | Physical layers and logical calls, the model, training, data, resume and export |
| Recipes | The configurations of the published designs and where to start reading |
| Method map | Each design: its source, what is kept and what is adapted |
| Extensions | A new configuration, a new state update, a new attention |
| Cost and comparison | Budgets, the comparison record and the benchmark |
| Training and data | Data preparation, training, resume, export and evaluation |
| Independent check | The check against Transformers Qwen3-MoE |
| Validation | What was run on GPU, and the limits of each result |
| Development | Tests, conformance and diagnostics |
| Protocol, TorchTitan record | How studies and runs are recorded |
| Phase 1 results | Every Phase 1 configuration under one protocol |
The quick start runs the Torch-free tests; the model tests need Torch and the train extra (Development).
LoopTitan builds on the work of many people. We thank them.
- TorchTitan, the trainer every run uses.
- CVSM, the protocol and run tooling this repository adopts.
- Hugging Face Transformers, whose Qwen3-MoE implementation the model is checked against, and the released checkpoints and model code of ByteDance/Ouro-1.4B and tomg-group-umd/huginn-0125, the references for checkpoint conversion.
- The public code of the looped designs implemented here: seal-rg/recurrent-pretraining6, SR-A-W/how-to-loop-moe4, epfml/looped-moe5, hed-ucas/LOOM8, ifm-ai/xllm-loop7 and lcqysl/LatentLoop2.
- DCLM, the open corpus the Phase 1 study trains on.
- SMELT: Scaling Laws for Compute-Matched MoE Looped Transformers. 2026. arXiv:2609.01343
- LatentLoop: Scaling Looped MoE Models with Asymmetric Compute Allocation. 2026. arXiv:2610.19975
- Scaling Laws for Looped Mixture of Experts. 2026. arXiv:2609.40316
- How to Loop MoE: Flatten the Experts, Untie the Attention. 2026. arXiv:2609.35751
- Tying the Loop β Tied Expert Layers in Mixture-of-Experts Language Models. 2026. arXiv:2606.16825
- Scaling up Test-Time Compute with Latent Reasoning: A Recurrent Depth Approach. NeurIPS 2025. arXiv:2502.05171
- Towards Looped Models Done Right, Part I: Topology, Input Injection, Recurrent-State Design. 2026. arXiv:2610.23036
- Looping Beyond Twice: A Scalable Recipe for Looped Mixture-of-Experts. 2026. arXiv:2610.01153
- Scaling Latent Reasoning via Looped Language Models. 2025. arXiv:2510.25741
- Relaxed Recursive Transformers: Effective Parameter Sharing with Layer-wise LoRA. ICLR 2025. arXiv:2410.20672
If you use LoopTitan, please cite the paper, arXiv:2611.34821. Cite the papers of the designs you use separately; the method map lists them.
@misc{looptitan2026,
title = {{LoopTitan: What Does Parameter Revisit Buy a Mixture-of-Experts?}},
author = {Tian, Zichen and Lu, Yudong and Wu, Xuansheng and Zou, Na and Hu, Xia and Wang, Guanchu and Sun, Qianru},
year = {2026},
eprint = {2611.34821},
archivePrefix = {arXiv},
primaryClass = {cs.LG},
url = {https://arxiv.org/abs/2611.34821}
}MIT. Copyright the LoopTitan authors.