[Bugfix][HiSparse][NIXL] Import full blocks without tail prefill on D (#57049)

Signed-off-by: NickLucche <nicolo.lucchesi@mistral.ai>
Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <noreply@openai.com>
Co-authored-by: Lucas Wilkinson <lwilkins@redhat.com>
This commit is contained in:
Nicolò Lucchesi
2026-09-17 15:26:10 -04:00
committed by GitHub
co-authored by OpenAI Codex Lucas Wilkinson
parent 41f9104fa6
commit 67e5b0acc9
8 changed files with 277 additions and 53 deletions
+12 -8
View File
@@ -2498,12 +2498,14 @@ class HiSparseResidentManager(_HiSparseAuxiliaryManager):
del num_tokens_main_model
assert not new_computed_blocks
if total_computed_tokens > num_local_computed_tokens:
if total_computed_tokens % self.block_size != 0:
raise ValueError(
"A host-only HiSparse import must end on a cache-block boundary."
)
imported_pages = total_computed_tokens // self.block_size
return max(cdiv(num_tokens, self.block_size) - imported_pages, 0)
# Keep the last imported page writable, including the last-token
# replay on a full prompt hit. Only earlier pages stay host-only.
imported_pages = cdiv(total_computed_tokens, self.block_size)
existing = len(self.req_to_blocks.get(request_id, ()))
needs_tail = self.get_resident_page(request_id, imported_pages - 1) is None
return int(needs_tail) + max(
cdiv(num_tokens, self.block_size) - max(imported_pages, existing), 0
)
existing = len(self.req_to_blocks.get(request_id, ()))
host_pages = cdiv(num_local_computed_tokens, self.block_size)
required = cdiv(num_tokens, self.block_size)
@@ -2518,13 +2520,15 @@ class HiSparseResidentManager(_HiSparseAuxiliaryManager):
num_local_computed_tokens: int,
num_external_computed_tokens: int,
) -> None:
"""Represent imported host history with null resident pages."""
"""Reserve a writable final page; earlier imported pages stay on host."""
assert num_external_computed_tokens > 0
num_tokens = num_local_computed_tokens + num_external_computed_tokens
blocks = self.req_to_blocks[request_id]
tail_page = cdiv(num_tokens, self.block_size) - 1
tail_page = (num_tokens - 1) // self.block_size
if len(blocks) <= tail_page:
blocks.extend([self._null_block] * (tail_page + 1 - len(blocks)))
if blocks[tail_page].is_null:
blocks[tail_page] = self.block_pool.get_new_blocks(1)[0]
def add_local_computed_blocks(
self,