Skip to main content
Overlap Scheduling is a performance optimization technique that overlaps CPU scheduling overhead with GPU computation, significantly improving overall system throughput and GPU utilization.

Overview

Proposed in the NanoFlow paper, overlap scheduling addresses a key bottleneck in LLM serving: the CPU overhead of scheduling, memory management, and batch preparation can leave the GPU idle between forward passes. Mini-SGLang employs overlap scheduling by default to maximize GPU utilization and minimize latency. Overlap Scheduling Illustration of Overlap Scheduling from LMSYS Blog

The Problem: CPU Bottleneck

Traditional Sequential Execution

Without overlap scheduling, the execution is strictly sequential:
The GPU sits idle during CPU scheduling, wasting valuable compute resources.

With Overlap Scheduling

While the GPU executes Batch N, the CPU simultaneously processes results from Batch N-1 and schedules Batch N+1. The GPU stays continuously busy.

Implementation

Dual Stream Architecture

Mini-SGLang uses two CUDA streams to enable overlap:
  • Main stream (self.stream): Used for CPU-side operations like scheduling, memory allocation, metadata preparation
  • Engine stream (self.engine.stream): Used for GPU computation (forward pass, attention, sampling)

Overlap Loop

The main event loop implements the overlap pattern:

Key Insights

  1. Asynchronous execution: GPU work is launched asynchronously on the engine stream
  2. Stream synchronization: engine.stream.wait_stream(self.stream) ensures scheduling is done before GPU starts
  3. Overlap window: While GPU processes Batch N, CPU processes results from Batch N-1
  4. Data passing: ForwardData captures both input and output to be processed in the next iteration

ForwardData Structure

The overlap requires caching forward pass data:
This captures all data needed to process results after the GPU completes.

Processing Last Batch Results

While the GPU works on the current batch, the CPU processes the previous batch:
This performs:
  • Token extraction from GPU results
  • Completion detection (EOS or max length)
  • Resource cleanup for finished requests
  • Detokenization message sending
  • Cache updates
All while the GPU is busy with the next batch!

Stream Synchronization

Wait Pattern

The synchronization ensures correct ordering:

Event Synchronization

The copy_done event ensures GPU->CPU copies complete:
Stream synchronization is critical for correctness. The wait_stream call ensures all scheduling work completes before GPU execution begins, while copy_done.synchronize() ensures CPU can safely read GPU results.

Performance Benefits

Benchmark Results

From the Mini-SGLang README: Offline Inference Benchmark
  • Hardware: 1x H200 GPU
  • Model: Qwen3-0.6B, Qwen3-14B
  • Workload: 256 sequences, 100-1024 tokens in/out
To test without overlap scheduling:
Offline Benchmark Overlap scheduling provides measurable throughput improvements by keeping the GPU saturated.

When Overlap Helps Most

  1. High CPU overhead: Complex scheduling logic, large batches, many requests
  2. Fast GPU execution: Small models or short sequences where CPU overhead is significant relative to GPU time
  3. Mixed workloads: Combination of prefill and decode requests requiring dynamic scheduling

When Overlap Helps Less

  1. Very large models: GPU execution dominates, little CPU time to hide
  2. Simple scheduling: Minimal CPU overhead leaves little to optimize
  3. Memory bound: If memory copies dominate, overlap may not help significantly

Disabling Overlap Scheduling

For debugging or comparison purposes, overlap scheduling can be disabled:
With overlap disabled, the system uses the normal loop:
This processes each batch completely before moving to the next, running everything sequentially.
Disabling overlap scheduling can be useful for debugging race conditions or isolating performance issues, but it will reduce throughput in production.

Advanced: Extra Synchronization

For certain edge cases, additional synchronization can be enabled:
This adds an explicit stream sync before the forward pass:
This ensures complete quiescence of the main stream before GPU work begins, trading some performance for additional safety.

Architecture

Understand the scheduler’s role in the system

Chunked Prefill

See how scheduling interacts with chunked prefill

References