Skip to content

Commit 7638f5e

Browse files
authored
[router] Implement gRPC SGLangSchedulerClient (#9364)
1 parent b45f753 commit 7638f5e

File tree

10 files changed

+388
-8
lines changed

10 files changed

+388
-8
lines changed

.github/workflows/release-pypi-router.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
env:
4848
CIBW_BUILD: "cp38-manylinux_x86_64 cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64"
4949
CIBW_BEFORE_ALL: |
50-
yum update && yum install -y openssl-devel && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
50+
yum update && yum install -y openssl-devel protobuf-compiler && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
5151
CIBW_ENVIRONMENT: "PATH=$HOME/.cargo/bin:$PATH"
5252

5353
- name: List built packages

docker/Dockerfile.router

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ ENV PATH="/root/.cargo/bin:${PATH}"
3939

4040
# install dependencies
4141
RUN apt update -y \
42-
&& apt install -y git build-essential libssl-dev pkg-config \
42+
&& apt install -y git build-essential libssl-dev pkg-config protobuf-compiler \
4343
&& rm -rf /var/lib/apt/lists/* \
4444
&& apt clean
4545

4646
# install rustup from rustup.rs
4747
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
48-
&& rustc --version && cargo --version
48+
&& rustc --version && cargo --version && protoc --version
4949

5050
# pull the github repository
5151
RUN cd /opt \

scripts/ci/ci_install_rust.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ set -euxo pipefail
44
# Check if sudo is available
55
if command -v sudo >/dev/null 2>&1; then
66
sudo apt-get update
7-
sudo apt-get install -y libssl-dev pkg-config
7+
sudo apt-get install -y libssl-dev pkg-config protobuf-compiler
88
else
99
apt-get update
10-
apt-get install -y libssl-dev pkg-config
10+
apt-get install -y libssl-dev pkg-config protobuf-compiler
1111
fi
1212

1313
# Install rustup (Rust installer and version manager)
@@ -21,3 +21,4 @@ source $HOME/.cargo/env
2121
# Verify installation
2222
rustc --version
2323
cargo --version
24+
protoc --version

sgl-router/Cargo.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ version = "0.0.0"
44
edition = "2021"
55

66
[features]
7-
default = ["huggingface"]
7+
default = ["huggingface", "grpc-client"]
88
huggingface = ["tokenizers"]
99
tiktoken = ["tiktoken-rs"]
10+
grpc-client = []
11+
grpc-server = []
1012

1113
[lib]
1214
name = "sglang_router_rs"
@@ -52,6 +54,18 @@ anyhow = "1.0"
5254
tokenizers = { version = "0.21.4", optional = true }
5355
tiktoken-rs = { version = "0.5", optional = true }
5456

57+
# gRPC and Protobuf dependencies
58+
tonic = { version = "0.12", features = ["tls", "gzip", "transport"] }
59+
prost = "0.13"
60+
prost-types = "0.13"
61+
deadpool = { version = "0.12", features = ["managed", "rt_tokio_1"] }
62+
backoff = { version = "0.4", features = ["tokio"] }
63+
strum = { version = "0.26", features = ["derive"] }
64+
65+
[build-dependencies]
66+
tonic-build = "0.12"
67+
prost-build = "0.13"
68+
5569
[dev-dependencies]
5670
criterion = { version = "0.5", features = ["html_reports"] }
5771
tower = { version = "0.5", features = ["util"] }

sgl-router/MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Must include:
22
include Cargo.toml # Rust project configuration
3+
include build.rs # Build script for protobuf generation
34
recursive-include src *.rs # Rust source files
5+
recursive-include src/proto *.proto # Protobuf definitions

sgl-router/build.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
fn main() -> Result<(), Box<dyn std::error::Error>> {
2+
// Only regenerate if the proto file changes
3+
println!("cargo:rerun-if-changed=src/proto/sglang_scheduler.proto");
4+
5+
// Configure protobuf compilation with custom settings
6+
let config = prost_build::Config::new();
7+
8+
// Skip serde for types that use prost_types::Struct
9+
// These cause conflicts and we don't need serde for all generated types
10+
11+
// Configure tonic-build for gRPC code generation
12+
tonic_build::configure()
13+
// Generate both client and server code
14+
.build_server(true)
15+
.build_client(true)
16+
// Add a module-level attribute for documentation and clippy warnings
17+
.server_mod_attribute(
18+
"sglang.grpc.scheduler",
19+
"#[allow(unused, clippy::mixed_attributes_style)]",
20+
)
21+
.client_mod_attribute(
22+
"sglang.grpc.scheduler",
23+
"#[allow(unused, clippy::mixed_attributes_style)]",
24+
)
25+
// Compile the proto file with the custom config
26+
.compile_protos_with_config(
27+
config,
28+
&["src/proto/sglang_scheduler.proto"],
29+
&["src/proto"],
30+
)?;
31+
32+
println!("cargo:warning=Protobuf compilation completed successfully");
33+
34+
Ok(())
35+
}

0 commit comments

Comments
 (0)