- 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. KV caching
namespaces each request by its ordered media identities and
cache_salt, so a short placeholder collision cannot reuse another image’s KV state. Requests with identical media can still share prefixes; requests with different media do not share even their common text prefix. This can increase prefill cost for workloads with long shared instructions and changing images. - 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
