- Basic Call: Directly pass images and text.
- Processor Output: Use HuggingFace processor for data preprocessing.
- Precomputed Embeddings: Pre-calculate image features to improve inference efficiency.
Understanding the Three Input Formats
SGLang supports three ways to pass visual data, each optimized for different scenarios:1. Raw Images - Simplest approach
- Pass PIL Images, file paths, URLs, or base64 strings directly
- SGLang handles all preprocessing automatically
- Best for: Quick prototyping, simple applications
2. Processor Output - For custom preprocessing
- Pre-process images with HuggingFace processor
- Pass the complete processor output dict with
format: "processor_output" - Best for: Custom image transformations, integration with existing pipelines
- Requirement: Must use
input_idsinstead of text prompt
3. Precomputed Embeddings - For maximum performance
- Pre-calculate visual embeddings using the vision encoder
- Pass embeddings with
format: "precomputed_embedding" - Best for: Repeated queries on same images, caching, high-throughput serving
- Performance gain: Avoids redundant vision encoder computation (30-50% speedup)
Multimodal cache identity
SGLang identifies actual media features or supplied embeddings using full 256-bit digests. Cache identities also include tensor shape and dtype, container boundaries, modality, model-specific metadata, and the effective model/processor configuration. CPU and CUDA tensor hashing use BLAKE3; GPU hashing transfers only the digests to the host. These are collision-resistant identifiers, not a mathematical guarantee that collisions are impossible.-
mm_hashesremains accepted for compatibility, but cannot override cache keys or skip server-side content hashing. External routers must not assume that a supplied scalar hash equals SGLang’s internal KV-cache key. -
mm_content_hashesdescribes source content. Keep--trust-mm-content-hashesdisabled for untrusted clients; enabling it allows preprocessing-cache lookup before verifying the supplied media. -
Embedding caching and batch deduplication retain the full identity. In the KV
cache key, each media span is padded with a repeating cycle of four 62-bit
sentinels derived from the item’s identity, so the radix cache shares earlier
turns when media are appended, and the text before media that differ. This is
on by default for every natively served multimodal model at any
--page-sizeand span position, including PD and EPD disaggregation and media passed as processor outputs or precomputed embeddings. The existing Qwen2.5-VL cache-only page proof remains unchanged where enabled. -
Media that do not hold the cycle (a span shorter than four tokens, missing or
truncated offsets, model-specific scalar padding) are named in the KV
namespace instead, together with every media before them and
cache_salt. Such a request shares KV only with requests that start with the same media; media appended after the last such item still share through their spans. -
A request names all of its media, and so shares KV only with requests that
carry the same media list, when:
- the model cross-attends to an encoder state built from the whole request (Llama 3.2 Vision, Moss-VL, Whisper);
- the request carries
input_embedsor positional embedding overrides, which its prompt tokens do not describe; - the request continues a streaming session.
has_causal_image_positions=Falseon its output. Deployments using HiCache or PD must use the same model, processor and settings across participating workers. SetSGLANG_FORCE_MM_KV_NAMESPACE=1to name every media of every request in the namespace, which removes prefix sharing across different media lists. - Pin model revisions when sharing encoder caches. Clear caches or restart when replacing weights or processor implementations in place; a configuration fingerprint is not a checksum of all model weights.
Querying Qwen2.5-VL Model
Example
Example
Basic Offline Engine API Call
Example
Example
Call with Processor Output
Using a HuggingFace processor to preprocess text and images, and passing theprocessor_output directly into Engine.generate.
Example
Call with Precomputed Embeddings
You can pre-calculate image features to avoid repeated visual encoding processes.Example
Example
Querying Llama 4 Vision Model
Example
Llama 4 Basic Call
Llama 4 requires more computational resources, so it’s configured with multi-GPU parallelism (tp_size=4) and larger context length.Example
Call with Processor Output
Using HuggingFace processor to preprocess data can reduce computational overhead during inference.Example
Call with Precomputed Embeddings
Example
