Skip to content

Conversation

tanmayv25
Copy link
Contributor

@tanmayv25 tanmayv25 commented Oct 7, 2025

Overview:

This fixes the logging within TRTLLM engine. The code will set TLLM_LOG_LEVEL=INFO by default which would allow the print_iter_log to appear.

Without this TRTLLM logs will not appear during inference.

Before


data: {"id":"chatcmpl-d043cc61-c996-4baf-b2cb-7b9b323f59b9","choices":[{"index":0,"delta":{"content":" me","function_call":null,"tool_calls":null,"role":"assistant","refusal":null,"reasoning_content":null}}],"created":1759789572,"model":"Qwen/Qwen3-0.6B","service_tier":null,"system_fingerprint":null,"object":"chat.completion.chunk","usage":null}

data: {"id":"chatcmpl-d043cc61-c996-4baf-b2cb-7b9b323f59b9","choices":[{"index":0,"delta":{"content":" start","function_call":null,"tool_calls":null,"role":"assistant","refusal":null,"reasoning_content":null}}],"created":1759789572,"model":"Qwen/Qwen3-0.6B","service_tier":null,"system_fingerprint":null,"object":"chat.completion.chunk","usage":null}

data: {"id":"chatcmpl-d043cc61-c996-4baf-b2cb-7b9b323f59b9","choices":[{"index":0,"delta":{"content":" by","function_call":null,"tool_calls":null,"role":"assistant","refusal":null,"reasoning_content":null}}],"created":1759789572,"model":"Qwen/Qwen3-0.6B","service_tier":null,"system_fingerprint":null,"object":"chat.completion.chunk","usage":null}

data: {"id":"chatcmpl-d043cc61-c996-4baf-b2cb-7b9b323f59b9","choices":[{"index":0,"delta":{"content":" recalling","function_call":null,"tool_calls":null,"role":"assistant","refusal":null,"reasoning_content":null},"finish_reason":"length"}],"created":1759789572,"model":"Qwen/Qwen3-0.6B","service_tier":null,"system_fingerprint":null,"object":"chat.completion.chunk","usage":null}

data: [DONE]

After

[10/07/2025-00:29:01] [TRT-LLM] [I] iter = 94, global_rank = 0, rank = 0, currank_total_requests = 0/0, host_step_time = 2.382040023803711ms, prev_device_step_time = 2.4019839763641357ms, timestamp = 2025-10-07 00:29:01, num_scheduled_requests: 1, states = {'num_ctx_requests': 0, 'num_ctx_tokens': 0, 'num_generation_tokens': 1}
data: {"id":"chatcmpl-51e76f86-db3a-4092-bf60-94372ccaf7b4","choices":[{"index":0,"delta":{"content":".","function_call":null,"tool_calls":null,"role":"assistant","refusal":null,"reasoning_content":null}}],"created":1759796941,"model":"Qwen/Qwen3-0.6B","service_tier":null,"system_fingerprint":null,"object":"chat.completion.chunk","usage":null}

[10/07/2025-00:29:01] [TRT-LLM] [I] iter = 95, global_rank = 0, rank = 0, currank_total_requests = 0/0, host_step_time = 2.3653507232666016ms, prev_device_step_time = 2.436768054962158ms, timestamp = 2025-10-07 00:29:01, num_scheduled_requests: 1, states = {'num_ctx_requests': 0, 'num_ctx_tokens': 0, 'num_generation_tokens': 1}
data: {"id":"chatcmpl-51e76f86-db3a-4092-bf60-94372ccaf7b4","choices":[{"index":0,"delta":{"content":" Let","function_call":null,"tool_calls":null,"role":"assistant","refusal":null,"reasoning_content":null}}],"created":1759796941,"model":"Qwen/Qwen3-0.6B","service_tier":null,"system_fingerprint":null,"object":"chat.completion.chunk","usage":null}

[10/07/2025-00:29:01] [TRT-LLM] [I] iter = 96, global_rank = 0, rank = 0, currank_total_requests = 0/0, host_step_time = 2.4323463439941406ms, prev_device_step_time = 2.398848056793213ms, timestamp = 2025-10-07 00:29:01, num_scheduled_requests: 1, states = {'num_ctx_requests': 0, 'num_ctx_tokens': 0, 'num_generation_tokens': 1}
data: {"id":"chatcmpl-51e76f86-db3a-4092-bf60-94372ccaf7b4","choices":[{"index":0,"delta":{"content":" me","function_call":null,"tool_calls":null,"role":"assistant","refusal":null,"reasoning_content":null}}],"created":1759796941,"model":"Qwen/Qwen3-0.6B","service_tier":null,"system_fingerprint":null,"object":"chat.completion.chunk","usage":null}

[10/07/2025-00:29:01] [TRT-LLM] [I] iter = 97, global_rank = 0, rank = 0, currank_total_requests = 0/0, host_step_time = 2.274036407470703ms, prev_device_step_time = 2.4051520824432373ms, timestamp = 2025-10-07 00:29:01, num_scheduled_requests: 1, states = {'num_ctx_requests': 0, 'num_ctx_tokens': 0, 'num_generation_tokens': 1}
data: {"id":"chatcmpl-51e76f86-db3a-4092-bf60-94372ccaf7b4","choices":[{"index":0,"delta":{"content":" start","function_call":null,"tool_calls":null,"role":"assistant","refusal":null,"reasoning_content":null}}],"created":1759796941,"model":"Qwen/Qwen3-0.6B","service_tier":null,"system_fingerprint":null,"object":"chat.completion.chunk","usage":null}

[10/07/2025-00:29:01] [TRT-LLM] [I] iter = 98, global_rank = 0, rank = 0, currank_total_requests = 0/0, host_step_time = 2.378702163696289ms, prev_device_step_time = 2.430624008178711ms, timestamp = 2025-10-07 00:29:01, num_scheduled_requests: 1, states = {'num_ctx_requests': 0, 'num_ctx_tokens': 0, 'num_generation_tokens': 1}
data: {"id":"chatcmpl-51e76f86-db3a-4092-bf60-94372ccaf7b4","choices":[{"index":0,"delta":{"content":" by","function_call":null,"tool_calls":null,"role":"assistant","refusal":null,"reasoning_content":null}}],"created":1759796941,"model":"Qwen/Qwen3-0.6B","service_tier":null,"system_fingerprint":null,"object":"chat.completion.chunk","usage":null}

[10/07/2025-00:29:01] [TRT-LLM] [I] iter = 99, global_rank = 0, rank = 0, currank_total_requests = 0/0, host_step_time = 2.4247169494628906ms, prev_device_step_time = 2.4163520336151123ms, timestamp = 2025-10-07 00:29:01, num_scheduled_requests: 1, states = {'num_ctx_requests': 0, 'num_ctx_tokens': 0, 'num_generation_tokens': 1}
data: {"id":"chatcmpl-51e76f86-db3a-4092-bf60-94372ccaf7b4","choices":[{"index":0,"delta":{"content":" recalling","function_call":null,"tool_calls":null,"role":"assistant","refusal":null,"reasoning_content":null},"finish_reason":"length"}],"created":1759796941,"model":"Qwen/Qwen3-0.6B","service_tier":null,"system_fingerprint":null,"object":"chat.completion.chunk","usage":null}

data: [DONE]

Summary by CodeRabbit

  • New Features
    • Automatically aligns TensorRT-LLM logging level with your existing DYN_LOG setting at startup for consistent logs.
    • Respects any pre-set TLLM_LOG_LEVEL and falls back to sensible defaults when unspecified.
    • Supports comma-delimited DYN_LOG values and maps them to appropriate TensorRT-LLM levels.
    • Integrates with the runtime logging setup by default; can be disabled via an environment flag.

@tanmayv25 tanmayv25 requested review from a team as code owners October 7, 2025 00:36
@github-actions github-actions bot added the feat label Oct 7, 2025
Copy link
Contributor

coderabbitai bot commented Oct 7, 2025

Walkthrough

Introduces pre-import configuration to set TLLM_LOG_LEVEL from DYN_LOG before importing TensorRT-LLM. Adds mapping and configuration functions to the logging module, integrates TensorRT-LLM logging setup into existing configure_dynamo_logging, and respects overrides via existing environment variables or a skip flag.

Changes

Cohort / File(s) Summary
TRT-LLM pre-import env setup
components/src/dynamo/trtllm/main.py
Adds early environment configuration to set TLLM_LOG_LEVEL from DYN_LOG (via safe mapping) before any tensorrt_llm imports, ensuring logging level is established prior to initialization.
Logging mapping and integration
lib/bindings/python/src/dynamo/runtime/logging.py
Adds map_dyn_log_to_tllm_level(...) to translate DYN_LOG to TensorRT-LLM levels; adds configure_trtllm_logging(...); updates configure_dynamo_logging to invoke TRT-LLM logging unless DYN_SKIP_TRTLLM_LOG_FORMATTING is set; respects preexisting TLLM_LOG_LEVEL.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Env as Process Env
  participant Main as dynamo/trtllm/main.py
  participant L as logging.py
  participant TRT as tensorrt_llm

  Note over Main: Module import start
  Main->>Env: Check TLLM_LOG_LEVEL
  alt Not set
    Main->>L: map_dyn_log_to_tllm_level(DYN_LOG)
    L-->>Main: TLLM level string
    Main->>Env: Set TLLM_LOG_LEVEL
  else Already set
    Note over Main: Preserve existing value
  end
  Main->>TRT: import tensorrt_llm...
  Note over TRT: Initializes with established log level
Loading
sequenceDiagram
  autonumber
  participant App as Application
  participant Log as configure_dynamo_logging
  participant L as logging.py
  participant Env as Process Env

  App->>Log: configure_dynamo_logging(...)
  alt DYN_SKIP_TRTLLM_LOG_FORMATTING not set
    Log->>L: configure_trtllm_logging(dyn_level)
    L->>Env: If TLLM_LOG_LEVEL unset, set from map_dyn_log_to_tllm_level(DYN_LOG)
  else Skip flag set
    Note over Log,Env: Do not modify TLLM_LOG_LEVEL
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A hare taps logs before the dawn,
Sets TLLM’s voice, then hops along.
From DYN’s whisper, levels bloom—
INFO, WARN, or VERBOSE plume.
Pre-import seeds the forest bright,
So Tensor trees log true and light. 🐇✨

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description only includes the Overview section and provides before-and-after examples, but it omits the required Details, Where should the reviewer start?, and Related Issues sections defined in the repository template, so it does not conform to the template. Please update the description to include a “#### Details:” section summarizing the changes made, a “#### Where should the reviewer start?” section pointing to the key files, and a “#### Related Issues:” section linking any relevant GitHub issues.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary change by indicating that the DYN_LOG level is now being connected to the TLLM_LOG_LEVEL environment variable, matching the core functionality introduced in the diff. It uses clear and specific terminology without extraneous details or noise.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

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

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

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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d809906 and 35a5303.

📒 Files selected for processing (2)
  • components/src/dynamo/trtllm/main.py (1 hunks)
  • lib/bindings/python/src/dynamo/runtime/logging.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
components/src/dynamo/trtllm/main.py (1)
lib/bindings/python/src/dynamo/runtime/logging.py (1)
  • map_dyn_log_to_tllm_level (198-222)
🪛 Ruff (0.13.3)
lib/bindings/python/src/dynamo/runtime/logging.py

225-225: Unused function argument: dyn_level

(ARG001)

⏰ 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). (2)
  • GitHub Check: trtllm (amd64)
  • GitHub Check: Build and Test - dynamo

Comment on lines +11 to +20
# Configure TLLM_LOG_LEVEL before importing tensorrt_llm
# This must happen before any tensorrt_llm imports
if "TLLM_LOG_LEVEL" not in os.environ:
# This import is safe because it doesn't trigger tensorrt_llm imports
from dynamo.runtime.logging import map_dyn_log_to_tllm_level

dyn_log = os.environ.get("DYN_LOG", "info")
tllm_level = map_dyn_log_to_tllm_level(dyn_log)
os.environ["TLLM_LOG_LEVEL"] = tllm_level

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Respect DYN_SKIP_TRTLLM_LOG_FORMATTING before touching TLLM_LOG_LEVEL.

This pre-import block sets TLLM_LOG_LEVEL even when callers explicitly opt out via DYN_SKIP_TRTLLM_LOG_FORMATTING, making the skip flag ineffective. Gate the block on the same flag so users can truly bypass Dynamo’s TRT-LLM logging setup.

-# Configure TLLM_LOG_LEVEL before importing tensorrt_llm
-# This must happen before any tensorrt_llm imports
-if "TLLM_LOG_LEVEL" not in os.environ:
+# Configure TLLM_LOG_LEVEL before importing tensorrt_llm
+# This must happen before any tensorrt_llm imports
+if (
+    "TLLM_LOG_LEVEL" not in os.environ
+    and os.getenv("DYN_SKIP_TRTLLM_LOG_FORMATTING") not in ("1", "true", "TRUE")
+):
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Configure TLLM_LOG_LEVEL before importing tensorrt_llm
# This must happen before any tensorrt_llm imports
if "TLLM_LOG_LEVEL" not in os.environ:
# This import is safe because it doesn't trigger tensorrt_llm imports
from dynamo.runtime.logging import map_dyn_log_to_tllm_level
dyn_log = os.environ.get("DYN_LOG", "info")
tllm_level = map_dyn_log_to_tllm_level(dyn_log)
os.environ["TLLM_LOG_LEVEL"] = tllm_level
# Configure TLLM_LOG_LEVEL before importing tensorrt_llm
# This must happen before any tensorrt_llm imports
if (
"TLLM_LOG_LEVEL" not in os.environ
and os.getenv("DYN_SKIP_TRTLLM_LOG_FORMATTING") not in ("1", "true", "TRUE")
):
# This import is safe because it doesn't trigger tensorrt_llm imports
from dynamo.runtime.logging import map_dyn_log_to_tllm_level
dyn_log = os.environ.get("DYN_LOG", "info")
tllm_level = map_dyn_log_to_tllm_level(dyn_log)
os.environ["TLLM_LOG_LEVEL"] = tllm_level
🤖 Prompt for AI Agents
In components/src/dynamo/trtllm/main.py around lines 11 to 20, the pre-import
block sets TLLM_LOG_LEVEL even when callers set DYN_SKIP_TRTLLM_LOG_FORMATTING;
update the guard so the block runs only when DYN_SKIP_TRTLLM_LOG_FORMATTING is
not set and TLLM_LOG_LEVEL is also unset: check os.environ for
DYN_SKIP_TRTLLM_LOG_FORMATTING first and return/skip if present, otherwise
proceed to import map_dyn_log_to_tllm_level, compute tllm_level from DYN_LOG and
set os.environ["TLLM_LOG_LEVEL"] as before.

Comment on lines +235 to +241
# Only set TLLM_LOG_LEVEL if it's not already set
# This allows users to override it explicitly if needed
if "TLLM_LOG_LEVEL" not in os.environ:
dyn_log = os.environ.get("DYN_LOG", "info")
tllm_level = map_dyn_log_to_tllm_level(dyn_log)
os.environ["TLLM_LOG_LEVEL"] = tllm_level
logging.debug(f"Set TLLM_LOG_LEVEL to {tllm_level} based on DYN_LOG")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Use the dyn_level argument (fixes Ruff ARG001).

configure_trtllm_logging ignores its dyn_level parameter and re-reads DYN_LOG, which triggers Ruff ARG001 (unused argument) and will fail CI. Derive the TensorRT-LLM level from the provided dyn_level instead of reading the env again.

 def configure_trtllm_logging(dyn_level: int):
@@
-    if "TLLM_LOG_LEVEL" not in os.environ:
-        dyn_log = os.environ.get("DYN_LOG", "info")
-        tllm_level = map_dyn_log_to_tllm_level(dyn_log)
+    if "TLLM_LOG_LEVEL" not in os.environ:
+        dyn_level_name = logging.getLevelName(dyn_level)
+        tllm_level = map_dyn_log_to_tllm_level(dyn_level_name)
         os.environ["TLLM_LOG_LEVEL"] = tllm_level
         logging.debug(f"Set TLLM_LOG_LEVEL to {tllm_level} based on DYN_LOG")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Only set TLLM_LOG_LEVEL if it's not already set
# This allows users to override it explicitly if needed
if "TLLM_LOG_LEVEL" not in os.environ:
dyn_log = os.environ.get("DYN_LOG", "info")
tllm_level = map_dyn_log_to_tllm_level(dyn_log)
os.environ["TLLM_LOG_LEVEL"] = tllm_level
logging.debug(f"Set TLLM_LOG_LEVEL to {tllm_level} based on DYN_LOG")
def configure_trtllm_logging(dyn_level: int):
# Only set TLLM_LOG_LEVEL if it's not already set
# This allows users to override it explicitly if needed
if "TLLM_LOG_LEVEL" not in os.environ:
dyn_level_name = logging.getLevelName(dyn_level)
tllm_level = map_dyn_log_to_tllm_level(dyn_level_name)
os.environ["TLLM_LOG_LEVEL"] = tllm_level
logging.debug(f"Set TLLM_LOG_LEVEL to {tllm_level} based on DYN_LOG")

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.

1 participant