[TRTLLM-10851][feat] Add line_profiler tool for host overhead analysis.#11232
[TRTLLM-10851][feat] Add line_profiler tool for host overhead analysis.#11232hyukn merged 3 commits intoNVIDIA:mainfrom
Conversation
📝 WalkthroughWalkthroughThis PR introduces host-side line-by-line profiling capabilities to measure CPU overhead in PyExecutor. It adds a comprehensive HostProfiler utility with configurable profiling targets, introspection-driven expansion logic, and lifecycle management. The PyExecutor integrates this profiler into its event loop wrapper to enable profiling during execution when enabled. Changes
Sequence DiagramsequenceDiagram
participant PyExecutor as PyExecutor Event Loop
participant ProfilingContext as host_profiler_context
participant HostProfiler
participant LineProfiler as line_profiler
participant TargetFunctions as Target Functions
PyExecutor->>ProfilingContext: enter context (enable=enable_profiler)
ProfilingContext->>HostProfiler: get_global_profiler()
HostProfiler->>LineProfiler: start() profiling
PyExecutor->>TargetFunctions: execute profiled code
TargetFunctions->>LineProfiler: measure line-by-line overhead
PyExecutor->>LineProfiler: collect execution data
ProfilingContext->>HostProfiler: stop() profiling
HostProfiler->>HostProfiler: save results to output_path
ProfilingContext-->>PyExecutor: exit context
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@tensorrt_llm/tools/profiler/host_profile_tools/host_profiler.py`:
- Line 1: Update the SPDX copyright header in host_profiler.py to reflect the
correct year 2026 instead of 2025; locate the top-of-file header comment
containing "Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES" and change the
year to 2026 so the SPDX header matches the latest modification year.
🧹 Nitpick comments (4)
tensorrt_llm/tools/profiler/host_profile_tools/host_profiler.py (4)
545-548:is_availableproperty is misleading.This property always returns
True, but line_profiler may not be installed. The actual availability check happens instart()when importing. Consider checking if line_profiler can be imported.♻️ Proposed fix
`@property` def is_available(self) -> bool: """Check if line_profiler is available.""" - return True + try: + import line_profiler # noqa: F401 + return True + except ImportError: + return False
628-630: Specify encoding when opening file.When opening files for writing text, explicitly specify the encoding to ensure consistent behavior across platforms.
♻️ Proposed fix
- with open(self.output_path, "w") as f: + with open(self.output_path, "w", encoding="utf-8") as f: self._line_profiler.print_stats(stream=f)
610-613: Consider narrowing exception handling.Static analysis flags catching blind
Exception. While broad exception handling provides robustness here, consider logging the exception type or narrowing to expected exceptions (e.g.,ImportError,AttributeError).
681-682: Global variable naming convention.Per coding guidelines, Python global variables should use upper snake_case with prefix
G. Consider renaming_global_profilertoG_GLOBAL_PROFILERor add a comment explaining the intentional deviation (e.g., if this is meant to be module-private).♻️ Proposed fix
# Global profiler instance for use in worker thread -_global_profiler: Optional[HostProfiler] = None +G_GLOBAL_PROFILER: Optional[HostProfiler] = None def get_global_profiler() -> Optional[HostProfiler]: """Get the global profiler instance.""" - return _global_profiler + return G_GLOBAL_PROFILERAnd update
set_global_profileranddump_profiler_functionsaccordingly.
a8029a8 to
cf5833a
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #35070 [ run ] triggered by Bot. Commit: |
|
PR_Github #35070 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #35094 [ run ] triggered by Bot. Commit: |
|
PR_Github #35094 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #35273 [ run ] triggered by Bot. Commit: |
|
PR_Github #35273 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #35341 [ run ] triggered by Bot. Commit: |
|
PR_Github #35341 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #35385 [ run ] triggered by Bot. Commit: |
|
/bot run --disable-fail-fast |
|
PR_Github #35432 [ run ] triggered by Bot. Commit: |
|
PR_Github #35432 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #35511 [ run ] triggered by Bot. Commit: |
|
PR_Github #35511 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #35615 [ run ] triggered by Bot. Commit: |
|
/bot run --disable-fail-fast |
|
PR_Github #35620 [ run ] triggered by Bot. Commit: |
|
PR_Github #35620 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #35640 [ run ] triggered by Bot. Commit: |
|
PR_Github #35640 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #35655 [ run ] triggered by Bot. Commit: |
|
PR_Github #35655 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #35675 [ run ] triggered by Bot. Commit: |
|
PR_Github #35675 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #35704 [ run ] triggered by Bot. Commit: |
|
/bot run --disable-fail-fast |
|
PR_Github #35704 [ run ] completed with state
|
|
PR_Github #35724 [ run ] triggered by Bot. Commit: |
|
PR_Github #35724 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #35785 [ run ] triggered by Bot. Commit: |
|
PR_Github #35785 [ run ] completed with state |
…s. (NVIDIA#11232) Signed-off-by: Yukun He <23156053+hyukn@users.noreply.github.com> Signed-off-by: peihu-nv <259410613+peihu-nv@users.noreply.github.com>
Summary by CodeRabbit
Description
This is an integrated host time analysis tool based on
line_profilerPython tool, used to investigate the host bottleneck for modules invoked in py_executor loop.Test Coverage
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)
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
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]to print this help message.See details below for each supported subcommand.
Details
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-listparameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip testing for latest commit on pull request.
--comment "Reason for skipping build/test"is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipelineReuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.