Looped-ModernBERT
ModernBERT-base converted into a looped transformer
The recipe follows D. Louapre, Looped Transformers: Thinking twice with the same weights. It uses the GLM-5.4-style conversion: a pretrained model gets a looped block with per-pass gates and is then adapted by continued training.
embeddings → L0–6 (once) → L7–14 (×2, gated) → L15–21 (once) → MLM head 30 layer applications / token
Results: loop vs no loop
Same parameters, same continued MLM training (3k steps × 16 × 512 tokens of wikitext-103, lr 5e-5, frozen embeddings), same fine-tuning recipe. Only the loop differs.
| Without loop | With loop | Δ | |
|---|---|---|---|
| Layer applications / token | 22 | 30 | +36% compute |
| RTE dev acc (8 seeds) | 66.3 ± 4.7 | 70.2 ± 3.9 | +3.9 (p = 0.03, 6/8 wins) |
| MNLI-m / mm dev acc (1 seed) | 88.82 / 89.06 | 89.08 / 89.39 | +0.25 / +0.34 (noise) |
| MLM loss / acc (wikitext-103 val) | 1.443 / 69.71 | 1.434 / 69.85 | tie |

Gains show up on entailment (RTE), not masked-token prediction: extra passes buy reasoning, not stored knowledge.
Side findings
- Storing beats looping under compression. At 89.5M params, looping 3 core layers ×4 beats running them once by +1.1 points; storing 6 distinct layers (104.5M) is +3 better still.

- Gates keep loops stable past training depth. With 1–6 random training passes, ungated carries let state norm grow and loss rises after 6 passes; the gated carry stays flat to 12.

Usage
import torch
from looped_modernbert import from_pretrained
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("answerdotai/ModernBERT-base")
model = from_pretrained("mahwizzzz/looped-modernbert") # looped (L7-14 ×2)
# baseline = from_pretrained("mahwizzzz/looped-modernbert", subfolder="control") # no loop
enc = tok("The capital of France is [MASK].", return_tensors="pt")
sel = enc.input_ids == tok.mask_token_id
logits = model(enc.input_ids, enc.attention_mask, sel=sel) # logits at [MASK]
print(tok.decode(logits.argmax(-1)))
h = model(enc.input_ids, enc.attention_mask, hidden=True) # encoder states for fine-tuning
Reproduce: fine-tune with glue.py --model ... --task {rte,mnli} --seed N. Train with:
looped_modernbert.py train --name glm_loop2 --carry glm --prelude 0,1,2,3,4,5,6 --core 7,8,9,10,11,12,13,14 --coda 15,16,17,18,19,20,21 --passes 2 --kl 0 --lr 5e-5 --freeze-emb --accum 4
Files
model.safetensors, config.json (looped model) · control/ (no-loop baseline) · results/ (probes, GLUE JSONs, summary.json) · figures/ (plots)
Limitations
- Small budget: ~25M tokens of continued training on one 4.5 GB GPU share.
- Fine-tuning was untuned, so absolute RTE is below ModernBERT's reported score, but the loop vs no-loop comparison is fair.
- MNLI used one seed; RTE dev is small (277 examples). Treat the RTE gain as promising, not settled.
from_pretraineddownloads ModernBERT-base once to build the architecture skeleton.
Method credit: D. Louapre, Looped Transformers (CC-BY 4.0). Base model: answerdotai/ModernBERT-base (Apache-2.0).