[#17016][refactor] Isolate SMG gRPC protocol integration - #17221
[#17016][refactor] Isolate SMG gRPC protocol integration#17221connorcarpenter15 wants to merge 1 commit into
Conversation
Signed-off-by: Connor Carpenter <connorc@nvidia.com>
WalkthroughThe ChangesSMG gRPC server foundation
Serve command protocol routing
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant CLI
participant serve
participant launch_server
participant TensorRTLLMBackend
participant AsyncGRPCServer
CLI->>serve: pass --grpc --grpc-protocol smg
serve->>launch_server: forward host, port, LLM arguments, and model name
launch_server->>TensorRTLLMBackend: initialize backend
launch_server->>AsyncGRPCServer: register SMG service and start
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tensorrt_llm/grpc/smg/__init__.py`:
- Around line 40-74: The optional protobuf fallback in the module-level imports
causes request_manager and servicer imports to fail with an unclear
AttributeError when smg-grpc-proto is unavailable. Update the import flow around
PROTOS_AVAILABLE, REQUEST_MANAGER_AVAILABLE, and SERVICER_AVAILABLE so
protobuf-dependent modules are imported only after validating the generated
protobuf package, or raise a clear installation error before those imports;
preserve normal imports when smg-grpc-proto is installed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 0bfc9938-e917-4ad3-869a-c00c05765633
📒 Files selected for processing (8)
tensorrt_llm/commands/serve.pytensorrt_llm/grpc/__init__.pytensorrt_llm/grpc/smg/__init__.pytensorrt_llm/grpc/smg/request_manager.pytensorrt_llm/grpc/smg/server.pytensorrt_llm/grpc/smg/servicer.pytests/unittest/api_stability/references/trtllm_serve_cli.yamltests/unittest/grpc/smg/test_server.py
| # Try to import generated protobuf modules from smg-grpc-proto package | ||
| try: | ||
| from smg_grpc_proto.generated import trtllm_service_pb2, trtllm_service_pb2_grpc | ||
|
|
||
| PROTOS_AVAILABLE = True | ||
| except ImportError: | ||
| PROTOS_AVAILABLE = False | ||
| trtllm_service_pb2 = None | ||
| trtllm_service_pb2_grpc = None | ||
|
|
||
| # Try to import request manager | ||
| try: | ||
| from .request_manager import ( | ||
| GrpcRequestManager, | ||
| create_disaggregated_params_from_proto, | ||
| create_lora_request_from_proto, | ||
| create_sampling_params_from_proto, | ||
| ) | ||
|
|
||
| REQUEST_MANAGER_AVAILABLE = True | ||
| except ImportError: | ||
| REQUEST_MANAGER_AVAILABLE = False | ||
| GrpcRequestManager = None | ||
| create_sampling_params_from_proto = None | ||
| create_lora_request_from_proto = None | ||
| create_disaggregated_params_from_proto = None | ||
|
|
||
| # Try to import servicer | ||
| try: | ||
| from .servicer import TrtllmServiceServicer | ||
|
|
||
| SERVICER_AVAILABLE = True | ||
| except ImportError: | ||
| SERVICER_AVAILABLE = False | ||
| TrtllmServiceServicer = None |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect how request_manager.py and servicer.py reference the optional protobuf module,
# and confirm whether launch_server guards against missing smg-grpc-proto.
echo "=== smg/__init__.py ==="
cat -n tensorrt_llm/grpc/smg/__init__.py
echo "=== request_manager.py head (imports and type hints) ==="
sed -n '1,60p' tensorrt_llm/grpc/smg/request_manager.py
echo "=== servicer.py head (imports) ==="
sed -n '1,45p' tensorrt_llm/grpc/smg/servicer.py
echo "=== server.py (full) ==="
cat -n tensorrt_llm/grpc/smg/server.pyRepository: NVIDIA/TensorRT-LLM
Length of output: 12433
🏁 Script executed:
#!/bin/bash
set -eu
echo "=== protobuf references in request_manager.py and servicer.py ==="
rg -n -C 2 'pb2|trtllm_service_pb2' \
tensorrt_llm/grpc/smg/request_manager.py \
tensorrt_llm/grpc/smg/servicer.py
echo "=== definitions with protobuf annotations ==="
rg -n -C 3 'def .*pb2|-> .*pb2|: .*pb2' \
tensorrt_llm/grpc/smg/request_manager.py \
tensorrt_llm/grpc/smg/servicer.py
echo "=== package import dependency edges ==="
rg -n -C 2 'from \\. import|from \\.request_manager|from \\.servicer|class .*trtllm_service' \
tensorrt_llm/grpc/smg/__init__.py \
tensorrt_llm/grpc/smg/request_manager.py \
tensorrt_llm/grpc/smg/servicer.py \
tensorrt_llm/grpc/smg/server.pyRepository: NVIDIA/TensorRT-LLM
Length of output: 24118
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import ast
for name in (
"tensorrt_llm/grpc/smg/request_manager.py",
"tensorrt_llm/grpc/smg/servicer.py",
):
tree = ast.parse(Path(name).read_text())
print(f"=== {name} ===")
for node in ast.walk(tree):
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
annotations = []
for arg in [*node.args.posonlyargs, *node.args.args, *node.args.kwonlyargs]:
if arg.annotation is not None:
annotations.append(ast.unparse(arg.annotation))
if node.args.vararg and node.args.vararg.annotation:
annotations.append(ast.unparse(node.args.vararg.annotation))
if node.args.kwarg and node.args.kwarg.annotation:
annotations.append(ast.unparse(node.args.kwarg.annotation))
if node.returns is not None:
annotations.append(ast.unparse(node.returns))
if any("pb2" in annotation for annotation in annotations):
print(node.lineno, node.name, annotations)
PYRepository: NVIDIA/TensorRT-LLM
Length of output: 1904
🏁 Script executed:
#!/bin/bash
set -eu
echo "=== protobuf references in request_manager.py and servicer.py ==="
rg -n -C 2 'pb2|trtllm_service_pb2' \
tensorrt_llm/grpc/smg/request_manager.py \
tensorrt_llm/grpc/smg/servicer.py
echo "=== definitions with protobuf annotations ==="
rg -n -C 3 'def .*pb2|-> .*pb2|: .*pb2' \
tensorrt_llm/grpc/smg/request_manager.py \
tensorrt_llm/grpc/smg/servicer.py
echo "=== package import dependency edges ==="
rg -n -C 2 'from \\. import|from \\.request_manager|from \\.servicer|class .*trtllm_service' \
tensorrt_llm/grpc/smg/__init__.py \
tensorrt_llm/grpc/smg/request_manager.py \
tensorrt_llm/grpc/smg/servicer.pyRepository: NVIDIA/TensorRT-LLM
Length of output: 24118
🏁 Script executed:
#!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import ast
for name in (
"tensorrt_llm/grpc/smg/request_manager.py",
"tensorrt_llm/grpc/smg/servicer.py",
):
tree = ast.parse(Path(name).read_text())
print(f"=== {name} ===")
for node in ast.walk(tree):
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
annotations = []
for arg in [
*node.args.posonlyargs,
*node.args.args,
*node.args.kwonlyargs,
]:
if arg.annotation is not None:
annotations.append(ast.unparse(arg.annotation))
if node.args.vararg and node.args.vararg.annotation:
annotations.append(ast.unparse(node.args.vararg.annotation))
if node.args.kwarg and node.args.kwarg.annotation:
annotations.append(ast.unparse(node.args.kwarg.annotation))
if node.returns is not None:
annotations.append(ast.unparse(node.returns))
if any("pb2" in annotation for annotation in annotations):
print(node.lineno, node.name, annotations)
PYRepository: NVIDIA/TensorRT-LLM
Length of output: 1904
Fail clearly when smg-grpc-proto is missing. request_manager.py evaluates pb2.* annotations during import, so the None fallback raises AttributeError before launch_server() runs. Make these imports lazy or raise a clear error before importing them, such as Install smg-grpc-proto to use --grpc.
[medium_effort_and_high_reward]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tensorrt_llm/grpc/smg/__init__.py` around lines 40 - 74, The optional
protobuf fallback in the module-level imports causes request_manager and
servicer imports to fail with an unclear AttributeError when smg-grpc-proto is
unavailable. Update the import flow around PROTOS_AVAILABLE,
REQUEST_MANAGER_AVAILABLE, and SERVICER_AVAILABLE so protobuf-dependent modules
are imported only after validating the generated protobuf package, or raise a
clear installation error before those imports; preserve normal imports when
smg-grpc-proto is installed.
|
Superseded by #17084, which now contains this SMG refactor together with the OpenEngine stub and the shared |
Dev Engineer Review
tensorrt_llm.grpc.smg.tensorrt_llm.grpcprotocol-neutral.tensorrt_llm.grpc.smg.server.launch_server.--grpc-protocol {smg,openengine}.smgas the default protocol.openengineuntil its follow-up implementation is available.QA Engineer Review
tests/unittest/grpc/smg/test_server.py.tests/integration/test_lists/files were modified, so CI or manual-QA list coverage is not declared.Description
grpc/smgdirectories.tensorrt_llm.grpcprotocol-neutral.--grpc-protocol {smg,openengine}withsmgas the backward-compatible default for--grpc.Related RFC: #17016.
Maintainer action: please apply the
api-compatiblelabel; GitHub does not grant external contributors permission to label upstream PRs.Test Coverage
tests/unittest/grpc/smg/test_server.py.trtllm-serveCLI stability reference for--grpc-protocol.pre-commit run --files <changed files>python3 -m py_compile <changed Python files>The local rc21 container's compiled bindings predate the current
mainAPIs, so the Python suites require upstream CI's matching build.PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.