Skip to content

Conversation

@Shixiaowei02
Copy link
Collaborator

@Shixiaowei02 Shixiaowei02 commented Nov 29, 2025

Recently, dist-serving has experienced a performance degradation issue. We found that this problem is related to #8805. Upon investigation, PR 8805 changed the default CPU affinity configuration. This PR fixes the performance issue.

In addition, we also found that this modification improves the performance of non-dist-serving tests.

Test results run on H200

Without this modification:

691.91s call     accuracy/test_disaggregated_serving.py::TestLlama3_1_8BInstruct::test_eagle3[eagle3_one_model=False-overlap_scheduler=False]
923.63s call     accuracy/test_llm_api_pytorch.py::TestLlama3_1_8BInstruct::test_eagle3[eagle3_one_model=False-overlap_scheduler=False]

With this modification:

390.79s call     accuracy/test_disaggregated_serving.py::TestLlama3_1_8BInstruct::test_eagle3[eagle3_one_model=False-overlap_scheduler=False]
855.32s call     accuracy/test_llm_api_pytorch.py::TestLlama3_1_8BInstruct::test_eagle3[eagle3_one_model=False-overlap_scheduler=False]

@Shixiaowei02 Shixiaowei02 requested a review from a team as a code owner November 29, 2025 08:50
@Shixiaowei02 Shixiaowei02 force-pushed the user/xiaoweis/affinity branch from 232727e to a4b3ad4 Compare November 29, 2025 08:50
@NVIDIA NVIDIA deleted a comment from coderabbitai bot Nov 29, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 29, 2025

📝 Walkthrough

\n\n

\n📝 Walkthrough\n\n## Walkthrough\n\nThe changes add CPU affinity management utilities and integrate them into worker process initialization. Two new functions are introduced to set and clear CPU affinity; the worker process is updated to conditionally apply CPU affinity based on configuration state, with corresponding log messages.\n\n## Changes\n\n| Cohort / File(s) | Summary |\n|---|---|\n| CPU Affinity Utilities
tensorrt_llm/llmapi/utils.py | Added set_sched_setaffinity(required_cores: int) to set current process CPU affinity to least-used cores; added clear_sched_affinity(pid: int) stub that raises ValueError (not yet implemented) |\n| Worker Initialization
tensorrt_llm/executor/base_worker.py | Imported clear_sched_affinity; added conditional logic to clear CPU affinity for constrained cases or compute and set NUMA-aware affinity for unconstrained/auto-configured cases, with logging for each path |\n\n## Estimated code review effort\n\n🎯 2 (Simple) | ⏱️ ~12 minutes\n\n- Unimplemented function stub: clear_sched_affinity() raises ValueError; clarify whether this is intentional or a placeholder requiring completion\n- Conditional affinity logic: Verify the logic for detecting constrained vs. unconstrained affinity and that the correct function is called in each case\n- Process affinity application: Ensure process.cpu_affinity() call correctly applies the computed NUMA-aware affinity on target systems\n\n
\n\n

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ⚠️ Warning The PR description is incomplete and does not follow the required template structure with proper sections. Add a proper title following the template format, include a Description section explaining the issue and solution, provide Test Coverage details, and complete the PR Checklist with acknowledgment.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title directly reflects the main changes: adding CPU affinity management (clearing and setting) to improve distributed serving performance.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

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 ae0124e and a4b3ad4.

📒 Files selected for processing (2)
  • tensorrt_llm/executor/base_worker.py (2 hunks)
  • tensorrt_llm/llmapi/utils.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: The code developed for TensorRT-LLM should conform to Python 3.8+
Indent Python code with 4 spaces; do not use tabs
Always maintain the namespace when importing in Python, even if only one class or function from a module is used (e.g., use from package.subpackage import foo and then foo.SomeClass() instead of from package.subpackage.foo import SomeClass)
Python filenames should use snake_case (e.g., some_file.py)
Python class names should use PascalCase (e.g., class SomeClass)
Python function and method names should use snake_case (e.g., def my_awesome_function():)
Python local variable names should use snake_case, with prefix k for variable names that start with a number (e.g., k_99th_percentile = ...)
Python global variables should use upper snake_case with prefix G (e.g., G_MY_GLOBAL = ...)
Python constants should use upper snake_case (e.g., MY_CONSTANT = ...)
Avoid shadowing variables declared in an outer scope in Python
Initialize all externally visible members of a Python class in the constructor
For Python interfaces that may be used outside a file, prefer docstrings over comments
Python comments should be reserved for code within a function, or interfaces that are local to a file
Use Google style docstrings for Python classes and functions, which can be parsed by Sphinx
Python attributes and variables can be documented inline with type and description (e.g., self.x = 5 followed by """<type>: Description of 'x'""" )
Avoid using reflection in Python when functionality can be easily achieved without reflection
When using try-except blocks in Python, limit the except clause to the smallest set of specific errors possible instead of catching all exceptions
When using try-except blocks in Python to handle multiple possible variable types (duck-typing), keep the body of the try as small as possible and use the else block to implement the logic

Files:

  • tensorrt_llm/llmapi/utils.py
  • tensorrt_llm/executor/base_worker.py
**/*.{cpp,h,cu,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

All TensorRT-LLM Open Source Software code files should contain an NVIDIA copyright header that includes the current year at the top

Files:

  • tensorrt_llm/llmapi/utils.py
  • tensorrt_llm/executor/base_worker.py
🧬 Code graph analysis (1)
tensorrt_llm/executor/base_worker.py (2)
tensorrt_llm/llmapi/utils.py (5)
  • clear_sched_affinity (533-536)
  • get_numa_aware_cpu_affinity (539-589)
  • logger_debug (105-118)
  • get (415-445)
  • get (498-515)
tensorrt_llm/executor/utils.py (1)
  • get (122-123)
🪛 Ruff (0.14.6)
tensorrt_llm/llmapi/utils.py

535-535: Avoid specifying long messages outside the exception class

(TRY003)

⏰ 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 (4)
tensorrt_llm/executor/base_worker.py (2)

162-166: NUMA-aware affinity configuration looks good.

This code path correctly computes and applies NUMA-aware CPU affinity using get_numa_aware_cpu_affinity() and process.cpu_affinity(). The logging provides good visibility into the affinity settings being applied.

Note: This is the auto-configuration path that should work correctly once the constrained affinity path (lines 153-154) is fixed.


148-166: Verify the intended behavior when clearing constrained affinity.

When constrained affinity is detected and cleared (lines 153-154), the subsequent condition (line 160) prevents NUMA-aware affinity from being automatically applied. This means after clearing, the process will have unconstrained affinity (all CPUs) but won't get NUMA-optimized affinity unless TLLM_NUMA_AWARE_WORKER_AFFINITY=1 is explicitly set.

Is this the intended behavior, or should NUMA-aware affinity be automatically applied after clearing constrained affinity?

Current behavior:

  • Constrained affinity detected → clear to all CPUs → stop (unless env var = "1")

Alternative behavior:

  • Constrained affinity detected → clear to all CPUs → apply NUMA-aware affinity

If the alternative is desired, consider modifying the condition:

-        if ((numa_aware_affinity is None and not constrained_affinity)
+        if ((numa_aware_affinity is None)
                 or (numa_aware_affinity == "1")):
tensorrt_llm/llmapi/utils.py (2)

533-589: I'm unable to complete the verification due to persistent repository cloning failures. However, based on the information provided in the review comment itself:

The review comment states that the reviewer found these functions duplicated in tensorrt_llm/executor/utils.py (lines 532-588), and the same functions appear in tensorrt_llm/llmapi/utils.py (lines 533-589 under review).

Without direct access to the codebase to:

  1. Verify the functions are truly identical
  2. Confirm whether one imports from the other
  3. Check all usage locations
  4. Determine if this duplication is intentional for module separation

I cannot definitively confirm or refute the duplication claim.

Code duplication across tensorrt_llm/llmapi/utils.py and tensorrt_llm/executor/utils.py requires manual verification.

The clear_sched_affinity and get_numa_aware_cpu_affinity functions appear in both files. Verify whether these are intentionally separate implementations for module independence or represent duplicate code that should be consolidated. If consolidation is appropriate, consider moving to a shared utilities module or importing from one location.


518-530: I'm unable to execute shell scripts to verify the function usage due to repository access issues. However, I can assess the review comment based on the information provided:

The original review comment:

  1. Identifies that set_sched_setaffinity is defined but appears unused in the PR changes
  2. Notes that base_worker.py uses alternative approaches instead
  3. Requests verification via a grep script to confirm the function is not called anywhere

Since I cannot perform the verification script requested in the review comment due to infrastructure constraints, I must mark this as requiring manual verification. The comment itself already includes a request for verification, which is appropriate given that absence of evidence in a diff is not proof of absence in the full codebase.

The function set_sched_setaffinity may be unused or reserved for future use; verify with the provided grep script to confirm there are no calls to this function across the codebase.

The worker initialization in base_worker.py uses get_numa_aware_cpu_affinity and process.cpu_affinity() directly instead of calling set_sched_setaffinity. Consider whether this function serves a purpose or should be removed.

@Shixiaowei02 Shixiaowei02 force-pushed the user/xiaoweis/affinity branch 2 times, most recently from 2a82a38 to 84d7505 Compare November 29, 2025 09:40
@Shixiaowei02
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26255 [ run ] completed with state ABORTED. Commit: a4b3ad4
LLM/main/L0_MergeRequest_PR #19950 (Blue Ocean) completed with status: ABORTED

@NVIDIA NVIDIA deleted a comment from tensorrt-cicd Nov 29, 2025
@NVIDIA NVIDIA deleted a comment from tensorrt-cicd Nov 29, 2025
@Shixiaowei02 Shixiaowei02 changed the title [None][fix] Fix dist-serving perf by clear CPU affinity [None][fix] Fix dist-serving perf by clearing CPU affinity Nov 29, 2025
@Shixiaowei02 Shixiaowei02 changed the title [None][fix] Fix dist-serving perf by clearing CPU affinity [https://nvbugs/5651854][fix] Fix dist-serving perf by clearing CPU affinity Nov 29, 2025
@tensorrt-cicd
Copy link
Collaborator

PR_Github #26259 [ run ] completed with state SUCCESS. Commit: 84d7505
/LLM/main/L0_MergeRequest_PR pipeline #19953 completed with status: 'FAILURE'

@Shixiaowei02 Shixiaowei02 force-pushed the user/xiaoweis/affinity branch from 84d7505 to 057673a Compare November 29, 2025 14:59
@Shixiaowei02
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26266 [ run ] triggered by Bot. Commit: 057673a

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26266 [ run ] completed with state SUCCESS. Commit: 057673a
/LLM/main/L0_MergeRequest_PR pipeline #19960 completed with status: 'FAILURE'

@Shixiaowei02
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26270 [ run ] triggered by Bot. Commit: 057673a

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26270 [ run ] completed with state SUCCESS. Commit: 057673a
/LLM/main/L0_MergeRequest_PR pipeline #19964 completed with status: 'FAILURE'

@Shixiaowei02
Copy link
Collaborator Author

/bot run --stage-list "DGX_H100-2_GPUs-PyTorch-Others-1, DGX_H100-4_GPUs-PyTorch-Others-1"

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26278 [ run ] triggered by Bot. Commit: 057673a

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26278 [ run ] completed with state SUCCESS. Commit: 057673a
/LLM/main/L0_MergeRequest_PR pipeline #19972 (Partly Tested) completed with status: 'SUCCESS'

@Shixiaowei02
Copy link
Collaborator Author

/bot skip --comment "Pass through together in 26278 and 26270"

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26332 [ skip ] triggered by Bot. Commit: 057673a

@Shixiaowei02
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26448 [ run ] triggered by Bot. Commit: 97b357b

@dhansen-nvidia
Copy link
Collaborator

dhansen-nvidia commented Dec 1, 2025

EDIT: I misread the latest code in the PR, I see that it now does not clear affinity if it is set to 0. I think this generally strikes a good balance for now. However, I think we probably should at some point consider switching over to NUMA-aware affinity by default instead of clearing it when it is set.

~~
I've posted this comment to the bug, but I also wanted to post it here to make sure it is broadly visible:

This change will unconditionally "clear" affinity if it is set by the user/environment, which makes it impossible for the user to "override" the affinity with numactl.

Given that it is impossible to distinguish between the affinity as set by the "environment" (which seems to be causing the issue observed in this bug) and the affinity as set by the user, I think maybe we just need to accept that we need to modify affinity by default and then provide some explicit mechanism (i.e. environment variable) for the user to opt out. Furthermore, given that numa-aware affinity shows improved performance, why would we not default to that instead of blindly clearing affinity? It showed demonstrably better performance than just clearing affinity on DS R1 on GB200 in my testing.

In essence, my suggestion here is to just change the TLLM_NUMA_AWARE_WORKER_AFFINITY to operate as follows: If TLLM_NUMA_AWARE_WORKER_AFFINITY = 0, then we just don't touch affinity at all. Otherwise, we apply numa-aware affinity.
~~

@pcastonguay
Copy link
Collaborator

pcastonguay commented Dec 1, 2025

I've posted this comment to the bug, but I also wanted to post it here to make sure it is broadly visible:

This change will unconditionally "clear" affinity if it is set by the user/environment, which makes it impossible for the user to "override" the affinity with numactl.

Given that it is impossible to distinguish between the affinity as set by the "environment" (which seems to be causing the issue observed in this bug) and the affinity as set by the user, I think maybe we just need to accept that we need to modify affinity by default and then provide some explicit mechanism (i.e. environment variable) for the user to opt out. Furthermore, given that numa-aware affinity shows improved performance, why would we not default to that instead of blindly clearing affinity? It showed demonstrably better performance than just clearing affinity on DS R1 on GB200 in my testing.

In essence, my suggestion here is to just change the TLLM_NUMA_AWARE_WORKER_AFFINITY to operate as follows: If TLLM_NUMA_AWARE_WORKER_AFFINITY = 0, then we just don't touch affinity at all. Otherwise, we apply numa-aware affinity.

As we discussed on Slack, we can maintain PR as is to mitigate risk (in case NUMA aware affinity leads to worse perf). If user wants to maintain constrained affinity, they can set TLLM_NUMA_AWARE_WORKER_AFFINITY = 0.

Copy link
Collaborator

@dhansen-nvidia dhansen-nvidia left a comment

Choose a reason for hiding this comment

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

LGTM

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26448 [ run ] completed with state SUCCESS. Commit: 97b357b
/LLM/main/L0_MergeRequest_PR pipeline #20101 completed with status: 'FAILURE'

@Shixiaowei02 Shixiaowei02 force-pushed the user/xiaoweis/affinity branch from 97b357b to 1b3085e Compare December 2, 2025 02:07
@Shixiaowei02
Copy link
Collaborator Author

/bot help

@github-actions
Copy link

github-actions bot commented Dec 2, 2025

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.

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 the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip 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-pipeline

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

@Shixiaowei02
Copy link
Collaborator Author

/bot run --only-multi-gpu-test

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26499 [ run ] triggered by Bot. Commit: 1b3085e

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26499 [ run ] completed with state SUCCESS. Commit: 1b3085e
/LLM/main/L0_MergeRequest_PR pipeline #20148 (Partly Tested) completed with status: 'FAILURE'

@Shixiaowei02
Copy link
Collaborator Author

/bot run --stage-list "DGX_B200-4_GPUs-PyTorch-1, DGX_B200-4_GPUs-PyTorch-2, DGX_B200-4_GPUs-PyTorch-Ray-1, DGX_B200-8_GPUs-PyTorch-1, DGX_H100-2_GPUs-PyTorch-Others-1"

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26529 [ run ] triggered by Bot. Commit: 1b3085e

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26529 [ run ] completed with state SUCCESS. Commit: 1b3085e
/LLM/main/L0_MergeRequest_PR pipeline #20172 (Partly Tested) completed with status: 'FAILURE'

@longlee0622
Copy link
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26588 [ run ] triggered by Bot. Commit: 1b3085e

@longlee0622 longlee0622 force-pushed the user/xiaoweis/affinity branch from 1b3085e to 4e6bc12 Compare December 2, 2025 10:30
@longlee0622
Copy link
Collaborator

/bot run --disable-fail-fast

@longlee0622 longlee0622 enabled auto-merge (squash) December 2, 2025 10:32
@tensorrt-cicd
Copy link
Collaborator

PR_Github #26597 [ run ] triggered by Bot. Commit: 4e6bc12

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26588 [ run ] completed with state ABORTED. Commit: 1b3085e
LLM/main/L0_MergeRequest_PR #20216 (Blue Ocean) completed with status: ABORTED

@tensorrt-cicd
Copy link
Collaborator

PR_Github #26597 [ run ] completed with state SUCCESS. Commit: 4e6bc12
/LLM/main/L0_MergeRequest_PR pipeline #20224 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

@longlee0622 longlee0622 merged commit 227d42e into NVIDIA:main Dec 2, 2025
5 checks passed
@Shixiaowei02 Shixiaowei02 deleted the user/xiaoweis/affinity branch December 3, 2025 01:14
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.

7 participants