Skip to main content
This tutorial deploys a Vision Language Model (VLM) using SGLang on Cerebrium. A VLM combines a large language model (LLM) with a vision encoder, enabling it to understand and process both images and text. The example builds an intelligent ad analysis system that evaluates advertisements across multiple dimensions, scoring how the advertisement relates to the business in question and how it performs on the given criteria. SGLang (Structured Generation Language) differs from other inference frameworks such as vLLM and TensorRT by focusing no structed generation and complex workflows multi-step LLM workflows. SGLang is being used in production by teams at xAI and Deepseek to power their core language model capabilities making it a trusted choice.

SGLang Architecture

SGLang isn’t just a domain-specific language (DSL). It’s a complete, integrated execution system with a clear separation of functionality: Here are some frontend primitives for creating multi-step workflows: SGLang Architecture Here is a summary of key advantages over traditional inference engines For more details, see this article. You can see the final code sample here

Tutorial

Step 1: Project Setup

Create the project structure:

Step 2: Configure Dependencies

The VLM is Qwen3-VL-30B-A3B-Instruct-FP8, which requires significant GPU memory. The cerebrium.toml defines the environment, hardware, and scaling settings. This configuration uses an ADA_L40 GPU and includes:
  • Hardware settings for GPU, CPU, and memory allocation
  • Scaling parameters to control instance counts
  • Required pip packages: SGLang, flashinfer (the chosen backend), and PyTorch
  • APT system dependencies
  • FastAPI server configuration for hosting the API
For a complete reference of all available TOML settings, see the TOML Reference. This example uses flashinfer as the backend, but other options like flash attention are also available. Update cerebrium.toml with:

Step 3: Implement the Ad Analysis Logic

Cerebrium does not enforce any special class design or application architecture — write Python code as if running locally. The code below sets up the SGLang Runtime Engine (Backend) with FastAPI and loads the model on container startup. The first request incurs a model load, but subsequent requests execute instantaneously. In your main.py file:
To score the advertisement, the code uses one of SGLang’s core differentiators: fork, which runs many prompts in parallel and brings the results together. This enables many simultaneous evaluations with no increase in total latency. The results are then structured in a specific format for the response.
Bring it all together in an endpoint:
Deploy the application to create a scalable inference endpoint.

Step 4: Deploy Your Application

Run:
Once deployed, test with a sample request:
Nike AD

Example Response

This example demonstrates how to leverage SGLang’s structured generation capabilities to build an ad analysis system, using features like fork() for parallel processing and SGLang’s built-in output control. You can find the complete code for this tutorial in our examples repository.