Repository navigation
[https://nvbugs/6792615][fix] Keep session-prefetch output off sys.stdout - #20152
Conversation
aef0ab1 to
4e4cdd4
Compare
|
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. |
|
Please rebase to release/1.3 instead of main. |
brnguyen2
left a comment
There was a problem hiding this comment.
Approving — the comments below are optional touch-ups, not blockers.
The root-cause write-up matches the crashing thread layout. All print() calls in the prefetcher now go through _log, so no background thread in this module touches sys.stdout anymore. Because CI uses fd-level capture, the output still lands in the same place.
One side effect to keep in mind: under --capture=sys or capsys, these lines now bypass capture and go straight to the console. That's fine for diagnostics, and the summary test already uses capfd.
4e4cdd4 to
adf5831
Compare
…dout The session prefetcher printed from its build, warm and discard threads. On CPython 3.12.3, print() holds only a borrowed reference to sys.stdout, and the autouse capfd fixture in tests/unittest/conftest.py installs and frees a per-test stdout object at every teardown. A background print that races that teardown writes to freed memory and segfaults the pytest process; the faulthandler stack shows the "session-prefetch-build" thread inside print(). Route every prefetcher diagnostic through _log(), which writes to fd 1 with os.write(). pytest's fd capture redirects fd 1, so output still lands where print() put it, but no Python stream object is touched. Remove the A30 waiver of test_speculative_d2h_predictor_always_hit, which only failed because it was the test in flight when the harness crashed. Signed-off-by: qgai <qgai@nvidia.com>
adf5831 to
dcbe2d0
Compare
Drop OSError from the fd write in _log(). Several log calls come right before cleanup: the SIGKILL sweep in _reap_dead_pool, session.shutdown() in _publish, starting the reap thread in take(), and the except handler in _build. If fd 1 is a closed pipe (EPIPE) or a full non-blocking pipe (EAGAIN), a raising log call would skip that cleanup and leak a pool. Signed-off-by: qgai <qgai@nvidia.com>
|
/bot run --disable-fail-fast |
|
PR_Github #77455 [ run ] triggered by Bot. Commit: |
|
PR_Github #77455 [ run ] completed with state |
….3: Keep session-prefetch output off sys.stdout Forward-port of release/1.3 PR NVIDIA#20152 (release/1.3 commit ca9c5b6) to main. Signed-off-by: qgai <qgai@nvidia.com> Signed-off-by: Simeng Liu <simengl@nvidia.com>
….3: Keep session-prefetch output off sys.stdout Forward-port of release/1.3 PR NVIDIA#20152 (release/1.3 commit ca9c5b6) to main. Signed-off-by: qgai <qgai@nvidia.com> Signed-off-by: Simeng Liu <simengl@nvidia.com>
….3: Keep session-prefetch output off sys.stdout Forward-port of release/1.3 PR NVIDIA#20152 (release/1.3 commit ca9c5b6) to main. Signed-off-by: qgai <qgai@nvidia.com> Signed-off-by: Simeng Liu <simengl@nvidia.com>
….3: Keep session-prefetch output off sys.stdout Forward-port of release/1.3 PR NVIDIA#20152 (release/1.3 commit ca9c5b6) to main. Signed-off-by: qgai <qgai@nvidia.com> Signed-off-by: Simeng Liu <simengl@nvidia.com>
….3: Keep session-prefetch output off sys.stdout Forward-port of release/1.3 PR NVIDIA#20152 (release/1.3 commit ca9c5b6) to main. Signed-off-by: qgai <qgai@nvidia.com> Signed-off-by: Simeng Liu <simengl@nvidia.com>
….3: Keep session-prefetch output off sys.stdout Forward-port of release/1.3 PR NVIDIA#20152 (release/1.3 commit ca9c5b6) to main. Signed-off-by: qgai <qgai@nvidia.com> Signed-off-by: Simeng Liu <simengl@nvidia.com>
Dev Engineer Review
session_prefetcher.pyroutes prefetcher diagnostics through_log(), which writes to file descriptor 1 withos.write()and ignoresOSError. This avoids accessing Python’s stdout stream during capture teardown. Logging failures no longer interrupt cleanup. The prefetch and cleanup logic is otherwise unchanged.The change removes the A30 waiver for
test_speculative_d2h_predictor_always_hit. The test name was not found in the available CI or manual-QA test lists.QA Engineer Review
The PR modifies
tests/test_common/session_prefetcher.pyandtests/integration/test_lists/waives.txt. It adds no regression test functions or IDs. The waiver removal makes the A30 test eligible to run rather than skipping it.The author reports 46 passing prefetcher tests on a CPU-only host. One test failed and one was skipped because CUDA-enabled
tensorrt_llmcould not be imported; the author reports the same result on unmodifiedmain. No deterministic test covers the capture-teardown race. Coverage verdict: needs follow-up.Per-File QA Perspective
tests/test_common/session_prefetcher.py: Verify that fd capture records diagnostic output and background logging does not access Python stdout streams. The author reports that the existing prefetcher tests passed.tests/integration/test_lists/waives.txt: The A30 waiver fortest_speculative_d2h_predictor_always_hitwas removed. The test name was not found in the available CI or manual-QA lists.Description
Fixes NVBug 6792615 and its recurrence NVBug 6902356. The unittest stage (A30-PyTorch-1) dies with
Fatal Python error: Segmentation fault(exit -11). faulthandler shows the crashing thread is the session prefetcher'ssession-prefetch-buildthread, inside aprint()inSessionPrefetcher._build(tests/test_common/session_prefetcher.py). The main thread is at a test-phase boundary at that moment. The test named in the bug title is only the test that was in flight.Root cause:
print()holds only a borrowed reference tosys.stdout; CPython 3.12.10 and 3.13.3 take a strong reference instead.tests/unittest/conftest.py::cuda_error_early_quitis an autouse fixture that requestscapfd. Every unit test therefore installs its own capture stream assys.stdoutand frees it at fixture teardown.print()that races that teardown writes through a freed object and crashes the whole pytest process.Fix:
_log()helper, which writes the line to fd 1 withos.write(). pytest's fd capture redirects fd 1, so the output lands whereprint()put it: the per-test capture during a test, and the console at session finish. No Python stream object is involved.test_speculative_d2h_predictor_always_hitfiled under 6792615. That test only failed because it was in flight when the harness crashed.Target branch: release/1.3, because the bug is committed to v1.3.0.
tests/test_common/session_prefetcher.pyis identical on release/1.3 and main, and main carries the same waiver, so main needs the same change.Test Coverage
tests/unittest/llmapi/test_session_prefetcher.py(listed inl0_cpu.yml): 46 passed on a CPU-only host, validated on main. The changed file is byte-identical on release/1.3.test_session_summary_counters_and_emissionreads the prefetcher's summary line throughcapfd, so it also covers the new fd-level output path.test_patch_targets_cover_all_library_construction_sitesfailed and one case was skipped, both because the host cannot import a CUDA-enabledtensorrt_llm(libc10_cuda.so). This also happens on unmodified main.capfdfixture plus a daemon thread callingprint()segfaults with the same thread layout as the CI crash. The same setup usingos.write()never failed.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.