Skip to main content

Development Setup

This guide covers setting up a development environment for SGLang, including Docker-based and local setups.

Prerequisites

  • Python 3.8+
  • CUDA 11.8+ (for GPU support)
  • Docker (optional, for containerized development)
  • Git

Option 1: Local Development

Clone Repository

Install Dependencies

Install Kernels

Verify Installation

Option 2: Docker Development

SGLang includes a .devcontainer configuration for seamless Docker-based development.

Setup Steps

  1. Install VSCode and the Dev Containers extension
  2. Open the repository in VSCode:
  3. Press F1, type “Dev Containers: Reopen in Container”, and press Enter
  4. VSCode will build the container and install all dependencies automatically
Once the container is ready, you’ll see “Dev Container” in the status bar. All development happens inside the container with your local changes synced automatically.

Running the Server in Dev Container

Manual Docker Setup

For manual Docker container management:

Volume Mounts Explained

  • ~/.cache/huggingface: Avoids re-downloading models on container restart
  • $(pwd): Syncs your local code changes to the container
  • --network=host: Required for RDMA (can be omitted if RDMA is not needed)
  • --privileged: Required for RDMA (can be omitted if RDMA is not needed)
RDMA Note: If using RoCE, you may need to set export NCCL_IB_GID_INDEX=3 inside the container.

Option 3: Remote Development

VSCode Remote Tunnels

Develop on a remote machine using VSCode Remote Tunnels:

On Remote Host

On Local Machine

  1. Press F1 in VSCode
  2. Select “Remote Tunnels: Connect to Tunnel”
  3. Sign in and select your remote host
You can now edit code locally while it runs on the remote machine.

Debugging with VSCode

Configure Launch Settings

Create or edit .vscode/launch.json:

Start Debugging

  1. Set breakpoints in the code
  2. Press F5 to start debugging
  3. The debugger will pause at breakpoints, even in remote/container environments

Testing

Run Unit Tests

Run Integration Tests

Profiling

PyTorch Profiler

Nsight Systems

For more profiling details, see Benchmark and Profiling.

Environment Variables

Common environment variables for development:

Common Development Tasks

Format Code

Run Linters

Build Documentation

Update Dependencies

Troubleshooting

Out of Memory

CUDA Errors

Import Errors

Pre-commit Failures

Next Steps

Resources