Vision encoder re-encoding waste in multi-turn chat
Fields
gotchas/vision-encoder-re-encoding-waste-in-multi-turn-chatNotes
ENCODER CACHING IS CRITICAL FOR MULTI-TURN CHAT: Without it, the vision encoder cost multiplies by the number of turns. For a 448x448 image with ViT-L/16 at ~763 GFLOPs per forward pass, a 10-turn conversation wastes 6.9 TFLOPs (9 turns * 763 GFLOPs). TRT-LLM's Multimodal Embeddings Cache is currently available for seven architectures (Gemma4, Gemma4Unified, Mistral3, Qwen3VL, Qwen3VLMoe, Qwen3_5, Qwen3_5Moe). vLLM and SGLang have similar mechanisms but the exact API and coverage vary. The key insight is that the vision encoder is a pure function of the image pixels, so its output can be cached and reused. This is analogous to prefix caching for text, but for the vision encoder. The FLOP count is derived from the ViT paper Table 6; the caching mechanisms are from the engine docs.