MIO and Any-to-Any Streaming Multimodal Models
GPT-4o ships something most open models could not match: an agent that hears voice, sees video, and speaks back in real time. The open answer by late 2024 was MIO (Wang et al., September 2024). It tokenizes text, image, speech, and music, trains one causal transformer over the interleaved sequences, and generates any modality from any other. AnyGPT (Zhan et al., February 2024) was the proof of concept, MIO is the scale-up, and Unified-IO 2 (Allen AI, December 2023) is the cousin with vision and action grounding. This lesson reads the any-to-any pattern: four tokenizers, one transformer, streaming-friendly decode.
Learning Objectives
- Design a shared vocabulary that hosts text, image, speech, and music tokens without collisions.
- Compare SEED-Tokenizer (images) and SpeechTokenizer residual-VQ (speech) on compression + reconstruction trade-offs.
- Explain the four-stage curriculum that builds up any-to-any generation.
- Name the three open any-to-any recipes and their main trade-offs: MIO, AnyGPT, Unified-IO 2.
The Problem
A unified multimodal model is easy to claim and hard to build at scale. Most "any-to-any" systems until 2024 were pipelined: vision model → text representation → speech model → audio. Each hop loses information, adds latency, and makes training harder. GPT-4o's demo video showed a single-model alternative with subsecond response; open systems trailed by months.
The engineering challenges:
- You need a tokenizer per modality. It has to compress well enough to save compute, reconstruct well enough to sound or look right, and emit tokens at a rate the transformer can consume.
- A single vocabulary must allocate space for text (32k+), image (16k+), speech (4k+), music (8k+). Forty-thousand-plus entries minimum.
- Training data has to cover the input-output pairs you care about (text→image, image→speech, speech→image, and so on), or the model has to compose them.
- Inference must stream output tokens fast enough for conversational latency (<500ms time-to-first-audio-byte).
The Concept
Four tokenizers for four modalities
MIO's tokenizer stack:
- Text: standard BPE, vocab ~32000.
- Image: SEED-Tokenizer (2023), a quantized VAE with a discrete codebook, 4096 entries, 32x32 tokens per image.
- Speech: SpeechTokenizer residual-VQ (2023). It encodes a 16kHz waveform into 8 hierarchical codebooks. The first level is coarse content, and later levels add prosody and speaker identity.
- Music: similar residual-VQ (Meta's MusicGen / Encodec family), 4-8 codebooks.
Each modality produces integer tokens, and each gets a disjoint ID range in the shared vocabulary:
text: 0..31999
image: 32000..36095 (4096 image tokens)
speech: 36096..40191 (4096 speech base tokens, plus residual layers)
music: 40192..48383 (8192 music tokens)
sep: 48384..48389 (<image>, <speech>, <music>, </...>, etc.)
Total: ~48k vocabulary. The table counts only the base speech tokens, so main.py, which also reserves a slot for speech layers 1..7, prints 52486. The input embedding and output projection span all of it.
Streaming decode
Speech generation uses residual-VQ. The transformer predicts the base (layer 0) speech tokens; a parallel-decoded residual quantizer predicts the subsequent layers. Each layer 0 token is roughly 50ms of audio at 16kHz.
The streaming pattern:
- User speaks into mic; real-time audio tokenizer emits speech tokens every 50ms.
- MIO consumes tokens as they arrive (prompt prefill + incremental forward).
- Output tokens stream out as generated; a parallel speech decoder converts them to audio samples with ~50-150ms latency.
- Time-to-first-audio-byte: ~300-500ms in MIO paper, approaching GPT-4o's ~250ms.
Mini-Omni (arXiv:2408.16725), GLM-4-Voice (arXiv:2412.02612), and Moshi (arXiv:2410.00037) are complementary streaming speech-LLM designs. Moshi in particular achieves 160ms round-trip on a single GPU.
Four-stage curriculum
MIO's training curriculum:
- Stage 1: alignment. Large-scale modality-pair corpora: text-image, text-speech, text-music. Each pair uses its own token vocabulary segment. Trains the shared vocabulary.
- Stage 2: interleaved. Multi-modality interleaved documents (blogs with images + video, podcasts with transcripts, etc.). Trains cross-modality context.
- Stage 3: speech-enhanced. Extra audio data to lift speech quality without losing text capability.
- Stage 4: SFT. Instruction tuning across modalities: VQA, captioning, narration, speech-to-speech dialogue.
Skipping a stage hurts specific capabilities. Without stage 2 the model loses cross-modality context, and without stage 3 speech is poor.
Chain-of-visual-thought
MIO introduces chain-of-visual-thought: the model emits intermediate image tokens as a reasoning step. For "is the cat climbing a tree?" the model:
- Emits
<image>tokens rendering the scene (from the input image or a sketch). - Emits text analyzing the sketch.
- Emits the final answer.
The rendered intermediate image serves as a scratchpad. Benchmarks improve on spatial-reasoning tasks. The idea mirrors chain-of-thought for text reasoning.
Competitors in any-to-any
- AnyGPT (arXiv:2402.12226): 4 modalities (text, image, speech, music), similar design.
- Unified-IO 2 (arXiv:2312.17172): adds vision action outputs, depth, normals. More task diversity, smaller scale.
- NExT-GPT (arXiv:2309.05519): LLM + modality-specific diffusion decoders. Not a single-model approach.
- CoDi (arXiv:2305.11846): composable diffusion; any-to-any via shared latent.
MIO is the closest to pure-token any-to-any. AnyGPT is its conceptual ancestor.
Latency budget
For a conversational product, each component adds to the total:
- Mic to audio tokens: ~50ms.
- Prefill (audio tokens + history): ~100ms on an 8B model.
- First output token: ~50ms.
- Parallel residual-VQ + speech decoder: ~100-150ms.
Total time-to-first-audio-byte: ~300ms minimum. GPT-4o claims ~250ms. Moshi claims 160ms. MIO/AnyGPT are in the 400-600ms range per public benchmarks.
Why any-to-any stays hard
Even in 2026, open any-to-any models trail closed ones on two fronts:
- Speech quality. The residual-VQ tokenizer is lossy; conversational speech sounds robotic compared to ElevenLabs-class voices.
- Cross-modality reasoning. Asking the model "sing about what you see" still fails more often than pure-vision tasks.
Both are open research problems. Qwen3-Omni (Lesson 12.20) is the most advanced open attempt in 2025.
Use It
code/main.py:
- Defines the four-modality vocabulary allocation and prints it.
- Routes a list of multimodal inputs (text, image, audio-clip, music) through the tokenizer router.
- Simulates streaming decode for a text-to-speech response with latency counting.
- Computes the expected time-to-first-audio-byte given encoder, prefill, and decoder latencies.
Ship It
This lesson produces outputs/skill-any-to-any-pipeline-auditor.md. Given a conversational product spec (modalities in, modalities out, latency target), it audits the MIO-family design choices and computes the latency budget.
I'd run main.py and read the vocabulary table it prints before anything else. It lays out the shared ID space slot by slot (text BPE, SEED image tokens, speech, music, then six separator tokens), so you can see that each modality gets a disjoint range and that the embedding matrix has to span all of it. The total it prints is 52486, not the ~48k in the table above. The code gives speech L1..L7 its own 4096-entry slot, and the table counts only the base speech tokens, so treat the table as a sketch and the printout as the arithmetic.
The latency trace is worth tweaking by hand. With the defaults (2 seconds of prompt audio, an 8B model) it sums to 270 ms: 40 for mic to tokens, 80 for prefill, 40 for the first output token, 30 for residual-VQ layers 1..7, and 80 for the speech decoder. Those are constants and linear scalings I'd call plausible, not measurements, and 270 ms sits below the ~300 ms floor quoted in the Concept section. Change model_size_b and watch which terms move. Only prefill and first-token scale with model size, which tells you where a bigger model hurts.
Keep the toy in proportion. The router is an if/else on a kind string that returns a tokenizer name, and the chain-of-visual-thought demo prints four fixed steps. Neither runs a tokenizer or a transformer. If you want to learn how any-to-any behaves, read the MIO paper next, and treat this file as a way to get the budget and the ID layout straight.
Exercises
-
Your product accepts speech input and returns speech output. What's the end-to-end latency budget target? List the components that spend time.
-
SpeechTokenizer residual-VQ uses 8 codebooks. Propose why parallel-decoding the residual levels is necessary (vs sequential) and what latency savings it brings.
-
Your vocabulary has 32k text + 4k image + 4k speech. Add 8k music and ~10 separators. What is the embedding-matrix parameter cost at hidden dim 4096?
-
Chain-of-visual-thought emits an intermediate image. What kinds of questions benefit? What kinds are hurt by the extra tokens?
-
Read Moshi (arXiv:2410.00037). Describe its "inner monologue" technique and compare to MIO's chain-of-visual-thought.
Key Terms
| Term | What people say | What it actually means |
|---|---|---|
| Any-to-any | "Multimodal in/out" | A single model that accepts and emits text, image, speech, and music in any direction |
| Residual-VQ | "Speech tokenizer stack" | Multi-codebook tokenization where each layer adds information; base layer is content, later layers are prosody |
| SEED-Tokenizer | "Image codes" | Discrete image tokenizer with 4096-entry codebook used by MIO |
| Chain-of-visual-thought | "Visual scratchpad" | The model generates an intermediate image as a reasoning step before its final answer |
| Time-to-first-audio-byte | "TTFAB" | Latency from user voice to first audio output; <500ms for conversational feel |
| Four-stage curriculum | "Training recipe" | Alignment -> interleaved -> speech-enhanced -> SFT, in that order |
Code
- main.py (python, 158 lines)