Skip to main content
In this tutorial, we’ll explore how to deploy a Vision Language Model (VLM) using SGLang on Cerebrium. A VLM is an AI model that combines a large language model (LLM) with a vision encoder, allowing it to understand and process both images and text. We’ll build an intelligent ad analysis system that evaluates advertisements across multiple dimensions, giving us a score on how the advertisement relates to the business in quesion and how it scores 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, designed with a clear seperation of functionality:
LayerWhat it doesWhy it matters
FrontendWhere you define your LLM logic (with gen, fork, join, etc.)This keeps your code clean, readable, and your workflows easily reusable.
BackendWhere SGLang intelligently figures out how to run your logic most efficiently.This is where the speed, scalability, and optimized inference truly come to life.
To give you quick example, here are some primitives on the frontend you can use to create multi-step workflows:
PrimitiveWhat it doesExample
gen()Generates a text spangen("title", stop="\n")
fork()Splits execution into multiple branchesFor parallel sub-tasks
join()Merges branches back togetherFor combining outputs
select()Chooses one option from manyFor controlled logic, like multiple choice
SGLang Architecture Here is a summary of key advantages over traditional inference engines
FeatureTraditional Engines (vLLM, TGI)SGLang
Programming ModelSequential API calls with manual prompt chainingNative structured logic with gen(), fork(), join(), select()
Memory ManagementBasic KV caching, often discarded between callsRadixAttention: Intelligent prefix-aware cache reuse (up to 6x faster)
Output ControlHope and pray for correct formattingCompressed FSMs: Guaranteed structured output (JSON, XML, etc.)
Parallel ProcessingManual batching and coordinationBuilt-in fork() and join() for parallel execution
PerformanceStandard inference optimizationPyTorch-native with torch.compile(), quantization, sparse inference
If you would like to read more, checkout this article. Let us show this in practice with our tutorial. You can see the final code sample here

Tutorial

Step 1: Project Setup

First, let’s create our project structure:

Step 2: Configure Dependencies

The VLM we will be using is Qwen3-VL-30B-A3B-Instruct-FP8 model, which need a lot of GPU memory - we configure this in our cerebrium.toml. Cerebrium runs containers in the cloud and this file defines our environment, hardware, and scaling settings. We’ll use an ADA_L40 GPU to accommodate our model’s memory requirements. The configuration includes:
  • Hardware settings for GPU, CPU and memory allocation
  • Scaling parameters to control instance counts
  • Required pip packages like SGLang, flashinfer (our chosen backend), and PyTorch
  • APT system dependencies
  • FastAPI server configuration for hosting our API
For a complete reference of all available TOML settings, see our TOML Reference. While we use flashinfer as our backend here, other options like flash attention are also available depending on your needs. Update your cerebrium.toml with:

Step 3: Implement the Ad Analysis Logic

One of the many great features of Cerebrium is we don’t enforce any special class design or way of architecing your applications - Just write your python code as if you were running it locally (and if you had a GPU ;). Below, we setup our SGLang Runtime Engine (Backend) with our FastAPI and load the model on startup of the container. This means we will incur a model load on the first request but subsequent requests will execute instantaneously. In your main.py file:
In order to score the advertisement, we will be using one of the core differentiators of SGLang, fork, which allows us to run many prompts in parallel and bring the results together in the end. This allows us to execute alot of simulaneous requests with no increase in total latency. Lastly, we bring these results together and structure them in a specific format to return to the user.
To end, let us bring it all together in an endpoint and
Thats it! Let’s deploy your application so it becomes a scalable inference endpoint

Step 4: Deploy Your Application

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

Example Response

We’ve demonstrated a simple application how to leverage SGLang’s powerful structured generation capabilities to build a naive ad analysis system. By 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.