Looped Anticipatory Music Transformer (DangerLabs/music-large-800k-looped)
DangerLabs/music-large-800k-looped is a Looped Transformer architectural conversion of stanford-crfm/music-large-800k (Thickstun et al., TMLR 2024, arXiv:2306.08620), implementing the prelude / core / coda weight-sharing layout and gated inter-pass stabilization described in David Louapre's Looped Transformers: Thinking twice with the same weights (Nov. 2026), drawing on Thinking Machines' Inkling 2 Mini and Z.ai's GLM-5.4.
Training State Note: This checkpoint is a weight-preserving architectural conversion initialized directly from
stanford-crfm/music-large-800kwith freshly initializedLoopGateparameters (7,681added parameters,+0.00098%). No continued training has been run yet. Atnum_passes=1, the model is bit-for-bit identical (max_abs_diff = 0.0,KL = 0.0) tostanford-crfm/music-large-800k; atnum_passes >= 2, the GLM-5.4-style per-token gate keeps activations bounded and distributions tightly aligned with the base model, ready for fixed-pass or variable-loop continued training on symbolic music corpora.
Architecture Comparison vs. Original
| Property | Original (stanford-crfm/music-large-800k) | Patched (DangerLabs/music-large-800k-looped) |
|---|---|---|
| Architecture | GPT2LMHeadModel | LoopedGPT2LMHeadModel (looped_gpt2) |
| Stored Layers | 36 | 36 (9 prelude + 18 core + 9 coda) |
| Effective Depth | 36 | 18 + 18 × num_passes (default num_passes=2 → 54 layers) |
| Parameters | 780,139,520 | 780,147,201 (+7,681 / +0.00098% from LoopGate) |
| Hidden Size / Heads | 1280 / 20 | 1280 / 20 (unchanged) |
| Vocabulary / Context | 55,030 / 1024 | 55,030 / 1024 (unchanged AMT arrival-time + anticipation vocab) |
| Inter-Pass Stabilization | N/A | Per-token scalar LoopGate: h ← h + g · (core(h) - h) (default "gated", also supports "inject" and "plain") |
| Attention Scaling | scale_attn_by_inverse_layer_idx=True | Preserved per pretrained block |
| KV Cache Strategy | 36 layers | Isolated per-pass virtual cache slots (9 + 18 × num_passes + 9 layers) |
| Test-Time Compute | Fixed (36 layers) | Variable num_passes per forward() call (1, 2, 3, ...) |
Prelude / Core / Coda Layout
Following Inkling 2 Mini's 1:2:1 split, the 36 GPT-2 blocks of music-large-800k are partitioned as:
- Prelude (
h[0..8], 9 layers, runs once): Maps arrival-time, duration, note, and anticipation control embeddings into internal musical representations. - Core (
h[9..26], 18 layers, runsnum_passestimes): Shared weights executed iteratively for deeper sequential processing without adding model parameters. - Coda (
h[27..35], 9 layers, runs once): Projects refined internal representations back to next-token logits.
Each (pass_idx, core_layer) writes to its own virtual slot in DynamicCache, ensuring cached autoregressive generation matches full-sequence forward passes (max_abs_diff < 2e-5 at num_passes=2) while preserving each pretrained block's original inverse-layer-index attention scaling.
Executive Summary of Performance Differences
All benchmarks were executed on an NVIDIA GB10 GPU (PyTorch 2.14.1+cu130, transformers 5.5.0) with strict single-model GPU memory isolation (only one model resident on GPU per phase). Full raw metrics are included in benchmark_results.json.
- Near-zero wrapper overhead at
num_passes=1: Prefill, decode, and training throughput are within 0–2% of the originalGPT2LMHeadModelacross all batch sizes and sequence lengths, with 0.00e+00 logit difference and 100.00% exact greedy rollout parity. - Constant weight VRAM across passes: During
use_cache=Falseprefill, peak VRAM stays completely flat fromp=1top=4(4,730 MBatbs=1, seq=1024;5,515 MBatbs=8, seq=1024), delivering up to 2.5× effective depth (90 layers) in the exact same weight footprint as the 36-layer original. - Faster than real-time music generation up to
num_passes=4: At full 1024-token context (bs=1),p=2generates at 56.3 tok/s (1.88× real-time) and evenp=4(90 effective layers) sustains 34.4 tok/s (1.15× real-time) assuming ~10 MIDI events/sec (30 tok/s). - Flat ~6.8 GB training VRAM with gradient checkpointing: Uncheckpointed training VRAM scales linearly with passes (
14.1 → 25.8 GBatbs=2, seq=1024), whereas enabling gradient checkpointing holds peak VRAM flat at 6.84–6.95 GB acrossp=1..4(−62% to −73% VRAM). - 100% musical grammar preservation: Across 126-token (42-event) greedy and sampled rollouts, all pass counts (
p=1..4) maintain 100.0% valid(time, duration, note)triplets and 100.0% monotonic arrival times. - Gating prevents multi-pass collapse: Over 8 passes, naive weight-tied looping (
plain) blows up hidden norms 3.82× (25.1 → 95.9,KL = 2.25, top-1 drops to65.8%), whereas defaultgated(gate_init_bias=-2.0) keeps norms bounded (33.1,KL = 0.042,98.1%top-1) andinjectconverges to a fixed point (27.3,KL = 0.0038,98.8%top-1).
Detailed Benchmarks vs. Original (stanford-crfm/music-large-800k)
1. Prefill Scaling Across Batch Sizes & Sequence Lengths (bfloat16, use_cache=False)
Measured over 10 timed iterations (after 3 warmup iterations) with isolated GPU memory:
Batch Size 1 (Interactive / Single-Stream)
| Model / Passes | Eff. Layers | Seq 128 (ms / tok/s) | Seq 256 (ms / tok/s) | Seq 512 (ms / tok/s) | Seq 1024 (ms / tok/s) | Peak VRAM @ 1024 |
|---|---|---|---|---|---|---|
Original (GPT2LMHeadModel) | 36 | 15.76 / 8,123 | 19.88 / 12,878 | 46.03 / 11,123 | 124.23 / 8,243 | 4,703 MB |
Looped (p=1) | 36 (1.0×) | 15.88 / 8,058 | 20.24 / 12,646 | 45.49 / 11,256 | 127.87 / 8,008 | 4,732 MB |
Looped (p=2, default) | 54 (1.5×) | 23.36 / 5,480 | 29.63 / 8,639 | 68.89 / 7,432 | 185.60 / 5,517 | 4,730 MB |
Looped (p=3) | 72 (2.0×) | 30.61 / 4,181 | 39.11 / 6,546 | 89.97 / 5,691 | 250.98 / 4,080 | 4,730 MB |
Looped (p=4) | 90 (2.5×) | 37.42 / 3,420 | 48.37 / 5,292 | 111.72 / 4,583 | 317.09 / 3,229 | 4,730 MB |
Batch Sizes 4 & 8 (Batched Scoring / Offline Processing)
| Model / Passes | bs=4, s=512 (ms / tok/s) | bs=4, s=1024 (ms / tok/s) | bs=8, s=512 (ms / tok/s) | bs=8, s=1024 (ms / tok/s) | Rel. Speed @ bs=8, s=1024 | Peak VRAM @ bs=8, s=1024 |
|---|---|---|---|---|---|---|
| Original | 268.57 / 7,626 | 569.00 / 7,199 | 574.08 / 7,135 | 787.65 / 10,401 | 1.00× | 5,486 MB |
Looped (p=1) | 273.17 / 7,497 | 581.51 / 7,044 | 577.96 / 7,087 | 794.55 / 10,310 | 0.99× | 5,516 MB |
Looped (p=2) | 408.62 / 5,012 | 863.71 / 4,742 | 863.85 / 4,742 | 1,187.41 / 6,899 | 0.66× | 5,515 MB |
Looped (p=3) | 546.22 / 3,749 | 1,148.94 / 3,565 | 1,146.99 / 3,571 | 1,574.11 / 5,204 | 0.50× | 5,515 MB |
Looped (p=4) | 680.01 / 3,012 | 1,434.83 / 2,855 | 1,434.01 / 2,856 | 1,969.82 / 4,159 | 0.40× | 5,515 MB |
Prefill latency scales almost ideally with effective depth (18 + 18 × num_passes) / 36 (1.00×, 1.50×, 2.00×, 2.50×), with zero additional peak VRAM for extra passes.
2. Autoregressive Decode Scaling Across Context Lengths & Batch Sizes (bfloat16, use_cache=True)
AMT represents each musical event as a 3-token triplet (arrival_time, duration, note). The RT Factor column measures per-stream speed relative to real-time playback at 10 events/sec (30 tok/s).
Single-Stream Decode (batch_size=1)
| Model / Passes | Short 64→128 (ITL / tok/s) | Med 256→320 (ITL / tok/s) | Long 512→576 (ITL / tok/s) | Full Context 896→1024 (TTFT / ITL / tok/s) | RT Factor @ 1024 | KV Cache @ 1024 | Peak VRAM @ 1024 |
|---|---|---|---|---|---|---|---|
| Original | 10.38 ms / 96.3 | 10.86 ms / 92.1 | 11.32 ms / 88.4 | 151.2 ms / 12.08 ms / 82.8 | 2.76× | 180.0 MB (36L) | 4,835 MB |
Looped (p=1) | 10.40 ms / 96.2 | 10.89 ms / 91.8 | 11.35 ms / 88.1 | 150.4 ms / 12.19 ms / 82.1 | 2.74× | 180.0 MB (36L) | 4,865 MB |
Looped (p=2) | 15.19 ms / 65.8 | 15.95 ms / 62.7 | 16.65 ms / 60.0 | 197.0 ms / 17.76 ms / 56.3 | 1.88× | 270.0 MB (54L) | 4,951 MB |
Looped (p=3) | 19.94 ms / 50.2 | 20.89 ms / 47.9 | 21.90 ms / 45.7 | 249.8 ms / 23.40 ms / 42.7 | 1.42× | 360.0 MB (72L) | 5,032 MB |
Looped (p=4) | 24.73 ms / 40.4 | 25.96 ms / 38.5 | 27.18 ms / 36.8 | 312.8 ms / 29.03 ms / 34.4 | 1.15× | 450.0 MB (90L) | 5,111 MB |
Batched Decode (batch_size=4, 64 new tokens per stream)
| Model / Passes | bs=4, 256→320 Total tok/s (Per-Stream) | bs=4, 512→576 Total tok/s (Per-Stream) | RT Factor @ 512→576 | KV Cache @ 512→576 | Peak VRAM @ 512→576 |
|---|---|---|---|---|---|
| Original | 268.4 (67.1) | 231.2 (57.8) | 1.93× | 405.0 MB | 5,178 MB |
Looped (p=1) | 267.5 (66.9) | 230.8 (57.7) | 1.92× | 405.0 MB | 5,207 MB |
Looped (p=2) | 180.7 (45.2) | 156.0 (39.0) | 1.30× | 607.5 MB | 5,386 MB |
Looped (p=3) | 137.1 (34.3) | 117.6 (29.4) | 0.98× | 810.0 MB | 5,565 MB |
Looped (p=4) | 109.8 (27.5) | 94.4 (23.6) | 0.79× | 1,012.5 MB | 5,747 MB |
3. Precision Comparison (bfloat16 vs. float16 vs. float32, bs=1)
Prefill measured at seq=512; decode measured at prompt=128 → 64 new tokens:
| Model / Passes | Precision | Prefill 512 (ms / tok/s) | Decode (ITL / tok/s) | Peak VRAM |
|---|---|---|---|---|
| Original | bfloat16 | 45.08 ms / 11,358 | 10.56 ms / 94.7 | 4,650 MB |
| Original | float16 | 42.92 ms / 11,930 | 10.55 ms / 94.7 | 4,650 MB |
| Original | float32 | 88.51 ms / 5,785 | 18.18 ms / 55.0 | 3,191 MB |
Looped (p=1) | bfloat16 | 44.72 ms / 11,448 | 10.67 ms / 93.7 | 4,679 MB |
Looped (p=1) | float16 | 43.77 ms / 11,698 | 10.63 ms / 94.1 | 4,679 MB |
Looped (p=1) | float32 | 88.37 ms / 5,794 | 18.25 ms / 54.8 | 3,220 MB |
Looped (p=2) | bfloat16 | 68.20 ms / 7,507 | 15.48 ms / 64.6 | 4,678 MB |
Looped (p=2) | float16 | 63.45 ms / 8,069 | 15.48 ms / 64.6 | 4,678 MB |
Looped (p=2) | float32 | 128.96 ms / 3,970 | 26.85 ms / 37.2 | 3,220 MB |
(Note: float32 shows lower peak VRAM than autocast because autocast retains bf16/fp16 cast copies alongside fp32 master weights during inference; loading directly in torch_dtype=torch.bfloat16 cuts weight memory in half to ~1.56 GB.)
4. Continued-Training Step Benchmark (Forward + Backward, bfloat16)
Crucial for fixed-pass or variable-loop continued training (5 timed steps after 2 warmup steps, full parameter gradients):
| Model / Passes | bs=2, s=512 (ms / tok/s / VRAM) | bs=4, s=512 (ms / tok/s / VRAM) | bs=2, s=1024 No Ckpt (ms / tok/s / VRAM) | bs=2, s=1024 Grad Ckpt (ms / tok/s / VRAM) |
|---|---|---|---|---|
| Original | 360.6 ms / 2,840 / 9.26 GB | 716.6 ms / 2,858 / 13.89 GB | 722.9 ms / 2,833 / 13.89 GB | 995.1 ms / 2,058 / 6.60 GB |
Looped (p=1) | 365.2 ms / 2,804 / 9.50 GB | 712.4 ms / 2,875 / 14.13 GB | 719.8 ms / 2,845 / 14.13 GB | 990.3 ms / 2,068 / 6.84 GB |
Looped (p=2) | 510.3 ms / 2,007 / 11.46 GB | 1,047.0 ms / 1,956 / 18.04 GB | 1,051.3 ms / 1,948 / 18.03 GB | 1,447.1 ms / 1,415 / 6.84 GB |
Looped (p=3) | 677.0 ms / 1,513 / 13.41 GB | 1,373.1 ms / 1,492 / 21.94 GB | 1,367.6 ms / 1,498 / 21.94 GB | 1,906.2 ms / 1,074 / 6.84 GB |
Looped (p=4) | 833.3 ms / 1,229 / 15.37 GB | 1,710.6 ms / 1,197 / 25.84 GB | 1,719.3 ms / 1,191 / 25.84 GB | 2,360.1 ms / 868 / 6.95 GB |
Key takeaway: With gradient checkpointing enabled (model.gradient_checkpointing_enable()), continued training of 54–90 effective layers fits in < 7 GB VRAM (a 62–73% reduction vs. uncheckpointed), enabling variable-loop training on a single 12–16 GB GPU.
5. Zero-Shot Musical Quality & Per-Token-Type Sensitivity Across 4 AMT Regimes (float32)
Evaluated across 4 distinct symbolic music regimes (4 sequences × 241 tokens = 964 tokens per regime, 3,856 tokens total), before any continued training:
| Musical Regime | num_passes | max_abs_diff | KL(orig ‖ looped) | Top-1 Agree | Top-5 Agree | Base NLL → Looped NLL | Cos Sim to p=1 |
|---|---|---|---|---|---|---|---|
| Monophonic Melody | 1 | 0.00e+00 | 0.00000 | 100.00% | 100.00% | 0.6610 → 0.6610 | 1.0000 |
| 2 | 1.553 | 0.00095 | 98.76% | 100.00% | 0.6610 → 0.6631 | 0.9982 | |
| 3 | 3.833 | 0.00391 | 98.24% | 99.59% | 0.6610 → 0.6670 | 0.9935 | |
| 4 | 6.071 | 0.01152 | 97.20% | 99.59% | 0.6610 → 0.6760 | 0.9866 | |
| Polyphonic Ensemble (piano + bass + strings + drums) | 1 | 0.00e+00 | 0.00000 | 100.00% | 100.00% | 0.4093 → 0.4093 | 1.0000 |
| 2 | 1.249 | 0.00041 | 99.79% | 100.00% | 0.4093 → 0.4086 | 0.9983 | |
| 3 | 3.290 | 0.00165 | 98.86% | 99.59% | 0.4093 → 0.4089 | 0.9937 | |
| 4 | 5.921 | 0.00517 | 98.55% | 99.59% | 0.4093 → 0.4113 | 0.9869 | |
| Dense Arpeggios (100 ms 16th-note grid) | 1 | 0.00e+00 | 0.00000 | 100.00% | 100.00% | 0.3099 → 0.3099 | 1.0000 |
| 2 | 1.185 | 0.00040 | 100.00% | 100.00% | 0.3099 → 0.3107 | 0.9984 | |
| 3 | 2.502 | 0.00180 | 100.00% | 100.00% | 0.3099 → 0.3129 | 0.9943 | |
| 4 | 3.648 | 0.00448 | 99.48% | 99.59% | 0.3099 → 0.3169 | 0.9883 | |
| Anticipatory Conditioned (interleaved control + event) | 1 | 0.00e+00 | 0.00000 | 100.00% | 100.00% | 3.7868 → 3.7868 | 1.0000 |
| 2 | 2.457 | 0.01190 | 96.99% | 100.00% | 3.7868 → 3.8101 | 0.9980 | |
| 3 | 5.081 | 0.04569 | 93.98% | 99.07% | 3.7868 → 3.8330 | 0.9927 | |
| 4 | 7.440 | 0.09425 | 91.80% | 98.44% | 3.7868 → 3.8606 | 0.9851 |
Per-Token-Type Breakdown at Default num_passes=2
| Regime | Token Type | Base NLL | Looped (p=2) NLL | KL(orig ‖ looped) | Top-1 Agreement |
|---|---|---|---|---|---|
| Polyphonic Ensemble | Arrival Time (0..9999) | 0.3257 | 0.3227 | 0.00050 | 99.69% |
Duration (10000..10999) | 0.3623 | 0.3603 | 0.00041 | 99.69% | |
Note (11000..27511) | 0.5400 | 0.5429 | 0.00029 | 100.00% | |
| Anticipatory Conditioned | Arrival Time (0..9999) | 7.9020 | 7.7870 | 0.05955 | 87.50% |
Duration (10000..10999) | 0.2687 | 0.2642 | 0.00066 | 100.00% | |
Note (11000..27511) | 1.2158 | 1.2034 | 0.00052 | 98.75% | |
Control (27512..55023) | 4.4449 | 4.5354 | 0.00360 | 98.54% |
6. Autoregressive Rollout Comparison (4 Prompts × 126 Generated Tokens = 42 Events)
Comparing multi-step generation trajectories (49-token musical prompts → 126 generated tokens) for greedy decoding and nucleus sampling (temperature=1.0, top_p=0.95):
| Model / Passes | Greedy Exact Match vs. Orig | Mean First Divergence Step | Greedy Valid Triplets / Monotonic Time | Greedy Entropy (nats) | Sampled Valid Triplets / Monotonic Time | Sampled Unique Pitches | Sampled Events/s | Sampled Entropy (nats) |
|---|---|---|---|---|---|---|---|---|
| Original | (ref) | (ref) | 100% / 100% | 0.2208 | 100% / 100% | 32 | 7.09 | 0.6059 |
Looped (p=1) | 100.00% | 126 / 126 (none) | 100% / 100% | 0.2208 | 100% / 100% | 32 | 7.09 | 0.6059 |
Looped (p=2) | 99.80% | 125 / 126 | 100% / 100% | 0.2212 | 100% / 100% | 29 | 5.87 | 0.4106 |
Looped (p=3) | 94.05% | 94 / 126 | 100% / 100% | 0.2866 | 100% / 100% | 28 | 5.87 | 0.4174 |
Looped (p=4) | 93.45% | 94 / 126 | 100% / 100% | 0.2926 | 100% / 100% | 28 | 5.62 | 0.3763 |
At default num_passes=2, 3 of 4 prompts produce 100% identical 126-token greedy continuations to stanford-crfm/music-large-800k, and the 4th matches for the first 122 tokens. Across all pass counts (p=1..4), AMT triplet grammar and monotonic timestamps remain 100% intact.
7. Carry-Mode & gate_init_bias Stability Sweep Across 8 Passes (Reproducing GLM-5.4 / Louapre 2026)
Comparing carry modes and gate bias initializations on the same pretrained music-large-800k weights over 8 core passes (polyphonic_ensemble, pass-1 norm = 25.09, base NLL = 0.4093):
| Configuration | Gate g | Pass 1 Norm | Pass 2 Norm | Pass 4 Norm | Pass 6 Norm | Pass 8 Norm | KL @ 8 Passes | Top-1 @ 8 Passes | NLL @ 8 Passes | Cos Sim @ 8 Passes |
|---|---|---|---|---|---|---|---|---|---|---|
gated (bias=-4.0) | 0.018 | 25.09 | 25.24 | 25.55 | 25.87 | 26.18 | 0.00046 | 99.69% | 0.4087 | 0.9981 |
gated (bias=-2.0, default) | 0.119 | 25.09 | 26.14 | 28.36 | 30.68 | 33.06 | 0.04217 | 98.13% | 0.4393 | 0.9486 |
gated (bias=-1.0) | 0.269 | 25.09 | 27.58 | 32.91 | 38.40 | 43.87 | 0.29455 | 89.32% | 0.6578 | 0.8561 |
gated (bias=0.0) | 0.500 | 25.09 | 30.00 | 40.28 | 50.39 | 60.29 | 1.12323 | 74.27% | 1.4580 | 0.7461 |
inject (bias=-2.0, Inkling) | 0.119 | 25.09 | 27.07 | 27.29 | 27.29 | 27.29 | 0.00381 | 98.76% | 0.4110 | 0.9902 |
plain (naive weight-tied) | — | 25.09 | 35.88 | 56.16 | 75.99 | 95.93 | 2.24649 | 65.77% | 2.5870 | 0.6091 |
Without gating (plain), hidden-state norms grow 3.82× over 8 passes and next-token predictions collapse (KL = 2.25, NLL = 2.59), directly reproducing the activation norm blow-up reported for GLM-5.4 and Louapre (2026). Both gated (bias=-2.0) and inject keep norms tightly controlled, with inject converging to a stable fixed point (27.29) by pass 5.
Usage
Loading directly from Hugging Face Hub
import torch
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(
"DangerLabs/music-large-800k-looped",
trust_remote_code=True,
torch_dtype=torch.bfloat16,
).cuda().eval()
# Example AMT arrival-time sequence: [z=0 (55025), (time, dur, note), ...]
input_ids = torch.tensor(
[[55025, 0, 10050, 11060, 50, 10040, 11064, 100, 10050, 11067]],
device="cuda",
)
# Default 2 passes (54 effective layers) with loop diagnostics
out = model(input_ids, return_loop_trace=True)
print("Pass norms:", out.loop_trace["pass_norms"])
print("Gate means:", out.loop_trace["gate_means"])
# Override passes at test time (1 = exact original stanford-crfm/music-large-800k)
out_p1 = model(input_ids, num_passes=1)
out_p3 = model(input_ids, num_passes=3)
# Autoregressive generation with isolated per-pass KV caches
generated = model.generate(
input_ids,
max_new_tokens=30,
do_sample=True,
top_p=0.95,
use_cache=True,
)
Continued Training Recommendations
To unlock long-range musical structure and harmonic planning gains from extra passes (as in GLM-5.4 and Inkling's variable-loop training):
- Enable gradient checkpointing (
model.gradient_checkpointing_enable()) to keep VRAM flat (~6.8 GB atbs=2, seq=1024) regardless ofnum_passes. - Fixed-pass continued training: Keep
num_passes=2(or3) withcarry_mode="gated"and train on Lakh MIDI arrival-time / anticipatory sequences. - Variable-loop training: Sample
num_passes ~ Uniform(1, 4)per step during continued training so the model learns an iterative refinement procedure that generalizes across test-time pass counts.
Citations
@article{thickstun2024anticipatory,
title={Anticipatory Music Transformer},
author={Thickstun, John and Hall, David and Donahue, Chris and Liang, Percy},
journal={Transactions on Machine Learning Research},
year={2024},
url={https://arxiv.org/abs/2306.08620}
}
@misc{louapre2026_looped_transformers,
title={Looped Transformers: Thinking twice with the same weights},
author={Louapre, David},
year={2026},
howpublished={\url{https://huggingface.co/spaces/dlouapre/looped-transformers}}
}