Files
sglang/python
laoyao0822 1d7149df1c Avoid remap-cache aliasing across tensor views
The CP shared-KV remap caches may receive tensor views that share the same storage but represent different logical page rows.  Keying only by storage pointer and shape can reuse a stale remap for another view, corrupting cache-hit materialization.  Use the actual tensor data pointer plus stride, storage offset, and version so different views and mutations are not collapsed into one cache entry.

Constraint: CP shared-KV bs>1 cache-hit paths reuse small tensor views over shared backing tensors.

Rejected: Clear the remap cache on every call | would avoid aliasing but add avoidable hot-path churn and hide the identity bug.

Confidence: high

Scope-risk: narrow

Directive: Do not reduce the remap cache key back to storage pointer only; same-storage views are semantically distinct here.

Tested: g0034 cjy-glm5-new PYTHONPATH=python python -m pytest -q test/registered/unit/mem_cache/test_cp_shared_kv_runtime.py::TestCpSharedKVRuntimeHelpers::test_token_slot_remap_cache_distinguishes_same_storage_views test/registered/unit/mem_cache/test_cp_shared_kv_runtime.py::TestCpSharedKVRuntimeHelpers::test_paged_slot_remap_cache_distinguishes_same_storage_views test/registered/unit/speculative/test_eagle_worker_v2_cp_hidden.py

Not-tested: local pytest for CP runtime import is blocked by missing starlette in the local base environment.
(cherry picked from commit 7360ef13565dbf21428e3b121112135a2955f913)
2026-06-21 18:47:09 +00:00
..
2026-06-10 05:54:43 +08:00