Skip to content

Conversation

@tanmayv25
Copy link
Contributor

@tanmayv25 tanmayv25 commented Jul 30, 2025

Overview:

These defaults are picked from trtllm-serve stack. Without these optimizations, larger models like DS R1 can run into OOM.

See here for more information: https://github.com/NVIDIA/TensorRT-LLM/blob/main/tensorrt_llm/commands/serve.py#L94-L149

Summary by CodeRabbit

  • New Features

    • Added new configuration options for advanced parallelism and resource limits, including pipeline parallel size, expert parallel size, GPUs per node, and GPU memory fraction.
    • Introduced new command-line arguments to customize batch size, number of tokens, sequence length, and beam width.
  • Refactor

    • Improved initialization and configuration management for resource and scheduling settings, centralizing these options for easier setup and tuning.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 30, 2025

Walkthrough

The changes introduce enhanced configuration options for the TensorRT LLM backend, including dynamic GPU detection, new parallelism parameters, and resource-related settings. Command-line argument parsing and the configuration class are updated to support these options, and the engine initialization logic is refactored to incorporate the new configuration objects and parameters.

Changes

Cohort / File(s) Change Summary
Engine Initialization Refactor
components/backends/trtllm/src/dynamo/trtllm/main.py
Refactored the async init function to dynamically determine GPUs per node, raise errors if none found, and instantiate new configuration objects (BuildConfig, KvCacheConfig, DynamicBatchConfig, SchedulerConfig). Updated engine argument map to include new resource and parallelism parameters.
Configuration and CLI Argument Expansion
components/backends/trtllm/src/dynamo/trtllm/utils/trtllm_utils.py
Expanded the Config class and command-line argument parsing to include pipeline and expert parallel sizes, GPU count, batch and token limits, and free GPU memory fraction. Updated string representation and parsing logic accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

A rabbit hopped through code so bright,
Adding configs left and right.
GPUs counted, batches set,
Parallel dreams are now all met.
With options new and logic neat,
This backend’s tune is hard to beat!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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 anywhere in the PR title to generate the title automatically.

Documentation and Community

  • 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.

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)
components/backends/trtllm/src/dynamo/trtllm/utils/trtllm_utils.py (1)

127-140: Inconsistent help text capitalization.

The help text for --expert-parallel-size uses lowercase "expert" while other similar parameters use proper capitalization.

-        help="expert parallelism size.",
+        help="Expert parallelism size.",
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57482dc and 6b960e5.

📒 Files selected for processing (2)
  • components/backends/trtllm/src/dynamo/trtllm/main.py (2 hunks)
  • components/backends/trtllm/src/dynamo/trtllm/utils/trtllm_utils.py (6 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ptarasiewiczNV
PR: ai-dynamo/dynamo#2027
File: container/deps/vllm/install_vllm.sh:0-0
Timestamp: 2025-07-22T10:22:28.972Z
Learning: The `--torch-backend=auto` flag works with vLLM installations via uv pip install, even though it's not a standard pip option. This flag is processed by vLLM's build system during installation to automatically match PyTorch distribution with container CUDA versions.
Learnt from: tanmayv25
PR: ai-dynamo/dynamo#1391
File: examples/tensorrt_llm/common/base_engine.py:171-176
Timestamp: 2025-06-05T01:10:51.865Z
Learning: In examples/tensorrt_llm/common/base_engine.py, the _init_engine method is called only once during initialization, so direct mutation of the _default_sampling_params object during setup is safe and appropriate.
components/backends/trtllm/src/dynamo/trtllm/main.py (2)

Learnt from: tanmayv25
PR: #1391
File: examples/tensorrt_llm/common/base_engine.py:171-176
Timestamp: 2025-06-05T01:10:51.865Z
Learning: In examples/tensorrt_llm/common/base_engine.py, the _init_engine method is called only once during initialization, so direct mutation of the _default_sampling_params object during setup is safe and appropriate.

Learnt from: ptarasiewiczNV
PR: #2027
File: container/deps/vllm/install_vllm.sh:0-0
Timestamp: 2025-07-22T10:22:28.972Z
Learning: The --torch-backend=auto flag works with vLLM installations via uv pip install, even though it's not a standard pip option. This flag is processed by vLLM's build system during installation to automatically match PyTorch distribution with container CUDA versions.

⏰ 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). (4)
  • GitHub Check: pre-merge-rust (lib/runtime/examples)
  • GitHub Check: Build and Test - vllm
  • GitHub Check: pre-merge-rust (.)
  • GitHub Check: pre-merge-rust (lib/bindings/python)
🔇 Additional comments (7)
components/backends/trtllm/src/dynamo/trtllm/main.py (4)

11-17: LGTM! Well-organized imports for new configuration classes.

The imports are properly structured and include all necessary TensorRT LLM API configuration classes and the torch CUDA device counting function.

Also applies to: 20-20


95-101: Good defensive programming with GPU detection.

The dynamic GPU detection logic properly handles the case where gpus_per_node is not explicitly provided, with appropriate error handling when no GPUs are found.


102-122: Confirm DynamicBatchConfig values for OOM prevention

Please verify that these hardcoded values align with your memory-safety goals and workload characteristics in components/backends/trtllm/src/dynamo/trtllm/main.py (lines 102–122):

  • enable_batch_size_tuning=True
    • Adapts batch size at runtime—ensure it never exceeds available GPU memory under peak load.
  • enable_max_num_tokens_tuning=False
    • Keeps the maximum token count fixed; consider enabling if dynamic token trimming could reduce padding overhead.
  • dynamic_batch_moving_average_window=128
    • The default moving-average window is often 64; confirm that 128 strikes the right balance between responsiveness and stability for your models.
  • capacity_scheduler_policy=CapacitySchedulerPolicy.GUARANTEED_NO_EVICT
    • Guarantees no in-flight eviction (conservative memory usage) but may impact throughput; validate this trade-off against MAX_UTILIZATION if higher throughput is needed.

Monitor GPU memory (e.g., with nvidia-smi) under representative workloads and adjust these parameters as needed.


123-139: Double-check overlapping argument mappings for build_config/kv_cache_config vs. individual parameters

It looks like you’re passing both individual settings (max_num_tokens, max_seq_len, etc.) and entire config objects (build_config, kv_cache_config) into arg_map. Please verify that:

  • Neither build_config nor kv_cache_config already include the same fields (e.g., max sequence length, batch size, etc.).
  • There are no silent overrides or conflicts when arg_map is later merged with config.extra_engine_args via update_llm_args_with_extra_options.
  • The final engine invocation receives each parameter exactly once, with the intended precedence.

Key location:

  • File: components/backends/trtllm/src/dynamo/trtllm/main.py
  • Lines: 123–139 (where arg_map is defined)

If the config objects already encapsulate these values, consider removing the duplicates or consolidating into one source of truth to avoid confusion.

components/backends/trtllm/src/dynamo/trtllm/utils/trtllm_utils.py (3)

7-7: LGTM! Appropriate import for BuildConfig constants.

The import enables using BuildConfig default values for the new configuration parameters.


32-41: Well-structured configuration fields with sensible defaults.

The new configuration fields are properly typed and use appropriate defaults from BuildConfig constants, which should help prevent OOM issues by providing tested default values.


153-189: Comprehensive resource configuration options.

The new command-line arguments provide good coverage of resource-related parameters that should help prevent OOM issues. The defaults using BuildConfig constants are appropriate.

@nv-kmcgill53
Copy link
Contributor

In general, I want to ask why the file structure is the way it is. We have /dynamo/components/backends/trtllm/src/dynamo/trtllm/main.py. Why do we need to nest trtllm and dynamo twice?

@tanmayv25
Copy link
Contributor Author

tanmayv25 commented Jul 31, 2025

@nv-kmcgill53 See the discussion here. It is to support launch like python3 -m dynamo.trtllm.
We can improve this.

@tanmayv25 tanmayv25 merged commit 7e3b3fa into main Jul 31, 2025
12 of 13 checks passed
@tanmayv25 tanmayv25 deleted the tanmayv-buid-config branch July 31, 2025 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants