Views
No views yet
google/magenta-realtime-2
(MRT2), an open-weights real-time music-generation model from Google DeepMind. This repo
re-packages the MRT2 components as ONNX graphs that run with
onnxruntime on CPU, CUDA GPU, and the web
(onnxruntime-web or
jax-js) — no JAX, TensorFlow, or Apple-MLX runtime required.Unofficial community export by @blanchon. All model weights © Google LLC, redistributed under CC-BY-4.0 (see License & terms below). Converted from the originalgoogle/magenta-realtime-2artifacts.
| Component | Role | This repo |
|---|---|---|
| MusicCoCa | text / audio → 768-d style embedding → 12 RVQ style tokens | musiccoca/*.onnx |
| SpectroStream | 48 kHz stereo audio codec (encode ↔ 12-RVQ tokens ↔ decode) | spectrostream/*.onnx |
| Depthformer LLM | autoregressive frame-wise generator of audio tokens (style + MIDI + context → tokens) | mrt2_small/onnx/ (230M, fp32) |
musiccoca/ # style model (5 ONNX graphs + SentencePiece)
text_encoder.onnx audio_preprocessor.onnx music_encoder.onnx
pretrained_vector_quantizer.onnx mapper.onnx spm.model
spectrostream/ # audio codec
encoder.onnx decoder.onnx
mrt2_small/onnx/ # 230M Depthformer LLM, self-contained fp32 graphs
encoder.onnx temporal_step.onnx depth_step.onnx embed.onnx.onnx here is a single self-contained file (no external .onnx.data).encoder.onnx,
temporal_step.onnx, depth_step.onnx, embed.onnx — driven by a thin host-side runtime
loop that carries the fixed-size windowed KV-cache between frames and does sampling
host-side. For each 25 Hz frame the temporal step runs once, then the depth step + embed run
once per RVQ level (12) to emit the 12 codes for that frame. A complete, readable reference
implementation of this loop is src/lib/mrt2.ts in the
demo Space (jax-js).1import onnxruntime as ort, numpy as np
2# Each graph is provider-agnostic — CPU here, or CUDA / web elsewhere.
3sess = ort.InferenceSession("musiccoca/pretrained_vector_quantizer.onnx",
4 providers=["CPUExecutionProvider"]) # ["CUDAExecutionProvider", ...] for GPU
5emb = np.zeros((1, 768), np.float32)
6tokens = sess.run(None, {sess.get_inputs()[0].name: emb})[0] # 12 RVQ style tokens
7print(tokens)1<script type="module">
2import * as ort from "https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.all.min.mjs";
3const sess = await ort.InferenceSession.create("musiccoca/pretrained_vector_quantizer.onnx",
4 { executionProviders: ["webgpu", "wasm"] });
5const emb = new ort.Tensor("float32", new Float32Array(768), [1, 768]);
6const out = await sess.run({ [sess.inputNames[0]]: emb });
7console.log(out[sess.outputNames[0]].data); // 12 RVQ style tokens
8</script>| Component | vs original |
|---|---|
| MusicCoCa (text → style tokens) | token-exact |
| SpectroStream codec | codes exact, decode ≤ 9e-5 |
| Depthformer LLM (small, fp32) | codes exact (PyTorch & ONNX, in-browser) |
| Full pipeline (prompt → audio) | codes exact vs JAX fp32 |
tf2onnx (added FULLY_CONNECTED keep_num_dims,
GELU, EMBEDDING_LOOKUP handlers), and the log-mel STFT RFFT/ComplexAbs island was
replaced with an equivalent DFT cos/sin matmul so it uses only ONNX-standard,
web-compatible ops.sequence-layers/JAX graphs do not lower
cleanly through jax2tf (opaque XlaCallModule) or jax2onnx (shape-tracing limits), so
these were reimplemented in PyTorch from the architecture and checkpoint weights, validated
numerically against the JAX reference, and exported with torch.onnx.1@inproceedings{gdmlyria2025live,
2 title={Live Music Models},
3 author={Caillon, Antoine and others},
4 booktitle={NeurIPS Creative AI}, year={2025}
5}