Skip to main content
This tutorial demonstrates how to use SGLang’s offline Engine API to query VLMs. We will demonstrate usage with Qwen2.5-VL and Llama 4. This section demonstrates three different calling approaches:
  1. Basic Call: Directly pass images and text.
  2. Processor Output: Use HuggingFace processor for data preprocessing.
  3. 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_ids instead 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)
Key Rule: Within a single request, use only one format for all images. Don’t mix formats. The examples below demonstrate all three approaches with both Qwen2.5-VL and Llama 4 models.

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 the processor_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