Image-Text-to-Text
Transformers
Safetensors
mage_vl
multimodal
vision-language-model
mage-vl
video-understanding
streaming
conversational
custom_code
Instructions to use microsoft/Mage-VL with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Mage-VL with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="microsoft/Mage-VL", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoModelForImageTextToText model = AutoModelForImageTextToText.from_pretrained("microsoft/Mage-VL", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use microsoft/Mage-VL with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/Mage-VL" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Mage-VL", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/microsoft/Mage-VL
- SGLang
How to use microsoft/Mage-VL with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "microsoft/Mage-VL" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Mage-VL", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "microsoft/Mage-VL" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Mage-VL", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use microsoft/Mage-VL with Docker Model Runner:
docker model run hf.co/microsoft/Mage-VL
docs: update citation (yang2026mage, arXiv:2607.24904)
Browse files
README.md
CHANGED
|
@@ -14,7 +14,7 @@ tags:
|
|
| 14 |
|
| 15 |
<p align="center">
|
| 16 |
<a href="https://microsoft.github.io/Mage"><img alt="Project Page" src="https://img.shields.io/badge/%F0%9F%8C%90-Project%20Page-blue" height="22" /></a>
|
| 17 |
-
<a href="https://
|
| 18 |
<a href="https://github.com/microsoft/Mage"><img src="https://img.shields.io/badge/Code-GitHub-181717?logo=github" alt="GitHub" height="22"></a>
|
| 19 |
<a href="https://huggingface.co/microsoft/Mage-VL"><img alt="Mage-VL" src="https://img.shields.io/badge/%F0%9F%A4%97-Mage--VL-yellow" height="22" /></a>
|
| 20 |
<a href="https://huggingface.co/microsoft/Mage-ViT"><img alt="Mage-ViT" src="https://img.shields.io/badge/%F0%9F%A4%97-Mage--ViT-yellow" height="22" /></a>
|
|
@@ -40,6 +40,7 @@ On top of this pair, a **System 1 & System 2 dual-process design** adds proactiv
|
|
| 40 |
|
| 41 |
- **Codec-native & from scratch.** The entire visual stack is trained from scratch — no billion-scale image-text ViT initialization. The bio-inspired predictive-patch mechanism (I/P frames at `16×16`) cuts visual-token consumption by **over 75%** (**~1/8 or less** of dense frame sampling), letting the model train on videos **8× longer** under the same budget.
|
| 42 |
- **Codec-native speedup.** Codec tokenization sets a superior accuracy–efficiency frontier — **up to 3.5× wall-clock inference speedup** over uniform frame sampling at matched accuracy, and the fastest of all compared models on most video benchmarks (single 8×B200 node).
|
|
|
|
| 43 |
- **Native-resolution scaling.** Variable-resolution pretraining lets Mage-ViT improve *monotonically* with the token budget (peaking **>96.1% Food-101 / >86.3% ImageNet** at 676 tokens) where fixed-resolution encoders saturate or degrade.
|
| 44 |
- **Matched-LLM video gains.** With the 4B Qwen3 backbone held fixed and only the ViT swapped, Mage-VL improves over Qwen3-VL-4B on **every** reported video and temporal-grounding benchmark — largest on localization-heavy tasks (**+22.5 QVHighlight**, +17.1 ActivityNet, +11.0 VSI-Bench, +24.5 VideoEval-Pro).
|
| 45 |
- **Strong for its size.** On par with Qwen3-VL-4B on static images, and clearly ahead on video understanding and spatial intelligence (**+11.0** VSI-Bench, **+53.1** CrossPoint, **+5.2** EmbSpatial, **+22.5** QVHighlight).
|
|
@@ -49,7 +50,7 @@ On top of this pair, a **System 1 & System 2 dual-process design** adds proactiv
|
|
| 49 |
|
| 50 |
A **single checkpoint**, `microsoft/Mage-VL`, is one unified model that **simultaneously** provides image & video understanding **and** the proactive streaming gate — the same weights answer offline image/video questions and drive event-gated commentary. It covers every Mage-VL capability: image understanding, frame-sampled video, traditional H.264/HEVC codec video, neural DCVC-RT codec video, and event-gated streaming. The repository bundles the codec processor, the neural codec package, and the proactive gate weights — no separate understanding, NVC, or streaming checkpoint is required.
|
| 51 |
|
| 52 |
-
We additionally release **`microsoft/Mage-ViT`** — the standalone visual encoder from the two-stage, from-scratch ViT pre-training. This is the **ViT-pre-trained checkpoint only**: it has **not** gone through the joint VLM training with the language model. Use it as a data-efficient, codec-native visual encoder or as a drop-in ViT for your own multimodal training.
|
| 53 |
|
| 54 |
| Model | Task | Backbone | Hugging Face |
|
| 55 |
| :--- | :--- | :--- | :--- |
|
|
@@ -187,7 +188,7 @@ JoyAI's high TriggerAcc comes from predicting silence almost everywhere under So
|
|
| 187 |
|
| 188 |
Beyond the model, the report distills **seven empirical findings** for efficient multimodal training:
|
| 189 |
|
| 190 |
-
1. **
|
| 191 |
2. **Variable-resolution pretraining scales monotonically.** Quality keeps improving with the visual-token budget instead of saturating/degrading like fixed-resolution encoders.
|
| 192 |
3. **Codec-native tokenization sets a better accuracy–efficiency frontier** — up to **3.5× wall-clock inference speedup** over uniform frame sampling.
|
| 193 |
4. **Explicit VideoQA SFT is redundant.** Dense video *captions* + standard image SFT are sufficient for strong zero-shot VideoQA.
|
|
@@ -219,84 +220,6 @@ pip install "transformers>=5.7" accelerate pillow torch torchvision \
|
|
| 219 |
|
| 220 |
Codec-based video inference also requires `ffmpeg` and `ffprobe` on `PATH`.
|
| 221 |
|
| 222 |
-
### Using 🤗 Transformers directly
|
| 223 |
-
|
| 224 |
-
Mage-VL ships its modeling, processing, and chat-template code inside this repository, so image and frame-sampled video inference need **no script download and no extra package** beyond `transformers`:
|
| 225 |
-
|
| 226 |
-
```python
|
| 227 |
-
import torch
|
| 228 |
-
from PIL import Image
|
| 229 |
-
from transformers import AutoModelForCausalLM, AutoProcessor
|
| 230 |
-
|
| 231 |
-
model_id = "microsoft/Mage-VL"
|
| 232 |
-
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
| 233 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 234 |
-
model_id, trust_remote_code=True, torch_dtype="auto", device_map="auto"
|
| 235 |
-
).eval()
|
| 236 |
-
|
| 237 |
-
messages = [{"role": "user", "content": [
|
| 238 |
-
{"type": "image"},
|
| 239 |
-
{"type": "text", "text": "Describe this image in detail."},
|
| 240 |
-
]}]
|
| 241 |
-
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 242 |
-
|
| 243 |
-
inputs = processor(
|
| 244 |
-
text=[text], images=[Image.open("examples/dog.jpg").convert("RGB")], return_tensors="pt"
|
| 245 |
-
)
|
| 246 |
-
inputs = {k: (v.to(model.device) if hasattr(v, "to") else v) for k, v in inputs.items()}
|
| 247 |
-
inputs["pixel_values"] = inputs["pixel_values"].to(model.dtype)
|
| 248 |
-
|
| 249 |
-
with torch.inference_mode():
|
| 250 |
-
output = model.generate(**inputs, max_new_tokens=256, do_sample=False)
|
| 251 |
-
print(processor.tokenizer.decode(
|
| 252 |
-
output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True
|
| 253 |
-
).strip())
|
| 254 |
-
```
|
| 255 |
-
|
| 256 |
-
> The image depicts a dog sitting on a patterned rug. The dog appears to be a
|
| 257 |
-
> medium-sized breed with a thick, fluffy coat. Its fur is primarily white with
|
| 258 |
-
> patches of black and brown. The dog's ears are perked up, and it has a calm and
|
| 259 |
-
> attentive expression. [...]
|
| 260 |
-
|
| 261 |
-
For video, use `{"type": "video"}` in the message and pass a list of PIL frames as `videos=[frames]`:
|
| 262 |
-
|
| 263 |
-
```python
|
| 264 |
-
import cv2
|
| 265 |
-
import numpy as np
|
| 266 |
-
from PIL import Image
|
| 267 |
-
|
| 268 |
-
def sample_video(path, num_frames=32):
|
| 269 |
-
capture = cv2.VideoCapture(path)
|
| 270 |
-
total = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 271 |
-
frames = []
|
| 272 |
-
for index in np.linspace(0, total - 1, min(num_frames, total), dtype=int):
|
| 273 |
-
capture.set(cv2.CAP_PROP_POS_FRAMES, int(index))
|
| 274 |
-
ok, frame = capture.read()
|
| 275 |
-
if ok:
|
| 276 |
-
frames.append(Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)))
|
| 277 |
-
capture.release()
|
| 278 |
-
return frames
|
| 279 |
-
|
| 280 |
-
messages = [{"role": "user", "content": [
|
| 281 |
-
{"type": "video"},
|
| 282 |
-
{"type": "text", "text": "Describe this video."},
|
| 283 |
-
]}]
|
| 284 |
-
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 285 |
-
|
| 286 |
-
inputs = processor(
|
| 287 |
-
text=[text],
|
| 288 |
-
videos=[sample_video("examples/soccer-broadcast.mp4", 32)],
|
| 289 |
-
return_tensors="pt",
|
| 290 |
-
padding=True,
|
| 291 |
-
)
|
| 292 |
-
```
|
| 293 |
-
|
| 294 |
-
> The video opens with a man in a black polo shirt, sporting a short haircut,
|
| 295 |
-
> standing in a stadium. He is holding a yellow microphone with the BBC Sport
|
| 296 |
-
> logo on it. The background reveals a large crowd of spectators. [...]
|
| 297 |
-
|
| 298 |
-
Add `attn_implementation="sdpa"` to `from_pretrained` if `flash-attn` is not installed. Codec-based video (H.264/HEVC, DCVC-RT) and streaming commentary use [`inference.py`](inference.py) below.
|
| 299 |
-
|
| 300 |
### Examples
|
| 301 |
|
| 302 |
Two sample inputs ship with this repository:
|
|
@@ -413,9 +336,9 @@ The gate is trained on codec inputs, so `--video_backend codec` is the intended
|
|
| 413 |
## 📝 Citation
|
| 414 |
|
| 415 |
```bibtex
|
| 416 |
-
@article{
|
| 417 |
title={Mage-VL: An Efficient Codec-Native Streaming Multimodal Foundation Model},
|
| 418 |
-
author={Yang, Senqiao and Zhang, Kaichen and Jia, Zhaoyang and Guo, Jinghao and Shen, Yifei and Zhang, Xinjie and Zhang, Xiaoyi and Wang, Haoqing and Li, Xiao and
|
| 419 |
journal={arXiv preprint arXiv:2607.24904},
|
| 420 |
year={2026}
|
| 421 |
}
|
|
|
|
| 14 |
|
| 15 |
<p align="center">
|
| 16 |
<a href="https://microsoft.github.io/Mage"><img alt="Project Page" src="https://img.shields.io/badge/%F0%9F%8C%90-Project%20Page-blue" height="22" /></a>
|
| 17 |
+
<a href="https://github.com/microsoft/Mage/blob/main/assets/mage_vl_tech_report.pdf"><img alt="arXiv" src="https://img.shields.io/badge/arXiv-Mage--VL-b31b1b" height="22" /></a>
|
| 18 |
<a href="https://github.com/microsoft/Mage"><img src="https://img.shields.io/badge/Code-GitHub-181717?logo=github" alt="GitHub" height="22"></a>
|
| 19 |
<a href="https://huggingface.co/microsoft/Mage-VL"><img alt="Mage-VL" src="https://img.shields.io/badge/%F0%9F%A4%97-Mage--VL-yellow" height="22" /></a>
|
| 20 |
<a href="https://huggingface.co/microsoft/Mage-ViT"><img alt="Mage-ViT" src="https://img.shields.io/badge/%F0%9F%A4%97-Mage--ViT-yellow" height="22" /></a>
|
|
|
|
| 40 |
|
| 41 |
- **Codec-native & from scratch.** The entire visual stack is trained from scratch — no billion-scale image-text ViT initialization. The bio-inspired predictive-patch mechanism (I/P frames at `16×16`) cuts visual-token consumption by **over 75%** (**~1/8 or less** of dense frame sampling), letting the model train on videos **8× longer** under the same budget.
|
| 42 |
- **Codec-native speedup.** Codec tokenization sets a superior accuracy–efficiency frontier — **up to 3.5× wall-clock inference speedup** over uniform frame sampling at matched accuracy, and the fastest of all compared models on most video benchmarks (single 8×B200 node).
|
| 43 |
+
- **Data-efficient tokenizer.** Trained on only **~100M unlabeled images/videos**, Mage-ViT matches or beats frontier encoders trained on billions of image-text pairs (SigLIP2 @ 10B, MoonViT @ 2B) — e.g. **99.33% on CIFAR-10** and **85.69% on ImageNet** with 256 tokens, showing web-scale pretraining is *not* essential for a strong VLM front-end.
|
| 44 |
- **Native-resolution scaling.** Variable-resolution pretraining lets Mage-ViT improve *monotonically* with the token budget (peaking **>96.1% Food-101 / >86.3% ImageNet** at 676 tokens) where fixed-resolution encoders saturate or degrade.
|
| 45 |
- **Matched-LLM video gains.** With the 4B Qwen3 backbone held fixed and only the ViT swapped, Mage-VL improves over Qwen3-VL-4B on **every** reported video and temporal-grounding benchmark — largest on localization-heavy tasks (**+22.5 QVHighlight**, +17.1 ActivityNet, +11.0 VSI-Bench, +24.5 VideoEval-Pro).
|
| 46 |
- **Strong for its size.** On par with Qwen3-VL-4B on static images, and clearly ahead on video understanding and spatial intelligence (**+11.0** VSI-Bench, **+53.1** CrossPoint, **+5.2** EmbSpatial, **+22.5** QVHighlight).
|
|
|
|
| 50 |
|
| 51 |
A **single checkpoint**, `microsoft/Mage-VL`, is one unified model that **simultaneously** provides image & video understanding **and** the proactive streaming gate — the same weights answer offline image/video questions and drive event-gated commentary. It covers every Mage-VL capability: image understanding, frame-sampled video, traditional H.264/HEVC codec video, neural DCVC-RT codec video, and event-gated streaming. The repository bundles the codec processor, the neural codec package, and the proactive gate weights — no separate understanding, NVC, or streaming checkpoint is required.
|
| 52 |
|
| 53 |
+
We additionally release **`microsoft/Mage-ViT`** — the standalone visual encoder from the two-stage, from-scratch ViT pre-training (cluster-discrimination on ~100M unlabeled image/video frames). This is the **ViT-pre-trained checkpoint only**: it has **not** gone through the joint VLM training with the language model. Use it as a data-efficient, codec-native visual encoder or as a drop-in ViT for your own multimodal training.
|
| 54 |
|
| 55 |
| Model | Task | Backbone | Hugging Face |
|
| 56 |
| :--- | :--- | :--- | :--- |
|
|
|
|
| 188 |
|
| 189 |
Beyond the model, the report distills **seven empirical findings** for efficient multimodal training:
|
| 190 |
|
| 191 |
+
1. **Web-scale pretraining is not essential.** A from-scratch backbone on ~100M unlabeled frames matches encoders trained on billions of image-text pairs.
|
| 192 |
2. **Variable-resolution pretraining scales monotonically.** Quality keeps improving with the visual-token budget instead of saturating/degrading like fixed-resolution encoders.
|
| 193 |
3. **Codec-native tokenization sets a better accuracy–efficiency frontier** — up to **3.5× wall-clock inference speedup** over uniform frame sampling.
|
| 194 |
4. **Explicit VideoQA SFT is redundant.** Dense video *captions* + standard image SFT are sufficient for strong zero-shot VideoQA.
|
|
|
|
| 220 |
|
| 221 |
Codec-based video inference also requires `ffmpeg` and `ffprobe` on `PATH`.
|
| 222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
### Examples
|
| 224 |
|
| 225 |
Two sample inputs ship with this repository:
|
|
|
|
| 336 |
## 📝 Citation
|
| 337 |
|
| 338 |
```bibtex
|
| 339 |
+
@article{yang2026mage,
|
| 340 |
title={Mage-VL: An Efficient Codec-Native Streaming Multimodal Foundation Model},
|
| 341 |
+
author={Yang, Senqiao and Zhang, Kaichen and Jia, Zhaoyang and Guo, Jinghao and Shen, Yifei and Zhang, Xinjie and Zhang, Xiaoyi and Wang, Haoqing and Li, Xiao and Zhang, Peng and others},
|
| 342 |
journal={arXiv preprint arXiv:2607.24904},
|
| 343 |
year={2026}
|
| 344 |
}
|