Skip to main content
SGLang provides a direct inference engine without the need for an HTTP server, especially for use cases where additional HTTP server adds unnecessary complexity or overhead. Here are two general use cases:
  • Offline Batch Inference
  • Custom Server on Top of the Engine
This document focuses on the offline batch inference, demonstrating four different inference modes:
  • Non-streaming synchronous generation
  • Streaming synchronous generation
  • Non-streaming asynchronous generation
  • Streaming asynchronous generation
Additionally, you can easily build a custom server on top of the SGLang offline engine. A detailed example working in a python script can be found in custom_server.

Nest Asyncio

Note that if you want to use Offline Engine in ipython or some other nested loop code, you need to add the following code:
Example

Advanced Usage

The engine supports vlm inference as well as extracting hidden states. Please see the examples for further use cases.

Offline Batch Inference

SGLang offline engine supports batch inference with efficient scheduling.
Example

Non-streaming Synchronous Generation

Example

Streaming Synchronous Generation

Example

Non-streaming Asynchronous Generation

Example

Streaming Asynchronous Generation

Example
Example