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
Fix <|image_pad|> misalignment when images= and videos= coexist
Fixes microsoft/Mage#28.
Two independent defects made a single processor(images=..., videos=...) call
produce visual tensors that do not line up with the prompt placeholders:
codec_video_processing_mage_vl.rewrite_text_with_codec_positions used
text.find(VISION_START) / text.rfind(VISION_END), which spans from the
first vision block to the last. Any image block sitting between them was
wiped out along with the video block, so the images lost their
placeholders entirely and generate() raised
'Image features and image tokens do not match'. Now matches exactly one
<|vision_start|><|video_pad|><|vision_end|> block, mirroring what the
frames backend already did.processing_mage_vl.call ran the IMAGE PATH after the video branches
had already rewritten the video block into literal <|image_pad|> runs.
_expand_image_pads restarts from the start of the string on every
replace, so it consumed the video's placeholders. The tensor
concatenation was also unconditionally video-rows-then-image-rows, which
is only correct when the video precedes every image in the prompt. The
image path now runs first (while video placeholders are still
<|video_pad|>), both video branches emit per-visual slots, and the slots
are concatenated in recorded prompt order.
Reordering rows is safe for the vision tower: _build_cu_seqlens blocks
strictly per image_grid_thw row, so image and video rows never attend to
each other regardless of position.
Verification
Single-modality paths are byte-identical to the stock processor
(torch.equal on input_ids / pixel_values / image_grid_thw / patch_positions):
codec video-only, frames video-only, 1 image, 2 images -> all True
Mixed images + video, stock vs patched:
codec [image, video] 3775/3776 ValueError -> 3776/3776 match
codec [video, image] 3775/3776 ValueError -> 3776/3776 match
codec [image, image, video] 5822/5824 ValueError -> 5824/5824 match
codec [video, image, image] 5822/5824 ValueError -> 5824/5824 match
frames all four orders totals matched by coincidence but the k-th
placeholder run was paired with the wrong
tensor rows; runs == grid rows is now True
element-by-element
Generation with unmodified weights, examples/dog.jpg + soccer-broadcast.mp4:
codec [video, image] 'A dog is in the reference photo, and the video shows
a sports broadcast with four commentators...'
frames [video, image] 'A dog is in the reference photo, and the video shows
a football match between England and Argentina.'
Not addressed: the codec branch still replicates one text per video, so
multiple videos in a single prompt remains unsupported, as before.