From d8613d3b53f3af52a3d805ade11c84ce98eae63d Mon Sep 17 00:00:00 2001 From: Eran Geva <19514940+MrGeva@users.noreply.github.com> Date: Wed, 15 Jul 2026 08:45:46 -0700 Subject: [PATCH] [https://nvbugs/6435642][fix] avoid isinstance(MpiPoolSession) crash under session-reuse test infra _start_executor_workers() added isinstance(self.mpi_session, MpiPoolSession) to gate registering worker process identities with the new WorkerProcessMonitor. tests/test_common/session_reuse.py (an existing, default-on pytest speedup for bare LLM(...) tests) monkeypatches this module's MpiPoolSession attribute to a pool-reuse factory *function* so it can intercept `MpiPoolSession(n_workers=...)` construction calls. Under that patch, isinstance(x, MpiPoolSession) raises "isinstance() arg 2 must be a type, a tuple of types, or a union" because a function isn't a valid isinstance() type argument, crashing every MPI-mode LLM/executor test. Re-import MpiPoolSession from its origin module (tensorrt_llm.llmapi.mpi_session) at the check site instead of relying on this module's (intentionally monkeypatchable) module-level name, which the test-reuse pool-creation factory at self.mpi_session = MpiPoolSession(...) still needs to keep using. Signed-off-by: Eran Geva <19514940+MrGeva@users.noreply.github.com> --- tensorrt_llm/executor/proxy.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tensorrt_llm/executor/proxy.py b/tensorrt_llm/executor/proxy.py index 11451bad5b67..b1a70d444e7d 100644 --- a/tensorrt_llm/executor/proxy.py +++ b/tensorrt_llm/executor/proxy.py @@ -573,7 +573,14 @@ def mpi_done_callback(future: concurrent.futures.Future): raise RuntimeError( "Executor worker returned error") from ready_signal - if isinstance(self.mpi_session, MpiPoolSession) and len(status) == 3: + # Re-import MpiPoolSession from its origin module rather than using the + # module-level name above: test infra (tests/test_common/session_reuse.py) + # monkeypatches this module's ``MpiPoolSession`` attribute to a pool-reuse + # factory function for bare LLM(...) tests, and isinstance() against a + # non-type raises TypeError. + from ..llmapi.mpi_session import MpiPoolSession as _MpiPoolSessionCls + if isinstance(self.mpi_session, + _MpiPoolSessionCls) and len(status) == 3: worker_process_identities: List[WorkerProcessIdentity] = status[2] self._worker_process_monitor.register(worker_process_identities)