Skip to content

Commit c9d2dcc

Browse files
authored
[https://nvbugs/6971730][fix] Keep Inductor's async-compile pool alive (#21007)
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
1 parent a8ce107 commit c9d2dcc

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎tensorrt_llm/_bootstrap.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
_inited = False
4747

48+
_INDUCTOR_QUIESCE_POOL_ENV = "TORCHINDUCTOR_QUIESCE_ASYNC_COMPILE_POOL"
4849
_UNIFIED_CACHE_ROOT_ENV = "TRTLLM_CACHE_DIR"
4950
_TRTLLM_DG_CACHE_ENV = "TRTLLM_DG_CACHE_DIR"
5051
_TRTLLM_DG_DUMP_CUBIN_ENV = "TRTLLM_DG_JIT_DUMP_CUBIN"
@@ -94,6 +95,14 @@ def _set_numexpr_thread_default() -> None:
9495
os.environ.setdefault("NUMEXPR_NUM_THREADS", "1")
9596

9697

98+
def _keep_inductor_compile_pool_alive() -> None:
99+
# Inductor shuts down its async-compile worker pool after a short idle
100+
# period. A compile submitted while that shutdown is in flight can wait
101+
# forever, and a rank stuck there stalls every collective of its group
102+
# (e.g. a torch.compile'd helper recompiling inside a TP forward).
103+
os.environ.setdefault(_INDUCTOR_QUIESCE_POOL_ENV, "0")
104+
105+
97106
def _add_trt_llm_dll_directory():
98107
on_windows = platform.system() == "Windows"
99108
if on_windows:
@@ -162,6 +171,7 @@ def _setup_vendored_triton_kernels():
162171
def _prepare_environment() -> None:
163172
"""Phase 1: environment and library preparation, before the Torch import."""
164173
_set_numexpr_thread_default()
174+
_keep_inductor_compile_pool_alive()
165175
_setup_unified_cache()
166176
_add_trt_llm_dll_directory()
167177
_preload_python_lib()

‎tests/unittest/test_unified_cache.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,33 @@ def test_prepare_environment_configures_cache_first(monkeypatch: pytest.MonkeyPa
129129
assert calls == ["cache", "dll", "python", "triton"]
130130

131131

132+
def test_prepare_environment_keeps_inductor_compile_pool_alive(
133+
monkeypatch: pytest.MonkeyPatch,
134+
) -> None:
135+
monkeypatch.delenv(_bootstrap._INDUCTOR_QUIESCE_POOL_ENV, raising=False)
136+
for name in (
137+
"_setup_unified_cache",
138+
"_add_trt_llm_dll_directory",
139+
"_preload_python_lib",
140+
"_setup_vendored_triton_kernels",
141+
):
142+
monkeypatch.setattr(_bootstrap, name, lambda: None)
143+
144+
_bootstrap._prepare_environment()
145+
146+
assert os.environ[_bootstrap._INDUCTOR_QUIESCE_POOL_ENV] == "0"
147+
148+
149+
def test_explicit_inductor_compile_pool_quiesce_setting_takes_precedence(
150+
monkeypatch: pytest.MonkeyPatch,
151+
) -> None:
152+
monkeypatch.setenv(_bootstrap._INDUCTOR_QUIESCE_POOL_ENV, "1")
153+
154+
_bootstrap._keep_inductor_compile_pool_alive()
155+
156+
assert os.environ[_bootstrap._INDUCTOR_QUIESCE_POOL_ENV] == "1"
157+
158+
132159
def test_mpi_pool_environment_forwards_unified_cache_variables(
133160
monkeypatch: pytest.MonkeyPatch,
134161
) -> None:

0 commit comments

Comments
 (0)