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
| import numpy as np | |
| import scipy.ndimage | |
| import torch | |
| import torch.nn.functional as F | |
| YCBCR_WEIGHTS = { | |
| # Spec: (K_r, K_g, K_b) with K_g = 1 - K_r - K_b | |
| "ITU-R_BT.709": (0.2126, 0.7152, 0.0722) | |
| } | |
| def ycbcr420_to_444_np(y, uv, order=0, separate=False): | |
| ''' | |
| y is 1xhxw Y float numpy array | |
| uv is 2x(h/2)x(w/2) UV float numpy array | |
| order: 0 nearest neighbor (default), 1: binear | |
| return value is 3xhxw YCbCr float numpy array | |
| ''' | |
| uv = scipy.ndimage.zoom(uv, (1, 2, 2), order=order) | |
| if separate: | |
| return y, uv | |
| yuv = np.concatenate((y, uv), axis=0) | |
| return yuv | |
| def rgb2ycbcr(rgb, is_bgr=False): | |
| if is_bgr: | |
| b, g, r = rgb.chunk(3, -3) | |
| else: | |
| r, g, b = rgb.chunk(3, -3) | |
| Kr, Kg, Kb = YCBCR_WEIGHTS["ITU-R_BT.709"] | |
| y = Kr * r + Kg * g + Kb * b | |
| cb = 0.5 * (b - y) / (1 - Kb) + 0.5 | |
| cr = 0.5 * (r - y) / (1 - Kr) + 0.5 | |
| ycbcr = torch.cat((y, cb, cr), dim=-3) | |
| ycbcr = torch.clamp(ycbcr, 0., 1.) | |
| return ycbcr | |
| def ycbcr2rgb(ycbcr, is_bgr=False, clamp=True): | |
| y, cb, cr = ycbcr.chunk(3, -3) | |
| Kr, Kg, Kb = YCBCR_WEIGHTS["ITU-R_BT.709"] | |
| r = y + (2 - 2 * Kr) * (cr - 0.5) | |
| b = y + (2 - 2 * Kb) * (cb - 0.5) | |
| g = (y - Kr * r - Kb * b) / Kg | |
| if is_bgr: | |
| rgb = torch.cat((b, g, r), dim=-3) | |
| else: | |
| rgb = torch.cat((r, g, b), dim=-3) | |
| if clamp: | |
| rgb = torch.clamp(rgb, 0., 1.) | |
| return rgb | |
| def yuv_444_to_420(yuv): | |
| def _downsample(tensor): | |
| return F.avg_pool2d(tensor, kernel_size=2, stride=2) | |
| y = yuv[:, :1, :, :] | |
| uv = yuv[:, 1:, :, :] | |
| return y, _downsample(uv) | |