Skip to content

Conversation

@nv-guomingz
Copy link
Collaborator

@nv-guomingz nv-guomingz commented Aug 23, 2025

We need to put the quickstart_example.py which use trt flow under _tensorrt_engine folder.

Summary by CodeRabbit

  • New Features

    • Optional build-time configuration exposed for advanced users (BuildConfig) while default initialization remains simplified.
    • Sampling settings can now be provided at generation time via SamplingParams.
  • Refactor

    • Unified top-level imports for LLM and SamplingParams to streamline usage.
  • Documentation

    • Quickstart examples updated to show both simplified init and optional build-config workflows and generate(prompts, sampling_params) usage.

@nv-guomingz nv-guomingz requested a review from Superjomn August 23, 2025 10:48
@nv-guomingz nv-guomingz requested a review from a team as a code owner August 23, 2025 10:48
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 23, 2025

📝 Walkthrough

Walkthrough

Two example quickstart scripts were updated: the internal engine example now imports LLM from tensorrt_llm._tensorrt_engine, constructs and passes a BuildConfig; the public quickstart uses the top-level tensorrt_llm LLM and moves sampling configuration to generate(...) via SamplingParams.

Changes

Cohort / File(s) Summary
Internal engine-based quickstart
examples/llm-api/_tensorrt_engine/quickstart_example.py
Import LLM from tensorrt_llm._tensorrt_engine; import BuildConfig from top-level tensorrt_llm; create/configure BuildConfig (max_batch_size=256, max_num_tokens=1024); pass build_config to LLM(...).
Public API quickstart
examples/llm-api/quickstart_example.py
Import LLM, SamplingParams from tensorrt_llm; remove BuildConfig; change LLM construction to only model; create SamplingParams and call llm.generate(prompts, sampling_params).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant Q_int as Internal quickstart
  participant Q_pub as Public quickstart
  participant L_int as LLM (internal)
  participant L_pub as LLM (public)
  participant E as Engine/Runtime

  rect rgb(235,245,255)
  U->>Q_int: run internal example
  Q_int->>L_int: new LLM(model, build_config)
  Q_int->>L_int: generate(prompts)
  L_int->>E: execute with build-time config
  E-->>L_int: responses
  L_int-->>Q_int: results
  end

  rect rgb(245,255,235)
  U->>Q_pub: run public example
  Q_pub->>L_pub: new LLM(model)
  Q_pub->>L_pub: generate(prompts, sampling_params)
  L_pub->>E: execute with run-time sampling params
  E-->>L_pub: responses
  L_pub-->>Q_pub: results
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Documentation

Suggested reviewers

  • niukuo
  • yuxianq

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ad3b773 and bbf390a.

📒 Files selected for processing (2)
  • examples/llm-api/_tensorrt_engine/quickstart_example.py (1 hunks)
  • examples/llm-api/quickstart_example.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • examples/llm-api/quickstart_example.py
  • examples/llm-api/_tensorrt_engine/quickstart_example.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nv-guomingz
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16264 [ run ] triggered by Bot

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
examples/llm-api/_tensorrt_engine/quickstart_example.py (1)

2-2: Remove the inline “NOTE the change” comment.

The directory location already communicates the intent; keeping code comments neutral/concise improves readability.

Apply:

-from tensorrt_llm._tensorrt_engine import LLM  # NOTE the change
+from tensorrt_llm._tensorrt_engine import LLM
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3f2eb4d and ad3b773.

📒 Files selected for processing (2)
  • examples/llm-api/_tensorrt_engine/quickstart_example.py (1 hunks)
  • examples/llm-api/quickstart_example.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: Python code must target Python 3.8+
Python indentation: 4 spaces, no tabs
Maintain module namespace in imports (from package.subpackage import foo; then use foo.SomeClass())
Python file names use snake_case
Python class names use PascalCase
Python functions/methods and local variables use snake_case; variables starting with a number get k_ prefix (e.g., k_99th_percentile)
Global variables use G_ prefixed UPPER_SNAKE_CASE (e.g., G_MY_GLOBAL)
Constants use UPPER_SNAKE_CASE in Python
Avoid shadowing variables from outer scopes in Python
Initialize all externally visible members of a Python class in init
Prefer docstrings for interfaces used outside a file; comments for local code
Use Google-style docstrings for classes and functions (Sphinx-parsable)
Document attributes/variables inline with short docstrings
Avoid reflection when simple alternatives exist (e.g., prefer explicit parameters over dict(**locals()))
In try/except, catch the narrowest exceptions possible
For duck-typing with try/except, keep try body minimal and put logic in else

Files:

  • examples/llm-api/_tensorrt_engine/quickstart_example.py
  • examples/llm-api/quickstart_example.py
**/*.{cpp,cxx,cc,cu,h,hpp,hxx,hh,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Prepend NVIDIA copyright header (current year) to all source files

Files:

  • examples/llm-api/_tensorrt_engine/quickstart_example.py
  • examples/llm-api/quickstart_example.py
🧠 Learnings (2)
📚 Learning: 2025-08-01T15:14:45.673Z
Learnt from: yibinl-nvidia
PR: NVIDIA/TensorRT-LLM#6506
File: examples/models/core/mixtral/requirements.txt:3-3
Timestamp: 2025-08-01T15:14:45.673Z
Learning: In TensorRT-LLM, examples directory can have different dependency versions than the root requirements.txt file. Version conflicts between root and examples dependencies are acceptable because examples are designed to be standalone and self-contained.

Applied to files:

  • examples/llm-api/_tensorrt_engine/quickstart_example.py
📚 Learning: 2025-08-06T13:58:07.506Z
Learnt from: galagam
PR: NVIDIA/TensorRT-LLM#6487
File: tests/unittest/_torch/auto_deploy/unit/singlegpu/test_ad_trtllm_bench.py:1-12
Timestamp: 2025-08-06T13:58:07.506Z
Learning: In TensorRT-LLM, test files (files under tests/ directories) do not require NVIDIA copyright headers, unlike production source code files. Test files typically start directly with imports, docstrings, or code.

Applied to files:

  • examples/llm-api/_tensorrt_engine/quickstart_example.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
🔇 Additional comments (7)
examples/llm-api/_tensorrt_engine/quickstart_example.py (4)

1-2: Import split matches workflows (public BuildConfig + internal LLM).

This separation aligns with the PR goal to keep the TRT-flow example under _tensorrt_engine. Looks good.


13-14: Using build_config during LLM construction is appropriate for engine-centric examples.

Instantiation path is consistent with the internal TRT flow expectations.


26-29: Example code is correct for TensorRT-LLM 1.0’s Python API

Per the official API reference, LLM.generate() returns RequestOutput objects (or a list thereof), each of which exposes:

  • a .prompt field for the input prompt (nvidia.github.io)
  • an .outputs list of CompletionOutput items, where each CompletionOutput has a .text string field containing the generated text (nvidia.github.io)

The snippet:

for output in llm.generate(prompts, sampling_params):
    print(
        f"Prompt: {output.prompt!r}, Generated text: {output.outputs[0].text!r}"
    )

correctly reflects these types. Please disregard the earlier concern about missing .prompt or .outputs[0].text.

Likely an incorrect or invalid review comment.


7-9: BuildConfig fields are correct—no changes needed.

The BuildConfig dataclass in tensorrt_llm/builder.py defines both
max_batch_size: int (default 2048)
max_num_tokens: int (default 8192)
at lines 485–487, matching the example’s usage.

examples/llm-api/quickstart_example.py (3)

1-1: Switch to top-level public API import looks correct.

Using from tensorrt_llm import LLM, SamplingParams matches the public workflow.


8-8: LLM construction without build-time config aligns with the public quickstart.

Keeping build-time details out of the public example is the right call.


20-23: Verified generate signature matches example usage

The call to llm.generate(prompts, sampling_params) correctly aligns with the current LLM.generate signature in llmapi/llm.py, where the first two parameters are:

  • inputs: Union[PromptInputs, Sequence[PromptInputs]]
  • sampling_params: Optional[Union[SamplingParams, List[SamplingParams]]] = None

No further changes are needed at this time.

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16264 [ run ] completed with state SUCCESS
/LLM/release-1.0/L0_MergeRequest_PR pipeline #276 completed with status: 'SUCCESS'

@Superjomn Superjomn requested a review from kaiyux August 25, 2025 00:22
Copy link
Collaborator

@Superjomn Superjomn left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
@nv-guomingz nv-guomingz force-pushed the user/guomingz/fix_llmapi_doc branch from ad3b773 to bbf390a Compare August 25, 2025 01:41
@nv-guomingz
Copy link
Collaborator Author

/bot reuse-pipeline

@tensorrt-cicd
Copy link
Collaborator

PR_Github #16341 [ reuse-pipeline ] triggered by Bot

@nv-guomingz nv-guomingz enabled auto-merge (squash) August 25, 2025 01:47
@tensorrt-cicd
Copy link
Collaborator

PR_Github #16341 [ reuse-pipeline ] completed with state SUCCESS
Reusing PR_Github #16264 for commit bbf390a

@nv-guomingz nv-guomingz merged commit 01c5f2f into NVIDIA:release/1.0 Aug 25, 2025
5 checks passed
yuanjingx87 pushed a commit that referenced this pull request Aug 28, 2025
…7182)

Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 5, 2025
…VIDIA#7182)

Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
Signed-off-by: Wangshanshan <30051912+dominicshanshan@users.noreply.github.com>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 5, 2025
…VIDIA#7182)

Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
Signed-off-by: Wangshanshan <30051912+dominicshanshan@users.noreply.github.com>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 6, 2025
…VIDIA#7182)

Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
Signed-off-by: Wangshanshan <30051912+dominicshanshan@users.noreply.github.com>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 6, 2025
…VIDIA#7182)

Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
Signed-off-by: Wangshanshan <30051912+dominicshanshan@users.noreply.github.com>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Sep 7, 2025
…VIDIA#7182)

Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
Signed-off-by: Wangshanshan <30051912+dominicshanshan@users.noreply.github.com>
@nv-guomingz nv-guomingz deleted the user/guomingz/fix_llmapi_doc branch September 30, 2025 07:53
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.

4 participants