[Bugfix] Reset cached Mamba align metadata on profiling teardown (#54044)

Signed-off-by: Canlin Guo <canlinguosdu@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Canlin Guo
2026-08-30 00:43:20 -07:00
committed by GitHub
co-authored by mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 8fa4c6cdb3
commit b383e16396
2 changed files with 44 additions and 0 deletions
+8
View File
@@ -864,6 +864,14 @@ def _teardown_profiling_state(runner: "GPUModelRunner") -> None:
torch.accelerator.synchronize()
if hasattr(runner.model_state, "_mamba_ctx"):
runner.model_state._mamba_ctx = None
# Invalidate the align-mode Mamba group metadata cached from the
# profiling KVCacheConfig: the real (e.g. PP-projected) config may
# place Mamba layers into a different group layout, so it must be
# re-derived from the real config.
if hasattr(runner.model_state, "_mamba_group_ids"):
runner.model_state._mamba_group_ids = []
if hasattr(runner.model_state, "_mamba_spec"):
runner.model_state._mamba_spec = None
if hasattr(runner, "kv_caches"):
runner.kv_caches.clear()
if hasattr(runner, "attn_groups"):