Where the loop sits, how often it runs, what each visit shares, how the residual is scaled, how the input re-enters and how depth is chosen are fields of one readable PyTorch model. Each configuration declares its parent and the fields it changes (lineage).
Unique parameters, training FLOPs and KV cache come from the configuration, on a CPU, in one command. Two configurations are matched when all three are within 5% (cost contract).
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).
Install from source (Python 3.12, Torch 2.14.0):
uv venv --python 3.12
. .venv/bin/activate
uv pip install 'torch==2.14.0' --index-url https://download.pytorch.org/whl/cpu
uv pip install '.[data,hf]'Compare the loop of Phase 1 with its untied twin, which owns separate weights for each visit. The command prints one JSON record; its matched section, shown here, holds the three budgets:
$ python scripts/compare_recipes.py compare \
recipes/phase1/m3-adamw.json recipes/phase1/m4-adamw.json --seq-len 4096
…
"matched": {
"logical_kv_bytes": {
…
"relative_difference": 0.0,
"relative_tolerance": 0.05
},
"training_flops_per_token": {
…
"relative_difference": -0.0010398183468857637,
"relative_tolerance": 0.05
},
"unique_non_embedding_parameters": {
…
"relative_difference": 0.01103571024112304,
"relative_tolerance": 0.05
}
},
…Build a looped model, run it and cost it:
import torch
from moeloop import LoopedLM, ModelConfig
from moeloop.costs import estimate_cost
# one outer layer, two middle layers that run twice, one outer layer;
# the middle layers share their weights across visits, attention excepted
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)
model = LoopedLM(config).eval()
with torch.no_grad():
logits = model(torch.randint(0, 128, (2, 16))).logits
print(tuple(logits.shape)) # (2, 16, 128)
cost = estimate_cost(config, seq_len=16)
print(cost["calls"]["forward_cells"]) # 6
print(cost["parameters"]["unique_non_embedding"],
cost["flops"]["training_per_token"],
cost["kv"]["bytes_at_context"]) # 117536 619008 6144
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.
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 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.
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). Failed runs and short checks stay in the record (#243, 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 |
Tests: uv sync --frozen && uv run --frozen python -m pytest -q. 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
Cite the repository and the exact source commit: CITATION.cff. Cite the papers of the designs you use separately; the method map lists them.
@software{looptitan,
title = {{LoopTitan}},
author = {{The LoopTitan authors}},
version = {1.0.0rc1},
url = {https://github.com/datamllab/LoopTitan}
}MIT. Copyright the LoopTitan authors.