[None][test] Make the session-reuse pool seam isinstance-transparent - #16520
[None][test] Make the session-reuse pool seam isinstance-transparent#16520sunnyqgg wants to merge 1 commit into
Conversation
The pool-creation seams held a plain FUNCTION in place of MpiPoolSession. Library code doing isinstance(x, MpiPoolSession) against the patched module attribute then raises 'TypeError: isinstance() arg 2 must be a type' — proxy.py's killed-worker detection added exactly such a check and every bare LLM() creation failed until it was worked around with an exclusion-based match in the consumer. Remove the hazard class at its source: the seam now holds a real class whose metaclass routes construction to the reuse factory and instance/subclass checks to the real MpiPoolSession, so both usage patterns keep working — including isinstance consumers added after this layer was written. The exclusion-based check in _register_worker_processes can be reverted to the natural isinstance(self.mpi_session, MpiPoolSession) form at leisure. Signed-off-by: qgai <qgai@nvidia.com>
📝 WalkthroughWalkthroughThe session reuse test seam now replaces ChangesSession reuse seam
Estimated code review effort: 3 (Moderate) | ~15–30 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/test_common/session_reuse.py (1)
206-234: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd precise annotations to the new functions.
tests/test_common/session_reuse.py#L206-L234: annotate the shim factory and each metaclass hook.tests/unittest/llmapi/test_session_reuse.py#L300-L317: add-> None.tests/unittest/llmapi/test_session_reuse.py#L320-L329: annotatereuse_cacheprecisely and add-> None.As per coding guidelines, “Annotate every function.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_common/session_reuse.py` around lines 206 - 234, The new shim functions lack required annotations. In tests/test_common/session_reuse.py lines 206-234, annotate _isinstance_transparent_shim and each _SeamMeta hook with precise parameter and return types; in tests/unittest/llmapi/test_session_reuse.py lines 300-317, add -> None; and in lines 320-329, precisely annotate reuse_cache and add -> None.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/test_common/session_reuse.py`:
- Around line 206-234: The new shim functions lack required annotations. In
tests/test_common/session_reuse.py lines 206-234, annotate
_isinstance_transparent_shim and each _SeamMeta hook with precise parameter and
return types; in tests/unittest/llmapi/test_session_reuse.py lines 300-317, add
-> None; and in lines 320-329, precisely annotate reuse_cache and add -> None.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 7628505a-949c-46a0-9886-5b091a8fd000
📒 Files selected for processing (2)
tests/test_common/session_reuse.pytests/unittest/llmapi/test_session_reuse.py
|
Closing: this change has been folded into #15908 (cherry-picked as-is, then generalized — the shim now lives in the shared _session_utils and is applied at BOTH the session-reuse and session-prefetch seams). Tracking continues there. |
Summary
MpiPoolSessionattribute of three library modules with a factory function at test time. Any library code doingisinstance(x, MpiPoolSession)against a patched module then raisesTypeError: isinstance() arg 2 must be a type.proxy.py(killed-worker detection). The combination broke every bareLLM()creation on post-7/15 bases: ~8000 test failures across 15+ builds and 12+ PRs in two days, including post-merge main (e.g. build 48117 / PR [None][fix] avoid attention workspace resize during CUDA graph capture #16319 as an innocent victim). [https://nvbugs/6435642][fix] handle session reuse worker registration #16444 worked around it consumer-side with an exclusion-based match.__call__) and instance/subclass checks to the realMpiPoolSession(__instancecheck__/__subclasscheck__). Both usage patterns work, including isinstance consumers added in the future — no more whack-a-mole._register_worker_processesinproxy.pycan revert its exclusion-based match back to the naturalisinstance(self.mpi_session, MpiPoolSession)form.Changes
tests/test_common/session_reuse.py: install an isinstance-transparent metaclass shim at the seams instead of a bare function.tests/unittest/llmapi/test_session_reuse.py: shim unit test (construction routing + instance/subclass transparency) and an end-to-end regression test against the real patchedtensorrt_llm.executor.proxyseam (raisesTypeErroron pre-fix code).Test plan
tests/unittest/llmapi/test_session_reuse.py— 23 passed (21 existing + 2 new) with the session-reuse plugin activeSummary by CodeRabbit
Bug Fixes
isinstanceorissubclass.Tests