Skip to content

Commit 959056d

Browse files
committed
test(runtime): clarify full-refresh page alias regression
Update the full-refresh block-table test to encode the concrete corruption mode: a non-tail prefix page is repointed to a canonical cached page while the freed physical page is reused as the new tail. A tail-only mirror update would leave logical page 0 and logical page 2 aliasing the same physical page. Keep the test CPU-only by asserting the update_block_table contract passed to the page-table kernel: full_refresh rows copy the scheduler's occupied_pages from logical page 0, while ordinary rows still use their tail delta. Validation: - python -m pytest -q test/runtime/test_update_block_table_capacity_clamp.py - pre-commit run --all-files Signed-off-by: Stanley Winata <stanley.winata@amd.com>
1 parent 048e5b1 commit 959056d

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

test/runtime/test_update_block_table_capacity_clamp.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,25 @@ def emit(self, record: logging.LogRecord) -> None:
233233
assert any("page copy would exceed req_to_page capacity" in m for m in msgs), msgs
234234

235235

236-
def test_update_block_table_full_refresh_copies_whole_row(monkeypatch):
237-
"""A full_refresh=1 request must copy the scheduler's full occupied_pages
238-
row from logical page 0, ignoring the begin/size tail delta; a full_refresh=0
239-
request in the same batch keeps the tail-only delta."""
236+
def test_update_block_table_full_refresh_replaces_prefix_page(monkeypatch):
237+
"""full_refresh must copy repointed non-tail pages, not only append the tail.
238+
239+
If a prefix page changes from private P0 to canonical CACHED and the freed
240+
P0 is immediately reused as the new tail, a tail-only mirror update would
241+
leave logical page 0 and logical page 2 pointing at the same physical page.
242+
"""
240243
from tokenspeed.runtime.execution import cache_loc_kernel
241244

242245
req_to_page = torch.zeros(8, 513, dtype=torch.int32)
243-
# req[0]: full refresh -> whole row from 0, delta fields ignored.
246+
# req[0]: old mirror had [10, 11]. The scheduler authoritative row is
247+
# [99, 11, 10]: prefix repointed to cached page 99, freed page 10 reused
248+
# as the new tail. Copying only begin=2,new=[10] would leave [10, 11, 10].
244249
# req[1]: tail-only -> begin=200, only the 2-page delta.
245250
forward_op = _make_forward_op(
246-
begins=[100, 200],
251+
begins=[2, 200],
247252
sizes=[1, 2],
248-
new_occupied_pages=[[999], [50, 51]],
249-
occupied_pages=[[10, 11, 12, 13], [40, 41, 42]],
253+
new_occupied_pages=[[10], [50, 51]],
254+
occupied_pages=[[99, 11, 10], [40, 41, 42]],
250255
full_refresh=[1, 0],
251256
)
252257

@@ -268,11 +273,12 @@ def fake_update_req_to_page(
268273
forward_op, device="cpu", req_to_page=req_to_page
269274
)
270275

271-
# req[0] refreshed the whole 4-page row from start 0; req[1] kept its tail delta.
272-
assert captured["num"] == [4, 2]
276+
# req[0] refreshed the whole 3-page row from start 0; req[1] kept its tail
277+
# delta. The flattened full-refresh row must be [99, 11, 10], not the
278+
# tail-only aliasing update [10].
279+
assert captured["num"] == [3, 2]
273280
assert captured["starts"] == [0, 200]
274-
# Flattened: whole row of req[0] then the tail delta of req[1].
275-
assert captured["pages"] == [10, 11, 12, 13, 50, 51]
281+
assert captured["pages"] == [99, 11, 10, 50, 51]
276282

277283

278284
def test_update_block_table_full_refresh_respects_clamp(monkeypatch):

0 commit comments

Comments
 (0)