-
Notifications
You must be signed in to change notification settings - Fork 720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Docs] refactor Contribution Guide #2690
Changes from 3 commits
36b8d64
3049ea7
a6e1c3e
a00c93e
23d2793
273648c
f99bf4b
d27c13a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,126 @@ | ||
# Contributor Guide | ||
# Contribution Guide | ||
|
||
## Build SGLang | ||
Welcome to **SGLang**! We appreciate your interest in contributing. This guide provides a concise overview of how to set up your environment, run tests, build documentation, and open a Pull Request (PR). Whether you’re fixing a small bug or developing a major feature, we encourage following these steps for a smooth contribution process. | ||
|
||
See [Install SGLang, Method 2: From Source section](../start/install.md). | ||
## 1. Setting Up & Building from Source | ||
|
||
## Format Your Code | ||
Use these commands to format your code and pass CI linting tests. | ||
1. **Clone the Repository** | ||
|
||
``` | ||
bash | ||
git clone https://github.com/sgl-project/sglang.git | ||
cd sglang | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. git clone https://github.com/<your_user_name>/sglang.git
cd sglang |
||
2. **Install Dependencies & Build** | ||
Refer to our [Install SGLang](https://sgl-project.github.io/start/install.html) documentation for a detailed explanation of setting up the necessary dependencies and compiling the codebase locally. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Install Dependencies and Build SGLang on the Latest Commit # Install flashinfer
pip install --upgrade pip
pip install -e "python[all]" --find-links https://flashinfer.ai/whl/cu124/torch2.4/flashinfer/
# Install latest SGLang
cd sglang/python
pip install . Note: Please check the FlashInfer installation doc to install the proper version according to your PyTorch and CUDA versions. |
||
## 2. Code Formatting with Pre-Commit | ||
|
||
We use [pre-commit](https://pre-commit.com/) to maintain consistent code quality and style checks. Before pushing your changes, please run: | ||
|
||
bash | ||
pip3 install pre-commit | ||
cd sglang | ||
pre-commit install | ||
pre-commit run --all-files | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pip3 install pre-commit
cd sglang
pre-commit run --all-files |
||
|
||
## Add Unit Tests | ||
Add unit tests under [sglang/test](https://github.com/sgl-project/sglang/tree/main/test). You can learn how to add and run tests from the README.md in that folder. | ||
|
||
## For Newcomers | ||
If you want to contribute or learn but don't have a concrete idea yet, you can pick a task labeled as "good first issue" or "help wanted" from the list below. | ||
[https://github.com/sgl-project/sglang/issues?q=is%3Aissue+label%3A%22good+first+issue%22%2C%22help+wanted%22](https://github.com/sgl-project/sglang/issues?q=is%3Aissue+label%3A%22good+first+issue%22%2C%22help+wanted%22) | ||
- **pre-commit install**: Installs the Git hook, which automatically runs style checks on staged files. | ||
- **pre-commit run --all-files**: Manually runs all the configured checks on your repository, applying automatic fixes where possible. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this line. |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Please ensure your code passes all these checks locally before creating a Pull Request. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete. |
||
## 3. Writing Documentation & Running Docs CI | ||
|
||
All documentation files are located in the docs folder. We use make commands for building, cleaning, and previewing the documentation. Below is the typical workflow: | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make commands => makefile |
||
1. **Compile Jupyter Notebooks** | ||
|
||
bash | ||
make compile | ||
|
||
This command processes all .ipynb files into intermediate formats. | ||
|
||
2. **Generate HTML Documentation** | ||
|
||
bash | ||
make html | ||
|
||
The generated static site can be found under the _build/html directory. | ||
|
||
3. **Local Preview** | ||
|
||
bash | ||
bash serve.sh | ||
|
||
Open your browser at the specified port to view the docs locally. | ||
|
||
4. **Clean Notebook Outputs & Build Artifacts** | ||
|
||
bash | ||
find . -name '*.ipynb' -exec nbstripout {} \; | ||
make clean | ||
|
||
- **nbstripout** removes all outputs from Jupyter notebooks. | ||
- **make clean** removes temporary files and _build artifacts. | ||
|
||
5. **Modify index.rst (If Necessary)** | ||
Update index.rst whenever you add or remove sections from the documentation. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We prefer Jupyter Notebook over Markdown files since its correctness can be ensured by our docs CI. First make a new file under approperiate path and modify # Compile all .ipynb and markdown files
# The jupyter notebooks will be executed
make compile
# Generate static files and they can be found under _build/html
make html
# Preview the docs
# Open your browser at the specified port to view the docs locally
bash serve.sh Once you are sure your docs are right and passed compile, make a PR. # Clean Notebook outputs to make your PR clear
pip install nbstripout
find . -name '*.ipynb' -exec nbstripout {} \;
# Run pre-commit
pre-commit run --all-files Then you can submit your PR. TODO: How to run server/engine and close server/engine in docs. |
||
6. **Pass Pre-Commit and Submit a PR** | ||
After confirming the docs build successfully and pass all checks, open a Pull Request. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete. |
||
CI will automatically build and validate the documentation to ensure consistency and completeness before merging. | ||
|
||
## 4. Running Unit Tests Locally & Adding to CI | ||
|
||
SGLang uses Python’s built-in [unittest](https://docs.python.org/3/library/unittest.html) framework. You can run tests either individually or in suites. | ||
|
||
### 4.1 Test Backend Runtime | ||
|
||
bash | ||
cd sglang/test/srt | ||
|
||
# Run a single file | ||
python3 test_srt_endpoint.py | ||
|
||
# Run a single test | ||
python3 -m unittest test_srt_endpoint.TestSRTEndpoint.test_simple_decode | ||
|
||
# Run a suite with multiple files | ||
python3 run_suite.py --suite minimal | ||
|
||
|
||
### 4.2 Test Frontend Language | ||
|
||
bash | ||
cd sglang/test/lang | ||
export OPENAI_API_KEY=sk-***** | ||
|
||
# Run a single file | ||
python3 test_openai_backend.py | ||
|
||
# Run a single test | ||
python3 -m unittest test_openai_backend.TestOpenAIBackend.test_few_shot_qa | ||
|
||
# Run a suite with multiple files | ||
python3 run_suite.py --suite minimal | ||
|
||
|
||
### 4.3 Adding or Updating Tests in CI | ||
|
||
- Create new test files under test/srt, ensure they are referenced in test/srt/run_suite.py, or they will not be picked up. | ||
- In CI, all tests are executed automatically. You may modify the corresponding workflow in .github/workflows/ if you wish to include custom test groups or additional checks. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
### 4.4 Writing Elegant Test Cases | ||
|
||
- Examine existing tests in [sglang/test](https://github.com/sgl-project/sglang/tree/main/test) for practical examples. | ||
- Keep each test function focused on a specific scenario or unit of functionality. | ||
- Give tests descriptive names reflecting their purpose. | ||
- Use robust assertions (e.g., assert, unittest methods) to validate outcomes. | ||
- Clean up resources to avoid side effects and preserve test independence. | ||
|
||
## 5. Tips for Newcomers | ||
|
||
If you want to contribute but don’t have a specific idea in mind, start by picking up issues labeled [“good first issue” or “help wanted”](https://github.com/sgl-project/sglang/issues?q=is%3Aissue+label%3A%22good+first+issue%22%2C%22help+wanted%22). These tasks typically have lower complexity and provide an excellent introduction to the codebase. Feel free to ask questions or request clarifications in the corresponding issue threads. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
Thank you again for your interest in SGLang! If you have any questions along the way, feel free to open an issue or start a thread in our [slack channel](https://join.slack.com/t/sgl-fru7574/shared_invite/zt-2um0ad92q-LkU19KQTxCGzlCgRiOiQEw). Happy coding! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGLang do not accept PR on the main repo. Please fork your own and clone it.