README.md 2.21 KB
Newer Older
Byron Hsu's avatar
Byron Hsu committed
1
# SGLang Router
2
3
4

SGLang router is a standalone module implemented in Rust to achieve data parallelism across SGLang instances.

5
## User docs
Byron Hsu's avatar
Byron Hsu committed
6

7
Please check https://sgl-project.github.io/router/router.html
8

9
## Developer docs
10

11
### Prerequisites
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

- Rust and Cargo installed

```bash
# Install rustup (Rust installer and version manager)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Follow the installation prompts, then reload your shell
source $HOME/.cargo/env

# Verify installation
rustc --version
cargo --version
```

- Python with pip installed

29

Byron Hsu's avatar
Byron Hsu committed
30
### Build Process
31

Byron Hsu's avatar
Byron Hsu committed
32
#### 1. Build Rust Project
33
34

```bash
35
$ cargo build
36
37
```

Byron Hsu's avatar
Byron Hsu committed
38
#### 2. Build Python Binding
39

Byron Hsu's avatar
Byron Hsu committed
40
##### Option A: Build and Install Wheel
41
42
1. Build the wheel package:
```bash
43
44
$ pip install setuptools-rust wheel build
$ python -m build
45
46
47
48
```

2. Install the generated wheel:
```bash
49
50
51
52
53
54
55
$ pip install <path-to-wheel>
```

If you want one handy command to do build + install for every change you make:

```bash
$ python -m build && pip install --force-reinstall dist/*.whl
56
57
```

Byron Hsu's avatar
Byron Hsu committed
58
##### Option B: Development Mode
59
60

For development purposes, you can install the package in editable mode:
61
62
63

Warning: Using editable python binding can suffer from performance degradation!! Please build a fresh wheel for every update if you want to test performance.

64
```bash
65
$ pip install -e .
66
67
68
69
```

**Note:** When modifying Rust code, you must rebuild the wheel for changes to take effect.

Byron Hsu's avatar
Byron Hsu committed
70
### CI/CD Setup
71
72
73

The continuous integration pipeline consists of three main steps:

Byron Hsu's avatar
Byron Hsu committed
74
#### 1. Build Wheels
75
76
77
78
79
- Uses `cibuildwheel` to create manylinux x86_64 packages
- Compatible with major Linux distributions (Ubuntu, CentOS, etc.)
- Additional configurations can be added to support other OS/architectures
- Reference: [cibuildwheel documentation](https://cibuildwheel.pypa.io/en/stable/)

Byron Hsu's avatar
Byron Hsu committed
80
#### 2. Build Source Distribution
81
82
83
- Creates a source distribution containing the raw, unbuilt code
- Enables `pip` to build the package from source when prebuilt wheels are unavailable

Byron Hsu's avatar
Byron Hsu committed
84
#### 3. Publish to PyPI
85
86
87
- Uploads both wheels and source distribution to PyPI

The CI configuration is based on the [tiktoken workflow](https://github.com/openai/tiktoken/blob/63527649963def8c759b0f91f2eb69a40934e468/.github/workflows/build_wheels.yml#L1).