Skip to content
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

Merged
merged 8 commits into from
Dec 31, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 116 additions & 12 deletions docs/references/contributor_guide.md
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**

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Fork and Clone the Repository

SGLang do not accept PR on the main repo. Please fork your own and clone it.

```
bash
git clone https://github.com/sgl-project/sglang.git
cd sglang

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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
```
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this line.


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-commit run --all-files will manually run all the configured checks on your repository, applying automatic fixes where possible. If it fails the first time, please run it again to make sure the lint errors are fixed. Ensure your code passes all these pre-commit link checks. Otherwise, there are grammar errors beyond style in your code. And do not commit to the main branch. Always checkout a new branch with a valid name and commit, then create a pull request on that branch.

Please ensure your code passes all these checks locally before creating a Pull Request.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/docs

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 index.rst if neccessary.

# 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Create new test files under /test, and ensure they are referenced in /test/srt/run_suite.py or /test/lang/run_suite.py, other they will not be picked up in CI.


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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.

### 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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!
Loading