Skip to main content
Mini-SGLang offers several configuration options to optimize performance for your specific workload and hardware. This guide covers best practices and tuning recommendations.

Memory Management

GPU Memory Ratio

Control the fraction of GPU memory allocated to KV cache:
Recommendations:
  • Default: 0.9 (90% of available memory)
  • Shared GPU: Reduce to 0.7-0.8 if other processes need GPU memory
  • Long contexts: Increase to 0.95 for maximum cache capacity

Page Size Configuration

Page size determines the granularity of KV cache allocation:
Recommendations: Note: Some attention backends override page size:
  • TensorRT-LLM: Only supports 16, 32, or 64
  • FlashInfer: Works with any power-of-2 size

Number of Pages

Explicitly control the maximum number of KV cache pages:
Useful when:
  • Debugging OOM issues
  • Profiling memory usage
  • Running on constrained hardware

Chunked Prefill

Chunked prefill splits long prompts into smaller chunks to reduce peak memory usage and prevent OOM errors.

Configuration

Recommended values: Performance tips:
  • Too small (<512): Significant overhead from multiple kernel launches
  • Too large (>32K): Risk of OOM, especially with large batch sizes
  • Optimal: Set to 2-4x your typical prompt length
Chunked prefill is enabled by default and has been shown to improve throughput in long-context serving scenarios (see Sarathi-Serve).

CUDA Graph Optimization

CUDA graphs reduce CPU kernel launch overhead during the decode phase by capturing and replaying GPU operations.

Configuration

Recommendations: Trade-offs:
  • Higher values: Better performance at high concurrency, but more GPU memory usage
  • Lower values: Less memory overhead, but may miss optimization opportunities
  • Auto-tuning: Leave unset to automatically tune based on GPU memory

When to Disable

  • Debugging decode kernels
  • Running on very limited GPU memory (<8GB)
  • Shell/interactive mode (automatically disabled)

Attention Backend Selection

Mini-SGLang supports multiple attention backends optimized for different phases:

Available Backends

  • fa: FlashAttention (including FlashAttention-3 on Hopper GPUs)
  • fi: FlashInfer
  • trtllm: TensorRT-LLM FMHA

Configuration

Recommendations by GPU Architecture

Backend-Specific Considerations

FlashAttention:
  • Excellent prefill performance
  • FlashAttention-3 on Hopper provides significant speedup
  • Works with any page size
FlashInfer:
  • Optimized for decode with paged attention
  • Better performance with batched decode requests
  • Requires page size to be power of 2
TensorRT-LLM:
  • Highly optimized NVIDIA kernels
  • Restricts page size to 16, 32, or 64
  • May require additional setup

Cache Management Strategy

Choose between Radix Cache and naive cache management:
When to use Radix Cache (default):
  • Requests with shared prefixes (e.g., system prompts)
  • Multi-turn conversations
  • Batched requests with common context
  • Production serving scenarios
When to use naive cache:
  • Benchmarking (for fair comparison)
  • Debugging cache-related issues
  • Workloads with no shared prefixes
Performance impact: Radix Cache can improve throughput by 2-5x for workloads with high prefix sharing.

Overlap Scheduling

Overlap scheduling hides CPU scheduling overhead by overlapping it with GPU computation.

Configuration

Overlap scheduling is enabled by default. To disable for ablation studies:
Performance impact: Typically improves throughput by 5-15% by reducing scheduler overhead.

When to Disable

  • Debugging scheduler behavior
  • Profiling CPU overhead
  • Running ablation studies

Distributed Serving (Tensor Parallelism)

Scale large models across multiple GPUs:
Recommendations: Best practices:
  • Use NVLink-connected GPUs for best performance
  • TP size should divide model layers evenly
  • PyNCCL is enabled by default (disable with --disable-pynccl if needed)

Advanced Tuning

Maximum Running Requests

Control scheduler concurrency:
Trade-offs:
  • Higher: Better throughput under load, but more memory usage
  • Lower: Reduced memory pressure, but may bottleneck under high QPS

Maximum Sequence Length

Override model’s default max sequence length:
Useful when:
  • Model supports longer context than config specifies
  • Testing with shorter sequences to save memory

Data Type

Choose precision for model weights:
Options:
  • auto (default): FP16 for FP32/FP16 models, BF16 for BF16 models
  • bfloat16: Better numerical stability on Ampere+ GPUs
  • float16: Slightly faster on some GPUs
  • float32: Highest precision, but 2x memory usage

Monitoring and Debugging

Enable Detailed Logging

Set log level via environment variable:

Memory Profiling

Monitor GPU memory usage:

Performance Profiling

Use NVIDIA Nsight Systems for detailed profiling:

Quick Reference

Common Configuration Profiles

Maximum throughput (production):
Memory-constrained:
Long-context serving:
Debug/development: