Before you start: words you need#
| Word | Plain meaning |
|---|---|
| VLM | Vision-language model: an LLM that also reads images or video. |
| ViT | Vision transformer: a transformer whose “tokens” are small squares of an image (patches). |
| Patch | A square of pixels, often 14×14 or 16×16, that the ViT treats as one input token. |
| Patch merge | Combining neighbouring patch vectors (often 2×2) into one vector, so the LLM sees fewer tokens. |
| Dynamic resolution | The encoder accepts images at (close to) their own size and aspect ratio, so cost grows with pixel count. |
| Tiling | Cutting a large image into fixed-size tiles, encoding each, often plus a small thumbnail of the whole. |
| Projector | The small network that maps encoder vectors into the LLM’s embedding space. |
| Frame sampling | Choosing which video frames to feed the model, for example 2 per second. |
1. What is it?#
A VLM is three parts in a row: a vision encoder (usually a ViT of a few hundred million to a few billion parameters), a projector, and a language model. The encoder turns pixels into vectors; the projector makes them look like token embeddings; the LLM reads them alongside the text.
How vLLM wires this into its scheduler (placeholder tokens, the encoder budget, the three caches) is taught in 18.h; read it first. This lesson is about the serving engineering around it: what an image really costs, the knobs that control that cost, where to run the encoder, how video changes the picture, and how to size a VLM deployment. Facts checked on 13 November 2026 against vLLM v0.32.0 and the public Qwen3-VL configuration.
2. Why does it matter?#
- Images are the most expensive “words” in the prompt. One 1080p photo is about 2,000 LLM tokens with Qwen3-VL’s defaults; a 4K screenshot about 8,000. A user pasting four screenshots sends a 30,000-token prompt without typing a word.
- The encoder is a second model on the critical path. It runs before prefill can start, so its time adds directly to time to first token (TTFT).
- Video multiplies everything. A ten-minute video at two frames per second becomes over a hundred thousand tokens.
- The bottleneck hides on the CPU. Downloading, decoding and resizing images happens in the API server, and image-heavy traffic often saturates CPUs while GPUs idle (18.h).
3. Simple analogy#
A translator who reads documents with photos. For every photo, an assistant (the encoder) writes a description of each region. A tiny thumbnail gets one paragraph; a poster-sized print gets forty. The translator then has to read all of it before answering. You can hire a faster assistant, but the cheapest fix is often to stop sending poster-sized prints when a postcard would do.
4. Tiny example: one screenshot#
input 3840 x 2160 screenshot, "What does the error say?"
resize snap to multiples of 32 px -> 3840 x 2176
patches 240 x 136 = 32,640 patches of 16 x 16 px -> ViT sequence length 32,640
merge 2x2 8,160 tokens -> LLM sees 8,160 placeholders
same image, capped at 1 megapixel:
resize 1344 x 768 -> 4,032 patches -> 1,008 tokens, about 8x cheaperWhether the error text is still readable at 1 megapixel is the product question. The engineering answer is that the knob exists, it is per request or per deployment, and it is worth a factor of 8.
5. Technical explanation#
Three ways encoders turn images into tokens#
| Family | How | Cost vs image size | Examples |
|---|---|---|---|
| Fixed resolution | Resize every image to one size (for example 336×336 or 384×384) | Constant | Early LLaVA (CLIP ViT-L/14-336), SigLIP-based models |
| Tiling | Fixed-size tiles plus a thumbnail; pixel-shuffle to shrink each tile | Steps up with the tile count | InternVL, LLaVA-NeXT style “AnyRes” |
| Dynamic resolution | Keep the aspect ratio, snap sides to a multiple of patch × merge, cap total pixels | Grows with pixel count | Qwen2-VL / 2.5-VL / 3-VL |
Qwen3-VL’s published configuration uses 16-pixel patches, a 2×2 merge (one LLM token per 32×32 pixels), a temporal patch of 2 frames for video, a 27-layer encoder of width 1,152, and a processor that by default allows between 65,536 and 16,777,216 pixels per image. That upper limit is 16 megapixels: the default lets 4K images through at full cost.
The knobs that control image cost#
- Pixel limits in the processor. Passed with
--mm-processor-kwargsat server start (and, for many models, per request throughmm_processor_kwargs). The key names are model-specific; check the model’s processor. - Client-side resizing. The cheapest place to shrink an image is before upload: less network, less CPU decode, fewer tokens.
- Limits per prompt.
--limit-mm-per-promptbounds how many images, videos or audio clips one request may carry (18.h). With--language-model-onlyall of them are set to zero, which turns a VLM checkpoint into a text model and frees the encoder’s memory. - Video frame count.
--media-io-kwargs '{"video": {"num_frames": 40}}'controls how many frames the video loader extracts. - Video token pruning.
--video-pruning-rate(0 to below 1) drops that fraction of video tokens, using Efficient Video Sampling (evs, the default method) orvidcom2, on models that support it.
Where the encoder runs#
In a single vLLM instance, the encoder runs on the same GPUs as the LLM, between scheduler steps
(18.h). With tensor parallelism there are two choices, set by --mm-encoder-tp-mode:
weights(default): split each encoder layer across the TP ranks, like the LLM. Every image pays for all-reduces across GPUs, which for a 0.4B encoder can cost more than it saves.data: each TP rank holds a full copy of the (small) encoder and encodes a different subset of the batch’s images. Supported per model; falls back toweightsotherwise.
Beyond one instance, encoder disaggregation runs encoders as their own pool and ships embeddings
to the language-model instances through an encoder-cache connector (--ec-transfer-config,
connectors such as ECMooncakeConnector), in E+PD or E+P+D layouts. vLLM’s stated reasons are
independent scaling of the encoder fleet, lower TTFT because text-only requests never wait behind an
encoder, and reuse of embeddings across instances. Measured gains depend on load and can turn
negative at low concurrency; the numbers and the break-even argument are in 24.h.
Making the encoder itself faster#
- Encoder CUDA graphs (
-cc.cudagraph_mm_encoder=true) for small, frequent images (18.h). - FP8 encoder attention:
--mm-encoder-attn-dtype fp8, with optional calibrated per-layer scales. - Windowed attention inside the ViT. Full self-attention over 32,640 patches is expensive (see below). Qwen2.5-VL, for example, used window attention in most encoder layers and full attention in only a few, for exactly this reason.
6. Under the hood: what an image costs#
The program reproduces Qwen-VL-style dynamic resizing, then estimates the encoder’s cost (linear layers plus attention, assuming full attention in every layer) and the language model’s prefill cost for the resulting tokens on an 8B LLM. Times assume an H100 running at half its BF16 peak.
package main
import (
"fmt"
"math"
)
// Qwen-VL-style dynamic resolution: snap each side to a multiple of
// patch*merge pixels, then rescale if the pixel count is outside [minPx, maxPx].
const (
patch = 16 // pixels per patch side (Qwen3-VL)
merge = 2 // 2x2 patches merged into one LLM token
factor = patch * merge
)
func resize(w, h, minPx, maxPx float64) (float64, float64) {
wb := math.Max(factor, math.Round(w/factor)*factor)
hb := math.Max(factor, math.Round(h/factor)*factor)
if wb*hb > maxPx {
beta := math.Sqrt(w * h / maxPx)
wb = math.Floor(w/beta/factor) * factor
hb = math.Floor(h/beta/factor) * factor
} else if wb*hb < minPx {
beta := math.Sqrt(minPx / (w * h))
wb = math.Ceil(w*beta/factor) * factor
hb = math.Ceil(h*beta/factor) * factor
}
return wb, hb
}
// Encoder cost for n patches: linear layers plus full self-attention
// (assumption: every layer attends over every patch of the image).
func encoderGFLOP(n float64) (linear, attn float64) {
const params, layers, width = 0.4e9, 27, 1152.0
return 2 * params * n / 1e9, 4 * layers * width * n * n / 1e9
}
func main() {
const defaultMax, capped = 16777216.0, 1048576.0 // processor default vs a 1-megapixel cap
const llmGFLOPPerToken = 2 * 8.0 // 8B language model prefill
const effTFLOPs = 0.5 * 989 // H100 BF16 at 50% of peak
fmt.Printf("%-11s %-9s %8s %8s %9s %9s %9s\n",
"image", "max px", "patches", "tokens", "enc ms", " attn %", "LLM ms")
for _, im := range [][2]float64{{640, 480}, {1920, 1080}, {3840, 2160}} {
for _, maxPx := range []float64{defaultMax, capped} {
w, h := resize(im[0], im[1], 65536, maxPx)
patches := (w / patch) * (h / patch)
tokens := patches / (merge * merge)
lin, att := encoderGFLOP(patches)
encMs := (lin + att) / effTFLOPs
llmMs := tokens * llmGFLOPPerToken / effTFLOPs
label := "default"
if maxPx == capped {
label = "1 MP"
}
fmt.Printf("%4.0fx%-6.0f %-9s %8.0f %8.0f %9.2f %8.0f%% %9.2f\n",
im[0], im[1], label, patches, tokens, encMs, 100*att/(lin+att), llmMs)
}
}
// Video: frames sampled at 2 fps, two consecutive frames share one temporal patch.
fmt.Println()
w, h := resize(640, 360, 65536, defaultMax)
perPair := (w / patch) * (h / patch) / (merge * merge)
for _, secs := range []float64{10, 60, 600} {
frames := secs * 2
fmt.Printf("video %4.0f s at 2 fps, 640x360 frames: %6.0f frames -> %7.0f tokens\n",
secs, frames, frames/2*perPair)
}
}Output:
image max px patches tokens enc ms attn % LLM ms
640x480 default 1200 300 2.30 16% 9.71
640x480 1 MP 1200 300 2.30 16% 9.71
1920x1080 default 8160 2040 29.95 56% 66.01
1920x1080 1 MP 4032 1008 10.61 39% 32.61
3840x2160 default 32640 8160 320.85 84% 264.02
3840x2160 1 MP 4032 1008 10.61 39% 32.61
video 10 s at 2 fps, 640x360 frames: 20 frames -> 2200 tokens
video 60 s at 2 fps, 640x360 frames: 120 frames -> 13200 tokens
video 600 s at 2 fps, 640x360 frames: 1200 frames -> 132000 tokensHow to read it:
- Encoder sequences are four times longer than what the LLM sees, because the 2×2 merge happens at the end. Attention cost grows with the square, so at 4K, attention is 84% of the encoder’s work and the encoder (under the full-attention assumption) costs more than the 8B LLM’s prefill of the same image. This is why production encoders use windowed attention, and why a pixel cap is the single biggest lever.
- A 1-megapixel cap makes the 4K screenshot 30x cheaper in the encoder and 8x cheaper in the LLM.
- Video scales linearly with duration at a fixed frame rate. Ten minutes at low resolution is 132,000 tokens: beyond many models’ context windows, and a prefill measured in seconds. Long video needs lower frame rates, pruning, or a summarise-in-chunks design.
7. Performance implications#
- TTFT = fetch + decode + resize (CPU) + encoder + prefill. Measure each. For small images the CPU stages dominate; for large ones the encoder and prefill do.
- Encoder batching. Encoding many small images together keeps the GPU busy; the encoder budget (18.h) bounds how many per step. Large images can monopolise a step and delay other requests' decode tokens; chunked prefill does not split an encoder pass.
- Prefix caching pays twice for VLMs. A repeated image skips the processor, the encoder and the prefill of its placeholders (18.h). Multi-turn chats about the same screenshot benefit most.
- TP for the encoder is often waste. Prefer
--mm-encoder-tp-mode datawhere supported. - Quantization. The LLM can be quantized as usual (13.b); encoders are smaller and more sensitive to precision, so many deployments keep them in BF16 and use FP8 attention at most.
8. Production implications#
- Set a pixel policy. Decide a maximum resolution per product (documents need more than photos), enforce it on the client or the gateway, and make it visible in pricing. Providers that bill per image token are passing this cost on.
- Size
max_model_lenfor media. The maximum images per prompt times the maximum tokens per image, plus text (18.h). - Scale CPUs with image traffic. More API-server processes (
--api-server-count), more media loading threads, and a gateway that rejects oversized files before they are downloaded. - Security. URL fetching is an SSRF risk; restrict domains (18.h). Images can also carry prompt injection as text inside the picture; treat VLM output from untrusted images like any other untrusted model output.
- Separate pools when traffic is mixed. If only some requests carry images, an encoder pool (24.h) or a separate VLM deployment keeps text-only TTFT stable.
- Video is a batch workload in disguise. Most long-video understanding is not interactive; queue it, run it on cheaper capacity, and cache results by content hash.
9. Common mistakes#
- Accepting the processor’s default maximum resolution. For Qwen3-VL that is 16 megapixels.
- Counting the LLM tokens but not the encoder’s sequence. The encoder sees four times as many patches and pays quadratic attention on them.
- Splitting a 0.4B encoder across 8 GPUs with weight TP. Communication costs more than the compute saved.
- Sampling video at a fixed high frame rate. Most questions need 1–2 frames per second or less.
- Benchmarking with one image size. Real traffic mixes thumbnails and 4K screenshots; tail latency comes from the large ones.
10. Hands-on exercise#
- Run the program. Add a 2560×1440 image and a 1-megapixel cap. How many tokens does each produce?
- Change the encoder to windowed attention: assume each patch attends only to a 16×16-patch window (256 patches) in all but 4 of the 27 layers. Recompute the 4K encoder time.
- A product sends up to 5 screenshots of 2560×1440 per request plus 3,000 tokens of text. What
--max-model-lendo you need with the default limit, and with a 1-megapixel cap? - On a real vLLM VLM server, send the same request with and without
--mm-encoder-tp-mode dataat TP=4 and compare TTFT at concurrency 1 and 32.
11. Interview questions#
- Why does a 4K image cost more in the vision encoder than a 1080p image by more than 4x?
- Compare fixed-resolution, tiling and dynamic-resolution encoders for a document-reading product.
- What does
--mm-encoder-tp-mode datachange, and when does it help? - Your VLM service’s TTFT p99 doubled after a client app update, with no change in request count. What do you check first?
- When is encoder disaggregation worth it, and when does it make things worse?
12. Further reading#
Checked on 13 November 2026.
- Multimodal inputs (vLLM v0.32.0 docs)
- Disaggregated encoder (vLLM v0.32.0 docs)
vllm/config/multimodal.py(v0.32.0):mm_encoder_tp_mode,video_pruning_rate,media_io_kwargs- Qwen3-VL-8B-Instruct configuration and processor settings
- An Image is Worth 16x16 Words: the Vision Transformer (arXiv 2010.11929)
- Qwen2.5-VL Technical Report (arXiv 2502.13923)