[gRPC] Native gRPC server: proto + Rust crate scaffold + server args (#22736)

This commit is contained in:
Alex Nails
2026-04-20 12:39:35 +08:00
committed by GitHub
parent c304d0d64d
commit 10e17cc55e
9 changed files with 483 additions and 1 deletions
+6 -1
View File
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=61.0", "setuptools-scm>=8.0", "wheel"]
requires = ["setuptools>=61.0", "setuptools-scm>=8.0", "setuptools-rust>=1.10", "wheel"]
build-backend = "setuptools.build_meta"
[project]
@@ -217,5 +217,10 @@ git_describe_command = ["python3", "python/tools/get_version_tag.py"]
# Allow editable installs even when .git metadata is not available.
fallback_version = "0.0.0.dev0"
[[tool.setuptools-rust.ext-modules]]
target = "sglang.srt.grpc._core"
path = "../rust/sglang-grpc/Cargo.toml"
binding = "PyO3"
[tool.kernels.dependencies]
"kernels-community/sgl-flash-attn3" = 1
+3
View File
@@ -27,6 +27,9 @@ def run_server(server_args):
launch_server(server_args)
elif server_args.grpc_mode:
# TODO: Once the native Rust gRPC server starts alongside HTTP in the
# default path below (controlled by SGLANG_ENABLE_GRPC / SGLANG_GRPC_PORT),
# remove this legacy SMG path and the grpc_mode flag.
from sglang.srt.entrypoints.grpc_server import serve_grpc
asyncio.run(serve_grpc(server_args))
+4
View File
@@ -516,6 +516,10 @@ class Envs:
# Encoder receiver selection: http|grpc (used by EPD paths).
SGLANG_ENCODER_MM_RECEIVER_MODE = EnvStr("http")
# Native gRPC server (internal, not yet user-facing)
SGLANG_GRPC_PORT = EnvInt(None)
SGLANG_ENABLE_GRPC = EnvBool(False)
# External models
SGLANG_EXTERNAL_MODEL_PACKAGE = EnvStr("")
SGLANG_EXTERNAL_MM_MODEL_ARCH = EnvStr("")
+28
View File
@@ -999,6 +999,21 @@ class ServerArgs:
envs.SGLANG_SPEC_NAN_DETECTION.set(True)
envs.SGLANG_SPEC_OOB_DETECTION.set(True)
# Native gRPC flags — env-only for now, not exposed as CLI args.
# Set as instance attributes (not dataclass fields) to avoid
# argparse namespace lookup in from_cli_args.
self.enable_grpc = envs.SGLANG_ENABLE_GRPC.get()
grpc_port_env = envs.SGLANG_GRPC_PORT.get()
self.grpc_port = (
grpc_port_env if grpc_port_env is not None else self.port + 10000
)
if not (1 <= self.grpc_port <= 65535):
raise ValueError(
f"SGLANG_GRPC_PORT ({self.grpc_port}) must be between 1 and 65535"
)
def _handle_prefill_delayer_env_compat(self):
if envs.SGLANG_SCHEDULER_DECREASE_PREFILL_IDLE.get():
self.enable_prefill_delayer = True
@@ -6622,6 +6637,19 @@ class ServerArgs:
"When enabling two batch overlap, moe_a2a_backend cannot be 'none'."
)
if (
self.enable_grpc
and self.grpc_port is not None
and self.grpc_port == self.port
):
raise ValueError(
f"SGLANG_GRPC_PORT ({self.grpc_port}) must differ from --port ({self.port})"
)
# TODO: Also validate grpc_port != metrics_http_port and grpc_port != nccl_port
# to avoid opaque bind errors at runtime. Deferred because metrics_http_port
# and nccl_port have dynamic defaults that may not be resolved yet here.
if self.gc_threshold:
if not (1 <= len(self.gc_threshold) <= 3):
raise ValueError(