Stabilize CP HiCache residency under L1/L2 pressure

CP shared KV now keeps explicit L1 and host free-room targets so pressure is handled by planned eviction instead of repeated capacity-edge retries. The host allocator gains contiguous-preferred page reservation, L1 owner-lane allocation prefers contiguous physical pages, and CP HiCache metadata preserves pending backup safety for page-granular radix updates. Mooncake transfer stats and allocator microbenchmarks are included to make the remaining transfer bottlenecks measurable rather than inferred.

Constraint: CP shared KV uses decode CP size 1 with all prefill CP ranks participating in transfer, so L1/L2 cache residency must remain page-granular and avoid extra collectives.\nConstraint: Production HiCache can be hundreds of GB, so allocator metadata overhead must be visible before enabling aggressive contiguous allocation broadly.\nRejected: Evict only the exact deficit | this keeps the cache at the cliff and causes repeated evict/allocate pressure.\nRejected: Rely on allocator scans alone for contiguity | remote microbenchmarks show fragmented 220GB-equivalent host metadata can make contiguous-preferred scans multi-ms.\nConfidence: medium\nScope-risk: moderate\nDirective: Do not increase L1/L2 free-room defaults or add new CP collectives without ETE evidence and transfer/allocator measurements.\nTested: python -m py_compile on touched runtime/test/benchmark files.\nTested: PYTHONPATH=. python -m pytest -q test/registered/unit/benchmark/test_cp_hicache_allocator_bench.py => 4 passed, 1 warning.\nTested: Remote g0034 log /mnt/beegfs/cjy/log/sglang_cp_hicache_20260601_233723.log shows active prefill process with L1/L2 free-room args, 702 HTTP 200 chat completions, 6272 prefill batches, and no fatal scheduler traceback in latest scan.\nTested: User-reported L1/L2 cache ETE validation passed on remote run.\nNot-tested: Full local pytest suite; local environment is missing several runtime dependencies.\nNot-tested: CUDA allocator microbenchmark during active production prefill process.\nNot-tested: Mooncake straggler fix; stats show transfer tail latency remains a separate bottleneck.
This commit is contained in:
laoyao0822
2026-06-02 07:58:02 +08:00
parent 8be4a3a8b5
commit ce3a20d11b
17 changed files with 2268 additions and 16 deletions
@@ -0,0 +1,47 @@
import torch
from benchmark.hicache.bench_cp_hicache_allocator_overhead import (
StandaloneHostAllocator,
_host_pages_from_gb,
_make_host_free_slots,
_parse_int_list,
)
def test_parse_int_list_accepts_commas_and_spaces():
assert _parse_int_list("1, 2,8") == [1, 2, 8]
def test_host_pages_from_gb_rounds_to_page_capacity():
assert _host_pages_from_gb(220.0, bytes_per_token=100_000, page_size=64) == 34375
def test_host_contiguous_preferred_skips_fragmented_prefix():
page_size = 4
free_slots = _make_host_free_slots(
total_pages=12,
request_pages=2,
page_size=page_size,
pattern="fragmented_prefix_later_run",
seed=0,
)
allocator = StandaloneHostAllocator(page_size=page_size, free_slots=free_slots)
selected = allocator.alloc_contiguous_preferred(2 * page_size)
selected_pages = (selected.view(-1, page_size)[:, 0] // page_size).tolist()
assert selected_pages[1] == selected_pages[0] + 1
prefix_pages = (free_slots[: 2 * page_size].view(-1, page_size)[:, 0] // page_size)
assert selected_pages != prefix_pages.tolist()
def test_host_random_fragmented_has_requested_size():
free_slots = _make_host_free_slots(
total_pages=64,
request_pages=8,
page_size=16,
pattern="random_fragmented",
seed=123,
)
assert free_slots.numel() == 64 * 16
assert torch.unique(free_slots).numel() == free_slots.numel()