Skip to content

Commit a2fb13a

Browse files
committed
[None][test] Explicitly invalidate HF weight cache on grouped-test teardown
The per-worker HF raw-weight cache previously relied on the shared session's worker processes exiting to be cleared. Make invalidation explicit: on shared_llm_4gpu teardown (which runs before the session shuts down its workers), submit clear_worker_weight_cache() to each worker. This closes the 'setup cache / teardown invalidate' loop instead of leaning on process death. Signed-off-by: qgai <qgai@nvidia.com>
1 parent 33a140d commit a2fb13a

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

tensorrt_llm/llmapi/_grouped_test_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ def reset_worker_torch_compile_state() -> None:
8888
torch._dynamo.reset()
8989

9090

91+
def clear_worker_weight_cache() -> None:
92+
"""Drop the per-worker HF raw-weight cache (runs inside each worker).
93+
94+
The cache is a process-global keyed by checkpoint file fingerprints, so it
95+
otherwise lives until the worker process exits. Submit this to each worker
96+
via ``mpi_session.submit_sync(...)`` on group teardown to invalidate it
97+
explicitly instead of relying on process death.
98+
"""
99+
from tensorrt_llm._torch.models.checkpoints import HfWeightLoader
100+
101+
HfWeightLoader.clear_weight_cache()
102+
103+
91104
def make_shared_llm(mpi_session):
92105
"""Return an ``LLM`` factory that transparently injects a shared MPI session.
93106

tests/integration/defs/accuracy/test_llm_api_pytorch.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ def patched_start_mpi_pool(self):
7676

7777

7878
from tensorrt_llm.llmapi._grouped_test_utils import \
79-
hf_weight_cache_env as _hf_weight_cache_env # noqa: E402
79+
clear_worker_weight_cache as _clear_worker_weight_cache # noqa: E402
80+
from tensorrt_llm.llmapi._grouped_test_utils import \
81+
hf_weight_cache_env as _hf_weight_cache_env
8082
from tensorrt_llm.llmapi._grouped_test_utils import \
8183
make_shared_llm as _make_shared_llm
8284
from tensorrt_llm.llmapi._grouped_test_utils import \
@@ -109,7 +111,14 @@ def shared_mpi_session_4gpu(hf_weight_cache):
109111

110112
@pytest.fixture(scope="module")
111113
def shared_llm_4gpu(shared_mpi_session_4gpu):
112-
return _make_shared_llm(shared_mpi_session_4gpu)
114+
try:
115+
yield _make_shared_llm(shared_mpi_session_4gpu)
116+
finally:
117+
# Explicitly invalidate the per-worker HF weight cache while the shared
118+
# session is still alive (this fixture tears down before
119+
# shared_mpi_session_4gpu), instead of relying on worker process exit.
120+
if shared_mpi_session_4gpu is not None:
121+
shared_mpi_session_4gpu.submit_sync(_clear_worker_weight_cache)
113122

114123

115124
def _get_default_torch_compile_config(torch_compile):

0 commit comments

Comments
 (0)