[HiCache] Optimize LogicalHostPool free-list release (#33998)

This commit is contained in:
wangwenmingaa
2026-08-16 12:17:33 +08:00
committed by GitHub
parent 6314e9e4f5
commit 4654b927eb
2 changed files with 43 additions and 4 deletions
@@ -8,6 +8,7 @@ import torch
from sglang.srt.mem_cache.memory_pool import MHATokenToKVPool
from sglang.srt.mem_cache.memory_pool_host import (
DeepSeekV4PagedHostPool,
LogicalHostPool,
MambaPoolHost,
)
from sglang.srt.mem_cache.pool_host.mha import MHATokenToKVPoolHost
@@ -127,6 +128,10 @@ class TestLazyHostPoolRelease(CustomTestCase):
pool.clear()
return pool
@staticmethod
def _make_logical_pool():
return LogicalHostPool(size=8, page_size=2)
def _assert_lazy_release(self, pool):
self.assertEqual(pool.free(torch.empty(0, dtype=torch.int64)), 0)
self.assertEqual(pool.num_release_slots, 0)
@@ -181,6 +186,17 @@ class TestLazyHostPoolRelease(CustomTestCase):
pool.clear()
self.assertEqual(len(pool.alloc(1)), 2)
def test_logical_pool_lazy_release(self):
pool = self._make_logical_pool()
self._assert_lazy_release(pool)
# Preserve the logical pool's strict page-alignment checks.
pool.clear()
with self.assertRaises(ValueError):
pool.alloc(1)
with self.assertRaises(ValueError):
pool.free(torch.tensor([0]))
if __name__ == "__main__":
unittest.main()