Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions tests/v1/kv_connector/unit/test_moriio_hma_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def _make_read_request(remote_block_ids):
def test_update_state_drops_decode_recompute_tail_block(
external_tokens, has_mamba, zero_ids
):
"""Only full hybrid READ destinations skip zeroing; local tails still zero."""
"""Full READ destinations skip zeroing; local tails still zero."""
sched = _make_read_scheduler()
sched._has_mamba = has_mamba
remote_blocks = [[10, 11], [91]] if has_mamba else [[10, 11]]
Expand All @@ -787,7 +787,7 @@ def test_update_state_drops_decode_recompute_tail_block(
before = asdict(output)
meta = sched.build_connector_meta(output)
assert meta.reqs_to_recv["req"].local_block_ids == expected_blocks
if zero_ids and has_mamba and external_tokens:
if zero_ids and external_tokens:
before["new_block_ids_to_zero"] = zero_ids[1:]
assert asdict(output) == before

Expand All @@ -798,6 +798,19 @@ def test_update_state_drops_decode_recompute_tail_block(
assert output.new_block_ids_to_zero == [100, 101, 102]


def test_attention_only_read_skips_zeroing_in_every_group():
"""Mixed-precision attention-only hybrids zero pages in every READ group."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the docstring says these models "zero pages in every READ group", but the test asserts the opposite (READ pages are dropped from the zeroing list).

Suggested change
"""Mixed-precision attention-only hybrids zero pages in every READ group."""
"""Attention-only READ skips zeroing its destinations in every group."""

sched = _make_read_scheduler()
sched._has_mamba = False
request = _make_read_request([[10, 11], [12]])
sched._reqs_need_recv["req"] = (request, [[100, 101], [300]])

output = SchedulerOutput.make_empty()
output.new_block_ids_to_zero = [100, 101, 102, 300, 301]
sched.build_connector_meta(output)
assert output.new_block_ids_to_zero == [102, 301]


def test_update_state_pairs_shorter_local_blocks_with_remote_suffix():
sched = _make_read_scheduler()
request = _make_read_request([[10, 11, 12], [92]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1361,18 +1361,15 @@ def build_connector_meta(
local_block_ids=block_ids,
kv_transfer_params=kv_params,
)
if (
self.mode == MoRIIOMode.READ
and self._has_mamba
and scheduler_output.new_block_ids_to_zero
):
# Hybrid models zero recycled attention pages that held Mamba state.
# Host-submitted READs overwrite these pages and can race zeroing.
if self.mode == MoRIIOMode.READ and scheduler_output.new_block_ids_to_zero:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this filter now runs on every READ-mode step for mixed-precision models, including the prefill side where _reqs_need_recv is always empty, and copies new_block_ids_to_zero for nothing. Checking _reqs_need_recv first skips that.

Suggested change
if self.mode == MoRIIOMode.READ and scheduler_output.new_block_ids_to_zero:
if (
self.mode == MoRIIOMode.READ
and self._reqs_need_recv
and scheduler_output.new_block_ids_to_zero
):

# Mamba and mixed-precision caches zero new pages on the compute
# stream. Host-submitted READs overwrite these pages and can race it.
# Hybrid READ metadata puts the aligned attention pages first.
read_dst_block_ids = {
b
for _, block_ids in self._reqs_need_recv.values()
for b in block_ids[0]
for group in (block_ids[:1] if self._has_mamba else block_ids)

@simondanielsson simondanielsson Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is the condition now overly loose? IIUC zeroing happens either if it's mamba or if using mixed precision kv. Can we check that instead so it aligns full with needs_kv_cache_zeroing?

Ideally we would use needs_kv_cache_zeroing directly so we don't have to mirror the check as that will cause drifts in the future, not sure if that's possible though

for b in group
}
scheduler_output.new_block_ids_to_zero = [
b
Expand Down
Loading