โšก
Mac Playbook
โฑ 15 min

MLX VLM Inference

Run vision-language models locally with MLX

Replaces DGX Spark: Multi-modal Inference
mlxmultimodal

Basic idea

Vision-language models (VLMs) accept both images and text as input, enabling visual question answering, image description, document understanding, and multimodal reasoning. MLX VLM runs these models natively on Apple Silicon using the same MLX framework as text-only LLMs.

Here's how it works under the hood: the image is passed through a vision encoder โ€” a Vision Transformer (ViT) that divides the image into patches and converts them into embedding vectors. Those embeddings are projected into the same dimensional space as the language model's token embeddings, then concatenated with the text prompt tokens. The language model then processes both image and text tokens together in its standard attention layers. The model "sees" the image as a sequence of special tokens, each encoding spatial and semantic information about a region of the image.

What you'll accomplish

A local VLM (Qwen2.5-VL-7B) running on your Mac that can describe images, answer questions about photos, read text in screenshots, and analyze charts โ€” entirely offline with no API calls. Expected throughput: 10โ€“20 tokens/sec on M2/M3 Silicon with the 4-bit quantized model.

What to know before starting

Vision Transformer (ViT): โ€” a transformer architecture applied to images. The image is split into fixed-size patches (e.g., 14ร—14 pixels), each patch is flattened into a vector, and the sequence of patch vectors is processed by transformer attention layers. The output is a sequence of image embeddings.
Dynamic resolution in Qwen2.5-VL: โ€” unlike older VLMs that resize everything to 336ร—336, Qwen2.5-VL accepts variable image sizes and tiles large images into multiple crops. A 1920ร—1080 screenshot might be processed as 6 tiles, each 336ร—336, giving the model much more detail.
Multimodal fusion: โ€” the projection layer between the vision encoder and language model maps image patch embeddings (e.g., 1024-dimensional) to the language model's token dimension (e.g., 4096-dimensional). This is a linear layer trained to align visual and text representations.
Image tokens count toward context: โ€” a 336ร—336 image typically generates 256โ€“1024 image tokens. With dynamic resolution, a high-res image can use 2000+ tokens. This affects `max_tokens` and context window limits.
Prefix vs interleaving models: โ€” Qwen2.5-VL is a prefix model: images are processed before text. Some models support interleaving (image tokens mixed throughout). The mlx-vlm API handles this automatically based on model type.

Prerequisites

โ€ข macOS 14.0+ (Sonoma or later)
โ€ข Apple Silicon Mac (M1 or later) โ€” Intel not supported
โ€ข Python 3.10, 3.11, or 3.12
โ€ข `mlx-lm` already installed (`pip install mlx-lm`)
โ€ข 16 GB+ unified memory (7B model: ~6 GB for LLM + ~2 GB for vision encoder = ~8 GB total)
โ€ข Hugging Face account (free) for model access

Time & risk

Duration:: 15 minutes setup; first model load downloads ~4 GB
Risk level:: Low โ€” pip install only, no system configuration
Rollback:: `pip uninstall mlx-vlm`; remove `~/.cache/huggingface/hub/mlx-community__Qwen2.5-VL*`