Repository navigation
[None][perf] Run the executor loop under a CPython frame-stack reserve - #22396
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. WalkthroughA utility wrapper conditionally reserves frame-stack capacity based on the CPython version and an environment variable. ChangesFrame-stack reserve
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Refactor Merge Risk:
|
c9576df to
e3bdad2
Compare
|
/bot run |
|
PR_Github #85556 [ run ] triggered by Bot. Commit: |
|
PR_Github #85556 [ run ] completed with state
|
chienchunhung
left a comment
There was a problem hiding this comment.
Thanks for the PR!
e3bdad2 to
75314c3
Compare
|
/bot run |
|
PR_Github #85780 [ run ] triggered by Bot. Commit: |
|
PR_Github #85780 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #85838 [ run ] triggered by Bot. Commit: |
|
PR_Github #85838 [ run ] completed with state
|
75314c3 to
7a843f6
Compare
|
/bot run |
|
PR_Github #86112 [ run ] triggered by Bot. Commit: |
|
PR_Github #86112 [ run ] completed with state
|
|
Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements. |
CPython 3.11+ keeps frames in per-thread data-stack chunks. When a hot call sits at a chunk boundary, every call maps a fresh chunk and every return unmaps it (gh-142183). On GB200 each munmap also pays a Grace SMMU invalidation once NCCL has peer-mapped memory, so the churn costs milliseconds per executor step: MiniMax-M3 piecewise CUDA graph prefill steps spent about half their host time in munmap, all on the executor thread. CPython fixed this in 3.13.13 and 3.14.4; 3.12 will not get the fix. Add run_with_frame_stack_reserve() and call PyExecutor.event_loop through it, so the loop starts near the beginning of a large data-stack chunk and ordinary call depths never reach a boundary. The reserve is applied only on affected CPython versions and can be disabled with TLLM_DISABLE_FRAME_STACK_RESERVE=1. Cover the version gate, the disable switch, the churn itself and the executor wiring with cpu_only unit tests. Background: - python/cpython#142183 (the issue) - python/cpython#145789 (the fix; backports #145829 / #146123 for 3.13, #145828 for 3.14) - python/cpython#88756 (3.11 change that moved frames onto the data stack) - sgl-project/sglang-torchtpu#1037 (same technique) Signed-off-by: Dan Hansen <[email protected]>
7a843f6 to
edeeb33
Compare
|
/bot run |
|
PR_Github #86808 [ run ] triggered by Bot. Commit: |
|
PR_Github #86808 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #87269 [ run ] triggered by Bot. Commit: |
|
PR_Github #87269 [ run ] completed with state |
CPython 3.11+ keeps frames in per-thread data-stack chunks. When a hot call sits at a chunk boundary, every call maps a fresh chunk and every return unmaps it (gh-142183). On GB200 each munmap also pays a Grace SMMU invalidation once NCCL has peer-mapped memory, so the churn costs milliseconds per executor step: MiniMax-M3 piecewise CUDA graph prefill steps spent about half their host time in munmap, all on the executor thread. CPython fixed this in 3.13.13 and 3.14.4; 3.12 will not get the fix.
Add run_with_frame_stack_reserve() and call PyExecutor.event_loop through it, so the loop starts near the beginning of a large data-stack chunk and ordinary call depths never reach a boundary. The reserve is applied only on affected CPython versions and can be disabled with TLLM_DISABLE_FRAME_STACK_RESERVE=1. Cover the version gate, the disable switch, the churn itself and the executor wiring with cpu_only unit tests.
Background:
Dev Engineer Review
tensorrt_llm/_utils.pyaddsrun_with_frame_stack_reserve(fn, /, *args, **kwargs). It forwards arguments, returns the result, and propagates exceptions unchanged._needs_frame_stack_reserve()is true, the module setsrun_with_frame_stack_reserve.__code__to a copy withco_stacksize=65536. This patches a code object at runtime and depends on CPython internals.TLLM_DISABLE_FRAME_STACK_RESERVEis read only at import, and only the exact value"1"disables the reserve. Changing it after import has no effect.py_executor.pychanges one call:_event_loop_wrappernow callsrun_with_frame_stack_reserve(self.event_loop). The import list is updated to match. The profiler and GC context managers are unchanged.QA Engineer Review
Test files added:
tests/unittest/utils/test_frame_stack_reserve.py(+145). It covers argument and keyword forwarding, exception propagation, the version gate, import-time application, and the disable variable. On Linux, when the reserve is needed, it runs a thread-local minor-fault churn test.tests/unittest/_torch/pyexecutor/test_event_loop_frame_stack_reserve.py(+48). It checks thatevent_loopruns directly under the reserve function's code object.Test-list changes:
tests/integration/test_lists/test-db/l0_cpu.ymladdsunittest/utils/test_frame_stack_reserve.py.Coverage verdict: needs follow-up. The utils tests cover the gate, disable switch, and forwarding. The executor wiring test has no list entry. The churn test runs only on affected Linux interpreters.
Per-File QA Perspective
tensorrt_llm/_utils.py: Verify the code-object patch applies only on gated CPython versions, and thatTLLM_DISABLE_FRAME_STACK_RESERVE=1disables it.tensorrt_llm/_torch/pyexecutor/py_executor.py: Verify executor startup, shutdown, and error handling on affected CPython versions.tests/integration/test_lists/test-db/l0_cpu.yml: Adds the utils test to the CPU list.tests/unittest/utils/test_frame_stack_reserve.py: Verify that CI runs it.tests/unittest/_torch/pyexecutor/test_event_loop_frame_stack_reserve.py: Not in any test list. Add it to atest-db/list or confirm which list runs it.Description
Test Coverage
tests/unittest/utils/test_frame_stack_reserve.py(cpu_only, added tol0_cpu.yml) covers:fnis positional-only), the return value, and unchanged exception propagation;sys.version_infotuple, non-CPython);TLLM_DISABLE_FRAME_STACK_RESERVE=1turning it off at import (one subprocess);tests/unittest/_torch/pyexecutor/test_event_loop_frame_stack_reserve.py(cpu_only, picked up by the existingunittest/_torch/pyexecutorentry inl0_cpu.yml) checks that the real reserve frame is the event loop's direct caller.TLLM_DISABLE_FRAME_STACK_RESERVE=1):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)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.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
To see a list of available CI bot commands, please comment
/bot help.