-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[https://nvbugs/5651854][fix] Fix dist-serving perf by clearing CPU affinity #9549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
232727e to
a4b3ad4
Compare
📝 Walkthrough\n\n \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 Utilitiestensorrt_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\nPre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ 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.
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
📒 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., usefrom package.subpackage import fooand thenfoo.SomeClass()instead offrom 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 prefixkfor variable names that start with a number (e.g.,k_99th_percentile = ...)
Python global variables should use upper snake_case with prefixG(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 = 5followed 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.pytensorrt_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.pytensorrt_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()andprocess.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=1is 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 intensorrt_llm/llmapi/utils.py(lines 533-589 under review).Without direct access to the codebase to:
- Verify the functions are truly identical
- Confirm whether one imports from the other
- Check all usage locations
- 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.pyandtensorrt_llm/executor/utils.pyrequires manual verification.The
clear_sched_affinityandget_numa_aware_cpu_affinityfunctions 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:
- Identifies that
set_sched_setaffinityis defined but appears unused in the PR changes- Notes that
base_worker.pyuses alternative approaches instead- 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_setaffinitymay 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.pyusesget_numa_aware_cpu_affinityandprocess.cpu_affinity()directly instead of callingset_sched_setaffinity. Consider whether this function serves a purpose or should be removed.
2a82a38 to
84d7505
Compare
|
/bot run |
|
PR_Github #26255 [ run ] completed with state |
|
PR_Github #26259 [ run ] completed with state |
84d7505 to
057673a
Compare
|
/bot run |
|
PR_Github #26266 [ run ] triggered by Bot. Commit: |
|
PR_Github #26266 [ run ] completed with state |
|
/bot run |
|
PR_Github #26270 [ run ] triggered by Bot. Commit: |
|
PR_Github #26270 [ run ] completed with state |
|
/bot run --stage-list "DGX_H100-2_GPUs-PyTorch-Others-1, DGX_H100-4_GPUs-PyTorch-Others-1" |
|
PR_Github #26278 [ run ] triggered by Bot. Commit: |
|
PR_Github #26278 [ run ] completed with state |
|
/bot skip --comment "Pass through together in 26278 and 26270" |
|
PR_Github #26332 [ skip ] triggered by Bot. Commit: |
|
/bot run |
|
PR_Github #26448 [ run ] triggered by Bot. Commit: |
|
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. ~~ 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 |
dhansen-nvidia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
PR_Github #26448 [ run ] completed with state |
97b357b to
1b3085e
Compare
|
/bot help |
GitHub Bot Help
Provide a user friendly way for developers to interact with a Jenkins server. Run See details below for each supported subcommand.
Launch build/test pipelines. All previously running jobs will be killed.
kill
Kill all running builds associated with pull request. skip
Skip testing for latest commit on pull request. 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. |
|
/bot run --only-multi-gpu-test |
|
PR_Github #26499 [ run ] triggered by Bot. Commit: |
|
PR_Github #26499 [ run ] completed with state |
|
/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" |
|
PR_Github #26529 [ run ] triggered by Bot. Commit: |
|
PR_Github #26529 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #26588 [ run ] triggered by Bot. Commit: |
Signed-off-by: Shixiaowei02 <[email protected]>
Signed-off-by: Shixiaowei02 <[email protected]>
1b3085e to
4e6bc12
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #26597 [ run ] triggered by Bot. Commit: |
|
PR_Github #26588 [ run ] completed with state |
|
PR_Github #26597 [ run ] completed with state |
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:
With this modification: