Skip to content

[#17016][refactor] Isolate SMG gRPC protocol integration - #17221

Closed
connorcarpenter15 wants to merge 1 commit into
NVIDIA:mainfrom
connorcarpenter15:refactor/grpc-protocol-layout
Closed

[#17016][refactor] Isolate SMG gRPC protocol integration#17221
connorcarpenter15 wants to merge 1 commit into
NVIDIA:mainfrom
connorcarpenter15:refactor/grpc-protocol-layout

Conversation

@connorcarpenter15

@connorcarpenter15 connorcarpenter15 commented Aug 3, 2026

Copy link
Copy Markdown

Dev Engineer Review

  • Refactored SMG gRPC code into tensorrt_llm.grpc.smg.
  • Kept tensorrt_llm.grpc protocol-neutral.
  • Added tensorrt_llm.grpc.smg.server.launch_server.
  • Added --grpc-protocol {smg,openengine}.
  • Preserved smg as the default protocol.
  • Rejected openengine until its follow-up implementation is available.
  • Updated the CLI stability reference.
  • No OpenEngine dependencies were added.
  • Pre-commit and Python compilation checks passed.
  • Python test suites require upstream CI builds with matching compiled bindings.

QA Engineer Review

  • Modified tests/unittest/grpc/smg/test_server.py.
  • Updated existing SMG gRPC test imports and utility paths.
  • No test functions were added, removed, or functionally changed.
  • No tests/integration/test_lists/ files were modified, so CI or manual-QA list coverage is not declared.
  • Verdict: needs follow-up for upstream CI validation with matching compiled bindings.

Description

  • Move the existing SMG request conversion, servicer, server lifecycle, and unit tests into protocol-specific grpc/smg directories.
  • Keep tensorrt_llm.grpc protocol-neutral.
  • Add --grpc-protocol {smg,openengine} with smg as the backward-compatible default for --grpc.
  • Reserve the OpenEngine selector for follow-up PR [#17016][feat] Add selectable OpenEngine gRPC server #17084; this PR is its prerequisite and does not add OpenEngine dependencies or implementation.

Related RFC: #17016.

Maintainer action: please apply the api-compatible label; GitHub does not grant external contributors permission to label upstream PRs.

Test Coverage

  • Existing SMG unit coverage is preserved at tests/unittest/grpc/smg/test_server.py.
  • Updated the trtllm-serve CLI 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 main APIs, 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-compatible or api-breaking. For api-breaking, include BREAKING in 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.

Signed-off-by: Connor Carpenter <connorc@nvidia.com>
@connorcarpenter15 connorcarpenter15 changed the title [None][refactor] Isolate SMG gRPC protocol integration [#17016][refactor] Isolate SMG gRPC protocol integration Aug 3, 2026
@connorcarpenter15
connorcarpenter15 marked this pull request as ready for review August 3, 2026 21:54
@connorcarpenter15
connorcarpenter15 requested review from a team as code owners August 3, 2026 21:54
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The serve command adds SMG gRPC protocol selection and launches a new SMG server module. The gRPC package exports move into tensorrt_llm.grpc.smg, with optional imports and updated tests.

Changes

SMG gRPC server foundation

Layer / File(s) Summary
SMG package and server foundation
tensorrt_llm/grpc/..., tests/unittest/grpc/smg/test_server.py
The SMG package now owns optional gRPC exports. The new server initializes the backend, starts asynchronous gRPC serving, supports reflection, and shuts down on signals. Tests use the reorganized imports.

Serve command protocol routing

Layer / File(s) Summary
Serve command protocol routing
tensorrt_llm/commands/serve.py, tests/unittest/api_stability/references/trtllm_serve_cli.yaml
The CLI adds --grpc-protocol with smg and openengine choices. The command requires --grpc, rejects openengine, and launches the SMG server.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: qijune

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the refactor that isolates SMG gRPC protocol integration and follows the required ticket and type format.
Description check ✅ Passed The description explains the refactor, protocol option, testing, limitations, and checklist status with relevant details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 73efcee and 735b65b.

📒 Files selected for processing (8)
  • tensorrt_llm/commands/serve.py
  • tensorrt_llm/grpc/__init__.py
  • tensorrt_llm/grpc/smg/__init__.py
  • tensorrt_llm/grpc/smg/request_manager.py
  • tensorrt_llm/grpc/smg/server.py
  • tensorrt_llm/grpc/smg/servicer.py
  • tests/unittest/api_stability/references/trtllm_serve_cli.yaml
  • tests/unittest/grpc/smg/test_server.py

Comment on lines +40 to +74
# 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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.py

Repository: 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.py

Repository: 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)
PY

Repository: 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.py

Repository: 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)
PY

Repository: 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.

@connorcarpenter15

Copy link
Copy Markdown
Author

Superseded by #17084, which now contains this SMG refactor together with the OpenEngine stub and the shared --grpc-protocol integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant