8000 GitHub - hustvl/MoLT: Mixture-of-Loops Transformer · GitHub
[go: up one dir, main page]

Skip to content
hustvlPublic

About

Mixture-of-Loops Transformer

Resources

Stars

169 stars

Watchers

1 watching

Forks

Repository files navigation

Mixture-of-Loops Transformer

What Should Be Passed as a Transformer Loops?

Lianghui Zhu1,2, Shijie Wang2,†, Xinggang Wang1,#, Jinze Bai2, Bo Wang3, Xiang Bai1

1 Huazhong University of Science & Technology, 2 ByteDance Seed, 3 University of Toronto

(†) project lead, (#) corresponding author.

Paper (PDF), Code (U-MoLT, MoLT-R / MoLT-KV / MoL-Hybrid)

News

  • Nov. 26th, 2026: We released the Mixture-of-Loops Transformer (MoLT) paper (PDF) and the initial minimal U-MoLT implementation on BlaGPT.

TODO

Abstract

Looped Transformers boost expressivity by reusing shared layers across loops, yet at the cost of efficiency. Pushing their expressivity–efficiency frontier requires rethinking the core mechanism connecting adjacent loops: What should be passed as a Transformer loops? We introduce Mixture-of-Loops Transformer (MoLT), whose Mixture-of-Loops Attention (MoLA) uses keys and values (KV) as memory for selective reuse across depths and loops. Under loop residual, MoLT-R retains the residual stream and reads local KV across loops for expressivity. Under loop KV, MoLT-KV instead restarts from embeddings and reads current-loop local KV with preceding-loop memory KV at earlier positions for efficiency. MoLT-KV eliminates same-position cross-loop dependence and, paired with loop forcing for parallel training, unlocks single-traversal Mixture-of-Loops (MoL) decoding beyond the training loop horizon. To balance efficiency and quality, we introduce U-shaped MoLT (U-MoLT), which separates memory construction from prediction readout and skips unused decoder traversals without changing predictions.

In 400B-token pretraining, U-MoLT outperforms OLMo3 across 700M/1.5B dense and 3B MoE models, achieving 1.7× validation cross-entropy (CE) token efficiency at 700M while improving 3B MoE 10-domain perplexity by 0.75 and 10-task accuracy by 2.1 percentage points. In 100B-token continued pretraining of Qwen3.5-0.8B-Base, our U-MoLT adaptation lowers CE on all 11 domains over the matched baseline with 1.4× mean token efficiency. At inference, U-MoLT with MoL-Hybrid-2 matches non-looped OLMo3 latency at 996.6 vs. 1,000.6 ms on S-size (~113M) models.

Overview & MoLT Family

Variant Primary Focus Mechanism & Layout Inference Profile Best Suited For
MoLT-R Maximum expressivity Plain L-layer stack, loop residual, current- & preceding-loop local KV Fixed N-loop (NL prefill, NL decode, N× persistent KV) Expressivity-critical or deeper N-loop regimes with zero added parameters
MoLT-KV Plain-stack efficiency Plain L-layer stack, embedding restart, loop KV (j < t), current-loop local KV MoL-Hybrid, k ∈ {1, 2} (kL prefill, L decode, 1× persistent KV) Generation-heavy workloads or plain backbones with less inductive bias
U-MoLT Balanced efficiency & quality LE + LD split, loop KV encoder, cross-only decoder with per-layer KV MoL-Hybrid, k ∈ {1, 2} (kLE prefill, L decode, 1× persistent KV) General-purpose pure-attention LLMs needing matched prefill and decode cost

Attention Visibility Across Loops and Depths

Comparison of visible KV relationships across loops and depths. (a) Loop Model carries prior computation only through the residual stream. (b) MoLT-R adds direct MoLA reads over current-loop and preceding-loop local KV at token t. (c) MoLT-KV restarts from token embeddings and reads strict-prefix memory KV (j < t) from loop r − 1 alongside current-loop local KV, eliminating same-position cross-loop dependence. (d) U-MoLT pairs a loop KV MoLT Encoder with a causal cross-only MoLT Decoder reading the normalized encoder output (j <= t).

U-MoLT Architecture

U-MoLT separates memory construction from prediction readout. (a) The downward MoLT Encoder restarts from token embeddings each loop, while the upward cross-only MoLT Decoder starts from the raw encoder output Xr,LE and attends causally to the normalized encoder output zr. (b) Each MoLT Encoder block jointly attends to current-loop local KV and strict-prefix memory KV (j < t) within a single softmax via MoLA. (c) Each MoLT Decoder block performs causal cross-attention (j <= t) with independent per-layer KV projections from zr, allowing intermediate-loop and non-final prompt decoder traversals to be skipped at inference without changing predictions.

Results

Downstream Performance (400B tokens, Accuracy %)

Model PIQA HellaSwag WinoGrande OpenBookQA BoolQ SciQ ARC-E ARC-C COPA MMLU Avg. ↑
OLMo3-700M 70.7 53.1 55.8 36.2 56.0 89.3 66.4 35.4 69.0 33.9 56.6
MoLT-R-700M 72.5 55.8 58.0 36.2 62.0 92.5 69.6 38.1 73.0 34.3 59.2
U-MoLT-700M 72.4 55.0 56.0 37.2 59.4 90.2 69.1 35.5 81.0 35.4 59.1
OLMo3-1.5B 73.9 59.9 58.4 37.4 63.7 91.8 74.2 40.4 76.0 36.6 61.2
U-MoLT-1.5B 74.8 61.8 59.0 39.0 65.7 93.0 74.2 42.1 79.0 37.0 62.6
OLMo3-3B MoE (660M active) 72.9 59.3 59.5 35.4 63.1 89.8 70.1 36.7 77.0 36.7 60.1
U-MoLT-3B MoE (660M active) 73.2 62.0 59.9 37.6 64.4 90.5 73.9 41.8 80.0 38.2 62.2

Validation Perplexity across 10 Domains (400B tokens, Lower is Better)

Model C4 ICE M2D2-S2ORC Pile WikiText-103 Books CC peS2o Reddit Stack Avg. ↓
OLMo3-700M 18.68 18.59 21.25 9.43 12.36 16.50 21.53 8.78 25.51 3.75 15.64
MoLT-R-700M 17.82 17.59 19.77 9.04 11.70 15.63 20.53 8.47 24.26 3.63 14.84
U-MoLT-700M 17.89 17.44 19.75 9.04 11.56 15.74 20.62 8.44 24.48 3.62 14.86
OLMo3-1.5B 16.53 16.72 18.75 8.49 10.62 14.23 19.05 7.94 22.77 3.45 13.86
U-MoLT-1.5B 15.81 15.52 17.77 8.11 9.92 13.50 18.16 7.63 21.71 3.34 13.15
OLMo3-3B MoE (660M active) 16.61 17.67 18.42 8.48 10.91 14.32 19.11 7.98 22.93 3.44 13.99
U-MoLT-3B MoE (660M active) 15.76 16.47 17.59 8.08 10.05 13.53 18.16 7.64 21.82 3.31 13.24

Token Efficiency at 700M Scale (400B tokens)

With only +1.50% additional parameters, U-MoLT-700M achieves a 1.5× input-token speedup on smoothed final-loop training CE and a 1.7× speedup on 11-domain mean validation CE (matching OLMo3's 400B loss at 232.8B tokens, i.e., 41.8% fewer tokens).

Continued Pretraining on Qwen3.5-0.8B-Base (100B tokens, Validation CE ↓)

Method C4 ICE M2D2-S2ORC Pile WikiText-103 Books CC peS2o Reddit Stack Wiki Avg. ↓
Qwen3.5-CT 2.759 2.967 2.995 2.057 2.401 2.710 2.939 2.039 3.170 1.042 2.376 2.496
U-MoLT-CT1 2.741 2.945 2.983 2.042 2.380 2.690 2.920 2.025 3.154 1.036 2.359 2.480
U-MoLT-CT2 2.745 2.946 2.985 2.045 2.383 2.694 2.923 2.028 3.157 1.040 2.363 2.483

Inference Latency (S-size ~113M, Prompt Prefill + 64 Decoding Steps, in seconds)

Method Schedule Prefill (128) Decode (128) Total (128) Prefill (4,096) Decode (4,096) Total (4,096)
OLMo3 Fixed 1-loop 0.0129 0.9776 0.9905 0.0181 0.9825 1.0006
Loop OLMo3 Fixed 2-loop 0.0245 1.9617 1.9862 0.0347 1.9396 1.9743
MoLT-R Fixed 2-loop 0.0256 1.8707 1.8963 0.0356 1.9412 1.9768
MoLT-KV Fixed 2-loop 0.0297 1.8290 1.8587 0.0362 1.9439 1.9801
MoLT-KV Mixture-of-Loops 2.2539 0.9370 3.1909 72.8810 0.9592 73.8402
MoLT-KV MoL-Hybrid-1 0.0161 0.9542 0.9703 0.0193 0.9702 0.9895
MoLT-KV MoL-Hybrid-2 0.0328 0.9650 0.9978 0.0378 0.9688 1.0066
U-MoLT Fixed 2-loop 0.0242 1.4291 1.4533 0.0245 1.4430 1.4675
U-MoLT Mixture-of-Loops 1.4386 0.9509 2.3895 46.2151 0.9633 47.1784
U-MoLT MoL-Hybrid-1 0.0182 0.9674 0.9856 0.0183 0.9712 0.9895
U-MoLT MoL-Hybrid-2 0.0268 0.9675 0.9944 0.0265 0.9701 0.9966

Installation

The current release provides minimal U-MoLT, MoLT-R and MoLT-KV implementations on BlaGPT, including Fixed-loop, MoL and MoL-Hybrid decoding, with zero modifications to upstream BlaGPT files.

Requirements for u_molt.py and BlaGPT's binary-shard training entry point:

cd language_tasks/BlaGPT
python -m pip install -r requirements-umolt.txt

Note: Preparing tokenized FineWeb shards using language_tasks/BlaGPT/data/ may require additional dependencies listed in language_tasks/BlaGPT/requirements.txt.

Quick Start

Direct PyTorch Usage (Fixed-loop, MoL and MoL-Hybrid)

Run from language_tasks/BlaGPT:

import torch
from bla_gpt.u_molt import UMoLT, UMoLTConfig

config = UMoLTConfig(
    vocab_size=128, hidden_size=64, num_heads=4, num_kv_heads=2,
    num_encoder_layers=2, num_decoder_layers=2, intermediate_size=128,
    block_size=64, sequence_length=64,
)
model = UMoLT(config)
tokens = torch.randint(0, config.vocab_size, (2, 17))
inputs, targets = tokens[:, :-1], tokens[:, 1:]
logits, loss = model(inputs, targets)
loss.backward()

model.eval()
with torch.no_grad():
    # Fixed-loop computation (parallel over the full prefix)
    full = model.forward_fixed_loop(inputs, num_loops=2)
    generated = model.generate(inputs[:1], 8, temperature=0, schedule="fixed_loop")

    # MoL decoding (single encoder + decoder traversal per token)
    mol_logits, state = model.forward_mol(inputs)
    next_token = torch.randint(0, config.vocab_size, (2, 1))
    next_logits, state = model.mol_step(next_token, state)

    # Parallel two-loop prompt, then single-traversal MoL-Hybrid decoding.
    prompt_logits, state = model.prefill_mol_hybrid(inputs, num_loops=2)
    next_logits, state = model.mol_step(next_token, state)
    hybrid_tokens = model.generate(
        inputs[:1], 8, temperature=0, schedule="mol_hybrid", num_loops=2)

MoLT-R and MoLT-KV

Both plain-stack models reuse U-MoLT's attention blocks and use MoLTConfig(num_layers=...):

from bla_gpt.molt import MoLTConfig, MoLTR, MoLTKV

config = MoLTConfig(
    vocab_size=128, hidden_size=64, num_heads=4, num_kv_heads=2,
    num_layers=4, intermediate_size=128, block_size=64,
)
residual_model = MoLTR(config)
kv_model = MoLTKV(config)
residual_tokens = residual_model.generate(inputs[:1], 8, temperature=0, schedule="fixed_loop")
kv_tokens = kv_model.generate(inputs[:1], 8, temperature=0, schedule="mol_hybrid", num_loops=2)

BlaGPT registration names are molt_r and molt_kv. See the implementation guide for paper terminology, residual/KV semantics and decoding APIs. MoLT-R supports Fixed-loop decoding; MoLT-KV and U-MoLT also support MoL and MoL-Hybrid schedules.

Training U-MoLT on BlaGPT

Run from language_tasks/BlaGPT (requires CUDA/NCCL and tokenized FineWeb .bin shards configured in configs/umolt_s.json):

cd language_tasks/BlaGPT
torchrun --standalone --nproc_per_node=1 bla_gpt/train.py \
  --model_name umolt \
  --config configs/umolt_s.json \
  --run_name umolt_s

configs/umolt_s.json reproduces paper Table 2, method (26): S-size U-MoLT (6+6 layers, 768 hidden, 12/3 GQA, sparse Loop KV & MoLA at layers [0, 2, 4], full current-loop cross-layer depth history, detach_loop_feedback=false, 1:1 loop loss weights) trained on 3B tokens (5,722 iterations, batch_size=512, Muon lr=1e-3, seed=11). Adjust --nproc_per_node (e.g. 8) for multi-GPU training.

Testing Models, Decoding and the Fused MoLA Triton Kernel

cd language_tasks/BlaGPT
python -m pytest tests/test_molt_decoding.py tests/test_mola_triton.py

Note: mola_backend="auto" (default) uses PyTorch FlashAttention + Triton (libs/mola_triton) on supported NVIDIA GPUs (sm80+, BF16/FP16). It also enables single-token cached joint attention, grouped Memory KV projection, and fused Memory K RMSNorm/RoPE during evaluation without gradients. CPU, FP32, and unsupported shapes use eager PyTorch. See language_tasks/BlaGPT/README_UMOLT.md for full implementation notes, API semantics, and multi-GPU constraints.

Repository Structure

MoLT/
├── Mixture-of-Loops Transformer.pdf        # Paper PDF
├── assets/                                 # Figures for README
├── libs/
│   └── mola_triton/
│       ├── __init__.py                     # Fused FlashAttention + Triton MoLA kernel
│       └── decoding.py                     # Cached attention and Memory KV inference kernels
└── language_tasks/
    └── BlaGPT/
        ├── README_UMOLT.md                 # Detailed U-MoLT implementation & usage guide
        ├── README_MOLT.md                  # Plain models, caching and MoL-Hybrid guide
        ├── UMOLT_UPSTREAM.json             # Pinned upstream BlaGPT commit metadata
        ├── requirements-umolt.txt          # Minimal U-MoLT dependencies
        ├── bla_gpt/
        │   ├── u_molt.py                   # U-MoLT and shared attention / sampling
        │   └── molt.py                     # MoLT-R / MoLT-KV models & BlaGPT registration
        ├── configs/
        │   └── umolt_s.json                # Paper Table 2 (26): 6+6 U-MoLT-S, sparse [0, 2, 4], Muon 3B
        └── tests/
            ├── test_molt_decoding.py       # Dense reference, cached and Hybrid decoding tests
            └── test_mola_triton.py         # CUDA unit tests for fused MoLA forward/backward & dispatch

Acknowledgement ❤️

This project builds on BlaGPT, OLMo, Qwen3, and our prior work Mixture-of-Depths Attention (MoDA) (paper). Thanks for their wonderful works.

Citation

If you find MoLT useful in your research or applications, please consider giving us a star ⭐ and citing it with the following BibTeX entry.

@article{zhu2026molt,
  title={Mixture-of-Loops Transformer},
  author={Zhu, Lianghui and Wang, Shijie and Wang, Xinggang and Bai, Jinze and Wang, Bo and Bai, Xiang},
  journal={arXiv preprint arXiv:2611.34923},
  year={2026}
}

About

Mixture-of-Loops Transformer

Resources

Stars

169 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

0