Contribution Guide
Welcome to SGLang! We appreciate your interest in contributing. This guide provides an overview of how to set up your environment, run tests, build documentation, and open a Pull Request.Getting Started
Fork and Clone
New contributors do not have write permission to the official SGLang repository. Please fork the repository under your GitHub account, then clone your fork locally.Install from Source
Build and install SGLang from source. This allows you to test your changes locally.Development Workflow
1. Create a Feature Branch
Never commit directly tomain. Always create a new branch:
2. Make Your Changes
Edit the code, add new features, or fix bugs. Follow the code style guidelines below.3. Format Code
We use pre-commit for code formatting and linting:4. Add Tests
Add unit tests for new features or bug fixes. SGLang uses Python’sunittest framework.
5. Write Documentation
Document your changes in the appropriate documentation files. We recommend new contributors start by writing documentation to quickly understand the codebase. For documentation guidelines, see docs/README.md.6. Test Accuracy (if applicable)
If your changes affect model output, run accuracy tests:7. Benchmark Performance (if applicable)
For performance-critical changes, benchmark your code:8. Commit and Push
Commit your changes with a descriptive message:9. Create Pull Request
Go to GitHub and create a Pull Request from your fork to the main SGLang repository.- Title: Clear and concise description of the change
- Description: Explain what the PR does, why it’s needed, and how to test it
- Link issues: If fixing a bug, reference the issue number
Code Review Process
Follow the process described in MAINTAINER.md:- Merge Oncall reviews the PR
- Codeowner reviews if touching their area
- Other reviewers may provide feedback
- Address feedback and update PR
- Once approved, the PR will be merged
CI Testing
Triggering CI
Only trusted contributors can trigger CI tests. If you have permission (listed in CI_PERMISSIONS.json), you can:/tag-run-ci-label: Add “run-ci” label to run CI on every commit/rerun-failed-ci: Rerun failed tests/tag-and-rerun-ci: Add label and rerun tests/rerun-stage <stage-name>: Rerun a specific test stage
/rerun-failed-ci on their own PRs.
If you don’t have permission, ask a maintainer to trigger CI for you.
CI Rate Limits
To prevent abuse, CI has rate limits. The default cooldown is 120 minutes between runs. Users inCI_PERMISSIONS.json may have custom limits.
Code Style Guidelines
General Principles
- Avoid code duplication: Extract repeated code (>5 lines) into functions
- Minimize device synchronization: Avoid
tensor.item()andtensor.cpu()in hot paths - Extreme efficiency: SGLang is a runtime—optimize everything on the critical path
- Pure functions: Avoid in-place modifications of arguments
- Keep files concise: Split files >2000 lines into smaller modules
- Fast tests: Split test files that run >500 seconds
Hardware/Feature Support
When adding support for new hardware or features:- Don’t drastically change existing code
- Use new files for hardware-specific components (e.g.,
allocator_ascend.py) - Common path first: Put the most common case (NVIDIA GPU) in the first if-branch
Example: Avoid Redundant Runtime Checks
Updating sgl-kernel
Sincesglang and sgl-kernel are separate packages, you cannot update a kernel and use it immediately in the same PR. Follow these steps:
- Submit PR to update sgl-kernel source without using it (example)
- Bump sgl-kernel version in a new PR (example)
- This triggers a PyPI release of the new kernel
- Use the new kernel in a third PR:
- Update
sgl-kernelversion inpyproject.toml - Update caller code in SGLang
- Update
Tips for Newcomers
- Start small: Pick issues labeled “good first issue” or “help wanted”
- Write docs: Documentation contributions help you learn the codebase
- Read the code walkthrough: Check out this code walkthrough for a deeper understanding
- Ask questions: Join our Slack channel for help
