[grpc] Support gRPC server entrypoint (#30190)
Signed-off-by: Chang Su <chang.s.su@oracle.com> Signed-off-by: njhill <nickhill123@gmail.com> Signed-off-by: Nick Hill <nickhill123@gmail.com> Co-authored-by: njhill <nickhill123@gmail.com> Co-authored-by: Simon Mo <simon.mo@hey.com>
This commit is contained in:
73
setup.py
73
setup.py
@@ -18,6 +18,7 @@ import torch
|
||||
from packaging.version import Version, parse
|
||||
from setuptools import Extension, setup
|
||||
from setuptools.command.build_ext import build_ext
|
||||
from setuptools.command.build_py import build_py
|
||||
from setuptools_scm import get_version
|
||||
from torch.utils.cpp_extension import CUDA_HOME, ROCM_HOME
|
||||
|
||||
@@ -79,6 +80,73 @@ def is_freethreaded():
|
||||
return bool(sysconfig.get_config_var("Py_GIL_DISABLED"))
|
||||
|
||||
|
||||
def compile_grpc_protos():
|
||||
"""Compile gRPC protobuf definitions during build.
|
||||
|
||||
This generates *_pb2.py, *_pb2_grpc.py, and *_pb2.pyi files from
|
||||
the vllm_engine.proto definition.
|
||||
"""
|
||||
try:
|
||||
from grpc_tools import protoc
|
||||
except ImportError:
|
||||
logger.warning(
|
||||
"grpcio-tools not installed, skipping gRPC proto compilation. "
|
||||
"gRPC server functionality will not be available."
|
||||
)
|
||||
return False
|
||||
|
||||
proto_file = ROOT_DIR / "vllm" / "grpc" / "vllm_engine.proto"
|
||||
if not proto_file.exists():
|
||||
logger.warning("Proto file not found at %s, skipping compilation", proto_file)
|
||||
return False
|
||||
|
||||
logger.info("Compiling gRPC protobuf: %s", proto_file)
|
||||
|
||||
result = protoc.main(
|
||||
[
|
||||
"grpc_tools.protoc",
|
||||
f"--proto_path={ROOT_DIR}",
|
||||
f"--python_out={ROOT_DIR}",
|
||||
f"--grpc_python_out={ROOT_DIR}",
|
||||
f"--pyi_out={ROOT_DIR}",
|
||||
str(proto_file),
|
||||
]
|
||||
)
|
||||
|
||||
if result != 0:
|
||||
logger.error("protoc failed with exit code %s", result)
|
||||
return False
|
||||
|
||||
# Add SPDX headers and mypy ignore to generated files
|
||||
spdx_header = (
|
||||
"# SPDX-License-Identifier: Apache-2.0\n"
|
||||
"# SPDX-FileCopyrightText: Copyright contributors to the vLLM project\n"
|
||||
"# mypy: ignore-errors\n"
|
||||
)
|
||||
|
||||
grpc_dir = ROOT_DIR / "vllm" / "grpc"
|
||||
for generated_file in [
|
||||
grpc_dir / "vllm_engine_pb2.py",
|
||||
grpc_dir / "vllm_engine_pb2_grpc.py",
|
||||
grpc_dir / "vllm_engine_pb2.pyi",
|
||||
]:
|
||||
if generated_file.exists():
|
||||
content = generated_file.read_text()
|
||||
if not content.startswith("# SPDX-License-Identifier"):
|
||||
generated_file.write_text(spdx_header + content)
|
||||
|
||||
logger.info("gRPC protobuf compilation successful")
|
||||
return True
|
||||
|
||||
|
||||
class BuildPyAndGenerateGrpc(build_py):
|
||||
"""Build Python modules and generate gRPC stubs from proto files."""
|
||||
|
||||
def run(self):
|
||||
compile_grpc_protos()
|
||||
super().run()
|
||||
|
||||
|
||||
class CMakeExtension(Extension):
|
||||
def __init__(self, name: str, cmake_lists_dir: str = ".", **kwa) -> None:
|
||||
super().__init__(name, sources=[], py_limited_api=not is_freethreaded(), **kwa)
|
||||
@@ -882,12 +950,13 @@ if _no_device():
|
||||
ext_modules = []
|
||||
|
||||
if not ext_modules:
|
||||
cmdclass = {}
|
||||
cmdclass = {"build_py": BuildPyAndGenerateGrpc}
|
||||
else:
|
||||
cmdclass = {
|
||||
"build_ext": precompiled_build_ext
|
||||
if envs.VLLM_USE_PRECOMPILED
|
||||
else cmake_build_ext
|
||||
else cmake_build_ext,
|
||||
"build_py": BuildPyAndGenerateGrpc,
|
||||
}
|
||||
|
||||
setup(
|
||||
|
||||
Reference in New Issue
Block a user