[NPU][Bugfix] Fix OOB gather in decode KV allocation when free pool is tight (#35727)

This commit is contained in:
xdtbynd
2026-08-27 19:44:45 +08:00
committed by GitHub
parent 97ba99067d
commit b647ae82f5
@@ -126,6 +126,7 @@ class NPUPagedTokenToKVPoolAllocator(PagedTokenToKVPoolAllocator):
if num_new_pages == 0:
out_indices = last_loc + 1
else:
start_new_pages = start_new_pages.clamp(max=num_new_pages - 1)
out_indices = (last_loc + 1) * (1 - need_new_pages) + self.free_pages[
start_new_pages
] * self.page_size * need_new_pages