[mem_cache] Split duplicate insert frees at the SWA eviction floor - #37481
Conversation
|
/tag-and-rerun-ci |
| max(state.params.swa_evicted_seqlen - abs_start, 0), dup.numel() | ||
| ) | ||
| if swa_already_freed > 0: | ||
| step_actions.append(FreeDeviceKVFullOnly([dup[:swa_already_freed]])) |
There was a problem hiding this comment.
Could you help to confirm if we have async assert inside token_to_kv_pool_allocator.free_full to confirm if there's no swa mapping from the full slots? I feel that could better guardrail the change to avoid leakage.
There was a problem hiding this comment.
For this PR, the changes should be no-ops. The whole stack is to remove [swa_indices > 0], I added an async assert here, https://github.com/sgl-project/sglang/pull/36723/changes#diff-5e4f4819b718cd7f28b375e1d1729d525290e1f8fa79da7353ccad7c2ad3b56cR368
Which has real behavior changes.
There was a problem hiding this comment.
Thanks for your clarification. Yeah, ideally, this change should be no-op.
However, I think that assertion you mentioned verify existence of SWA peer in free_swa, while FreeDeviceKVFullOnly should expect no SWA peer (which should be served as a long term invariant of FreeDeviceKVFullOnly usage. And if we use async assert, the overhead should be small enough). WDYT?
There was a problem hiding this comment.
Yes, I will add an extra guard of expect(swa.peer_released, mapping[free_index] == 0) in #36723
Summary
_insert_walk_stepsplits the duplicate slice of an insert at the request'sswa_evicted_seqlen:FreeDeviceKVFullOnlybelow it,FreeDeviceKVabove it, in both the Python and the Rust tree coreSWARadixCache._insert_helperalready does throughfree_kv_row_segmentsWhy
free_swareadsmapping = 0for those slots and theswa_indices > 0filter drops them, at the cost of one host sync per release; once that filter becomes a contract ([mem_cache] Makefree_swasync-free onpage_size == 1#36723) the same free tripsswa.peer_mappedcache_unfinished_reqinsert and the HiCache load-back insert (floor = span_end - len(swa_dev))Tests
test_dup_slice_below_eviction_floor_frees_full_onlyasserts the emitted actions in the shared unified suite, so it runs under both tree-core backends; fails on the current code with noFreeDeviceKVFullOnlyemittedcomponents/swa.rsoverlap tests whose duplicate slice lies entirely below the floor now expectFreeDeviceKVFullOnlytest_unified_radix_cache_unittest.pyandcargo test --lockedpassCI States
Latest PR Test (Base): 🚫 Run #33573510228
Latest PR Test (Extra): ✅ Run #33573509920
Latest PR Test (AMD ROCm 7.2): 🚫 Run #33573510276