Fifth of five; stacked on #38049. The split gave every namespace a file, but only for the half an operator types. This is the other half. ## The parallel quotients are declared, not written out `attn_tp_size` and its five siblings were sixty lines of near-identical properties in the runtime context, a file away from the leaves they are quotients of, so reading `parallel.py` told you what you could set and nothing about what that decides. They are declared in `Parallel` now, in the same class as those leaves. They carry no annotation, so they are not dataclass fields and `collect_input_fields` never puts them on the record -- the same mechanism that already keeps `_NS_PATH` off it. That is the right exclusion: a quotient has no operator input to preserve, and the record is what crosses a process boundary, where a stamped width is one an elastic scale-up will not refresh. ## A quotient is a value in the bag, like every other derived one `_derived_width` answered from a stamp or, failing that, a live process group. The group read could never disagree with the stamp: - `initialize_model_parallel` stamps all six as its last statement, unconditionally; - an elastic scale-up restamps `attn_dp_size` through `update_dp_attention_post_scale` -- the comment claiming it does *not* was wrong; - no hardware backend builds groups of its own; - `multimodal_gen`, which has its own `initialize_model_parallel` and does not stamp, never reads a quotient. So a built group was always already stamped, and the group read goes -- and with it the last reason for a quotient to be resolved on every read. Every input to `derive_parallel_widths` is a record field. `dcp_enabled` is `decode_context_parallel_size > 1`, not a fact about a built group; it was spelled `_DCP is not None`, which is a longer way to say the same thing. So the six are fixed once the configuration is fixed -- the same test every other `Derived(fn=...)` in this PR passes. They are declared the same way and computed the same way: once, at publish, into ordinary bag leaves. What remains is override -> stamp -> published leaf. The stamp stays above the leaf because an elastic scale-up restamps `attn_dp_size`; the override stays on top because that is how a test names a width. ## One answer for the config-derived predicates `enable_mamba_extra_buffer` and its lazy variant, `is_ep_joiner`, `is_ep_scale_joiner`, `is_startup_weight_load_overlap`: each existed as a `ServerArgs` member for the resolution pipeline and, for most of them, again as a `runtime_context` function for readers after publish. Three places to keep saying the same thing. A `Derived(fn=...)` is a pure function of the published configuration, so `publish` computes it once and stores it as an ordinary bag leaf -- a plain attribute load, which is what a read inside compiled model code needs. The function is handed the whole resolved config rather than the bag it lands in, because a derivation is free to span namespaces and the mamba one does: it reads `memory.disable_radix_cache` alongside its own `exec.mamba` strategy, which is why it could never have been a method on either bag. The pre-publish helpers stay -- resolution needs the predicate before there is a bag to read -- and three readers keep them, because they run before their own process publishes: `initialize_dp_attention`, which the weight-cache daemon calls while building its groups thirty lines before its `publish`, and `PortArgs.init_new`, a factory handed the record that already reads eighteen other fields off it. ## Notes for a reviewer **Overriding a leaf does not move its quotient.** `override(tp_size=2)` leaves `attn_tp_size` where the published config put it, because nothing is recomputed on read. A test states a topology by publishing a config -- which is what a real process does -- or by naming the width it wants, `override(attn_tp_size=2)`. Six tests say it that way now. This is the price of having one answer computed once, and it is the same price every other derived value in the config already carries. A caller that reads a quotient without publishing or overriding now gets an explicit error naming the field, instead of a default that an uninitialised group happened to supply. One fixture was in that state -- `TestMlaWriteDoorsUnderDcp` built a bare pool and asked whether DCP was on -- and it publishes a config now, which is what the process it stands in for does. Eighteen sites read these predicates without calling them. That is correct -- they are properties -- but it is worth saying they were checked, because a census that assumes otherwise reports eighteen always-true conditions. ## The skill that documents this subsystem is updated with it `.claude/rules/modify-component-must-read.md` points at `.claude/skills/sglang-runtime-context/SKILL.md` before anyone touches these files, so a stale sentence there is a wrong instruction rather than a stale note. Four of its load-bearing statements stopped being true across this series and are corrected here: `NS(...)` is no longer how a field states its namespace (the declaring class is); the DCP degrade rule is gone, because the quotients are not live reads; `mamba_extra_buffer_enabled()` and the other predicate functions it named as the shape to copy no longer exist; and the namespace-coverage ratchet is described in terms of the marker. The docstring of `test_server_args_namespaces.py` said the same thing and is fixed too. The consequence a test author actually trips over is stated there as well: overriding a leaf no longer moves its quotient, so a topology is stated by publishing a config or by naming the width. ## Verification A full registered-unit sweep (648 files) against this stack's merge-base: 19 failures on both sides, the same 19 -- AMD `gfx950`, `modelopt`, `cuda_vmm`, `weight_checker` and friends, none of them config. The narrower 139-file config sweep used earlier in this series does not contain the files this change reaches -- `test_kv_index_translator` never names `get_parallel()`, it constructs an object that does -- which is why the baseline differential over everything is what is quoted here.
456 lines
18 KiB
Python
456 lines
18 KiB
Python
"""Unit tests for the radix-cache registry, routing, and selection chain."""
|
|
|
|
from sglang.srt.runtime_context import get_context
|
|
from sglang.test.ci.ci_register import register_cpu_ci
|
|
|
|
register_cpu_ci(est_time=11, suite="base-a-test-cpu")
|
|
|
|
import unittest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from sglang.srt.mem_cache.registry import (
|
|
_RADIX_CACHE_REGISTRY,
|
|
TreeCacheBuildContext,
|
|
create_tree_cache,
|
|
default_radix_cache_factory,
|
|
get_radix_cache_factory,
|
|
register_radix_cache_backend,
|
|
registered_radix_cache_backends,
|
|
)
|
|
from sglang.test.test_utils import CustomTestCase, enter_override
|
|
|
|
|
|
def _publish(testcase, **fields):
|
|
"""Install a published config for one case and restore on its cleanup."""
|
|
from sglang.srt.runtime_context import get_context, get_server_args
|
|
|
|
override = get_context().override_server_args(**fields)
|
|
override.install()
|
|
testcase.addCleanup(override.restore)
|
|
return get_server_args()
|
|
|
|
|
|
def _make_ctx(
|
|
testcase,
|
|
*,
|
|
backend=None,
|
|
enable_streaming=False,
|
|
enable_lmcache=False,
|
|
is_hybrid_swa=False,
|
|
is_hybrid_ssm=False,
|
|
is_dsa=False,
|
|
enable_hierarchical_cache=False,
|
|
disable_radix_cache=False,
|
|
effective_chunked_prefill_size=None,
|
|
full_tokens_per_layer=None,
|
|
):
|
|
# The factory reads the published bags for the cache-backend leaves, so the
|
|
# fixture publishes them; the instance stays for the whole-object contract
|
|
# `TreeCacheBuildContext` carries.
|
|
server_args = _publish(
|
|
testcase,
|
|
radix_cache_backend=backend,
|
|
enable_streaming_session=enable_streaming,
|
|
enable_lmcache=enable_lmcache,
|
|
enable_flexkv=False,
|
|
enable_unified_cache_external_linker=False,
|
|
)
|
|
return TreeCacheBuildContext(
|
|
server_args=server_args,
|
|
params=MagicMock(),
|
|
is_hybrid_swa=is_hybrid_swa,
|
|
is_hybrid_ssm=is_hybrid_ssm,
|
|
is_dsa=is_dsa,
|
|
enable_hierarchical_cache=enable_hierarchical_cache,
|
|
disable_radix_cache=disable_radix_cache,
|
|
effective_chunked_prefill_size=effective_chunked_prefill_size,
|
|
tp_worker=MagicMock(),
|
|
model_config=MagicMock(),
|
|
tp_size=1,
|
|
tp_rank=0,
|
|
tp_group=MagicMock(),
|
|
full_tokens_per_layer=full_tokens_per_layer,
|
|
)
|
|
|
|
|
|
class _RegistryIsolationMixin:
|
|
"""Restore the global registry around each test so registrations
|
|
from one test don't leak into the next.
|
|
"""
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
self._registry_snapshot = dict(_RADIX_CACHE_REGISTRY)
|
|
|
|
def tearDown(self):
|
|
_RADIX_CACHE_REGISTRY.clear()
|
|
_RADIX_CACHE_REGISTRY.update(self._registry_snapshot)
|
|
super().tearDown()
|
|
|
|
|
|
class TestRegisterRadixCacheBackend(_RegistryIsolationMixin, CustomTestCase):
|
|
def test_register_then_lookup(self):
|
|
factory = MagicMock()
|
|
register_radix_cache_backend("oss_unit_test", factory)
|
|
self.assertIs(get_radix_cache_factory("oss_unit_test"), factory)
|
|
self.assertIn("oss_unit_test", registered_radix_cache_backends())
|
|
|
|
def test_lookup_unknown_returns_none(self):
|
|
self.assertIsNone(get_radix_cache_factory("definitely_not_registered"))
|
|
|
|
def test_empty_name_raises(self):
|
|
with self.assertRaises(ValueError):
|
|
register_radix_cache_backend("", MagicMock())
|
|
|
|
def test_whitespace_only_name_raises(self):
|
|
with self.assertRaises(ValueError):
|
|
register_radix_cache_backend(" ", MagicMock())
|
|
|
|
def test_duplicate_registration_raises(self):
|
|
register_radix_cache_backend("dupe", MagicMock())
|
|
with self.assertRaises(ValueError):
|
|
register_radix_cache_backend("dupe", MagicMock())
|
|
|
|
|
|
class TestCreateTreeCacheRouting(_RegistryIsolationMixin, CustomTestCase):
|
|
def test_dispatches_to_registered_factory(self):
|
|
cache = MagicMock()
|
|
cache.supports_streaming_session.return_value = True
|
|
factory = MagicMock(return_value=cache)
|
|
register_radix_cache_backend("custom", factory)
|
|
|
|
result = create_tree_cache(_make_ctx(self, backend="custom"))
|
|
|
|
factory.assert_called_once()
|
|
self.assertIs(result, cache)
|
|
|
|
def test_unknown_backend_raises(self):
|
|
with self.assertRaises(ValueError):
|
|
create_tree_cache(_make_ctx(self, backend="not_a_real_backend"))
|
|
|
|
@patch("sglang.srt.mem_cache.registry.default_radix_cache_factory")
|
|
def test_unset_backend_falls_back_to_default(self, default_factory):
|
|
cache = MagicMock()
|
|
cache.supports_streaming_session.return_value = True
|
|
default_factory.return_value = cache
|
|
|
|
result = create_tree_cache(_make_ctx(self, backend=None))
|
|
|
|
default_factory.assert_called_once()
|
|
self.assertIs(result, cache)
|
|
|
|
def test_streaming_wrap_when_cache_does_not_support_it(self):
|
|
inner = MagicMock()
|
|
inner.supports_streaming_session.return_value = False
|
|
register_radix_cache_backend("nonstreaming", MagicMock(return_value=inner))
|
|
|
|
with patch(
|
|
"sglang.srt.session.streaming_session.StreamingSession"
|
|
) as session_cls:
|
|
session_cls.return_value = MagicMock(name="wrapped")
|
|
result = create_tree_cache(
|
|
_make_ctx(self, backend="nonstreaming", enable_streaming=True)
|
|
)
|
|
|
|
session_cls.assert_called_once_with(inner)
|
|
self.assertIs(result, session_cls.return_value)
|
|
|
|
def test_no_streaming_wrap_when_cache_supports_it(self):
|
|
inner = MagicMock()
|
|
inner.supports_streaming_session.return_value = True
|
|
register_radix_cache_backend("streaming", MagicMock(return_value=inner))
|
|
|
|
result = create_tree_cache(
|
|
_make_ctx(self, backend="streaming", enable_streaming=True)
|
|
)
|
|
|
|
self.assertIs(result, inner)
|
|
|
|
|
|
class TestDefaultRadixCacheFactory(CustomTestCase):
|
|
"""Branch coverage for the built-in radix cache selection chain.
|
|
|
|
Each cache class is imported lazily inside the factory, so we patch
|
|
the class at its definition site to verify routing without depending
|
|
on each cache's real constructor or runtime state.
|
|
"""
|
|
|
|
def test_chunk_cache_when_chunked_prefill_and_disable_radix(self):
|
|
ctx = _make_ctx(
|
|
self, effective_chunked_prefill_size=512, disable_radix_cache=True
|
|
)
|
|
with patch("sglang.srt.mem_cache.chunk_cache.ChunkCache") as ChunkCache:
|
|
ChunkCache.return_value = MagicMock()
|
|
result = default_radix_cache_factory(ctx)
|
|
ChunkCache.assert_called_once_with(ctx.params)
|
|
self.assertIs(result, ChunkCache.return_value)
|
|
|
|
def test_swa_chunk_cache_when_chunked_prefill_disable_and_hybrid_swa(self):
|
|
ctx = _make_ctx(
|
|
self,
|
|
effective_chunked_prefill_size=512,
|
|
disable_radix_cache=True,
|
|
is_hybrid_swa=True,
|
|
)
|
|
with patch("sglang.srt.mem_cache.chunk_cache.SWAChunkCache") as SWAChunkCache:
|
|
SWAChunkCache.return_value = MagicMock()
|
|
result = default_radix_cache_factory(ctx)
|
|
SWAChunkCache.assert_called_once_with(ctx.params)
|
|
self.assertIs(result, SWAChunkCache.return_value)
|
|
|
|
def test_pure_swa_chunk_cache_when_chunked_prefill_disable_and_all_swa(self):
|
|
ctx = _make_ctx(
|
|
self,
|
|
effective_chunked_prefill_size=512,
|
|
disable_radix_cache=True,
|
|
is_hybrid_swa=True,
|
|
full_tokens_per_layer=0,
|
|
)
|
|
with patch(
|
|
"sglang.srt.mem_cache.chunk_cache.PureSWAChunkCache"
|
|
) as PureSWAChunkCache:
|
|
PureSWAChunkCache.return_value = MagicMock()
|
|
result = default_radix_cache_factory(ctx)
|
|
PureSWAChunkCache.assert_called_once_with(ctx.params)
|
|
self.assertIs(result, PureSWAChunkCache.return_value)
|
|
|
|
def test_cpp_radix_cache_when_env_flag_set(self):
|
|
ctx = _make_ctx(
|
|
self,
|
|
)
|
|
# `radix_cache_cpp` requires ninja + C++ extension to import, so
|
|
# we inject a stand-in module rather than letting patch() trigger
|
|
# the real import.
|
|
fake_module = MagicMock()
|
|
with (
|
|
patch(
|
|
"sglang.srt.mem_cache.registry.envs.SGLANG_EXPERIMENTAL_CPP_RADIX_TREE.get",
|
|
return_value=True,
|
|
),
|
|
patch.dict(
|
|
"sys.modules",
|
|
{"sglang.srt.mem_cache.radix_cache_cpp": fake_module},
|
|
),
|
|
):
|
|
result = default_radix_cache_factory(ctx)
|
|
fake_module.RadixCacheCpp.assert_called_once_with(
|
|
params=ctx.params, server_args=ctx.server_args
|
|
)
|
|
self.assertIs(result, fake_module.RadixCacheCpp.return_value)
|
|
|
|
def test_unified_radix_cache_is_the_default(self):
|
|
ctx = _make_ctx(
|
|
self,
|
|
)
|
|
# Shim both factory imports — each transitively loads sgl_kernel.
|
|
fake_components = MagicMock()
|
|
fake_radix = MagicMock()
|
|
with patch.dict(
|
|
"sys.modules",
|
|
{
|
|
"sglang.srt.mem_cache.unified_cache.components": fake_components,
|
|
"sglang.srt.mem_cache.unified_radix_cache": fake_radix,
|
|
},
|
|
):
|
|
result = default_radix_cache_factory(ctx)
|
|
fake_radix.UnifiedRadixCache.assert_called_once_with(ctx.params)
|
|
self.assertIs(result, fake_radix.UnifiedRadixCache.return_value)
|
|
|
|
def test_unified_radix_cache_when_hierarchical(self):
|
|
ctx = _make_ctx(self, enable_hierarchical_cache=True)
|
|
# Full attention with hierarchical cache also uses UnifiedRadixCache.
|
|
fake_components = MagicMock()
|
|
fake_radix = MagicMock()
|
|
with patch.dict(
|
|
"sys.modules",
|
|
{
|
|
"sglang.srt.mem_cache.unified_cache.components": fake_components,
|
|
"sglang.srt.mem_cache.unified_radix_cache": fake_radix,
|
|
},
|
|
):
|
|
result = default_radix_cache_factory(ctx)
|
|
fake_radix.UnifiedRadixCache.assert_called_once_with(ctx.params)
|
|
fake_radix.UnifiedRadixCache.return_value.init_hicache.assert_called_once_with(
|
|
ctx.server_args, ctx.params
|
|
)
|
|
ctx.tp_worker.register_hicache_layer_transfer_counter.assert_called_once()
|
|
self.assertIs(result, fake_radix.UnifiedRadixCache.return_value)
|
|
|
|
def test_unified_radix_cache_when_hierarchical_and_hybrid_ssm(self):
|
|
ctx = _make_ctx(self, enable_hierarchical_cache=True, is_hybrid_ssm=True)
|
|
# Hybrid SSM with hierarchical cache now uses UnifiedRadixCache.
|
|
fake_components = MagicMock()
|
|
fake_radix = MagicMock()
|
|
with patch.dict(
|
|
"sys.modules",
|
|
{
|
|
"sglang.srt.mem_cache.unified_cache.components": fake_components,
|
|
"sglang.srt.mem_cache.unified_radix_cache": fake_radix,
|
|
},
|
|
):
|
|
result = default_radix_cache_factory(ctx)
|
|
fake_radix.UnifiedRadixCache.assert_called_once_with(ctx.params)
|
|
fake_radix.UnifiedRadixCache.return_value.init_hicache.assert_called_once_with(
|
|
ctx.server_args, ctx.params
|
|
)
|
|
ctx.tp_worker.register_hicache_layer_transfer_counter.assert_called_once()
|
|
self.assertIs(result, fake_radix.UnifiedRadixCache.return_value)
|
|
|
|
def test_unified_radix_cache_when_hierarchical_and_hybrid_swa(self):
|
|
ctx = _make_ctx(self, enable_hierarchical_cache=True, is_hybrid_swa=True)
|
|
# Hybrid SWA with hierarchical cache also uses UnifiedRadixCache.
|
|
fake_components = MagicMock()
|
|
fake_radix = MagicMock()
|
|
with patch.dict(
|
|
"sys.modules",
|
|
{
|
|
"sglang.srt.mem_cache.unified_cache.components": fake_components,
|
|
"sglang.srt.mem_cache.unified_radix_cache": fake_radix,
|
|
},
|
|
):
|
|
result = default_radix_cache_factory(ctx)
|
|
fake_radix.UnifiedRadixCache.assert_called_once_with(ctx.params)
|
|
fake_radix.UnifiedRadixCache.return_value.init_hicache.assert_called_once_with(
|
|
ctx.server_args, ctx.params
|
|
)
|
|
ctx.tp_worker.register_hicache_layer_transfer_counter.assert_called_once()
|
|
self.assertIs(result, fake_radix.UnifiedRadixCache.return_value)
|
|
|
|
def test_unified_radix_cache_when_hierarchical_and_dsa(self):
|
|
ctx = _make_ctx(self, enable_hierarchical_cache=True, is_dsa=True)
|
|
# DSA models (e.g. DeepSeek V3.2 / GLM-5.1) with hierarchical cache
|
|
# use UnifiedRadixCache.
|
|
fake_components = MagicMock()
|
|
fake_radix = MagicMock()
|
|
with patch.dict(
|
|
"sys.modules",
|
|
{
|
|
"sglang.srt.mem_cache.unified_cache.components": fake_components,
|
|
"sglang.srt.mem_cache.unified_radix_cache": fake_radix,
|
|
},
|
|
):
|
|
result = default_radix_cache_factory(ctx)
|
|
fake_radix.UnifiedRadixCache.assert_called_once_with(ctx.params)
|
|
fake_radix.UnifiedRadixCache.return_value.init_hicache.assert_called_once_with(
|
|
ctx.server_args, ctx.params
|
|
)
|
|
ctx.tp_worker.register_hicache_layer_transfer_counter.assert_called_once()
|
|
self.assertIs(result, fake_radix.UnifiedRadixCache.return_value)
|
|
|
|
def test_unified_radix_cache_with_mori_external_linker(self):
|
|
from sglang.srt.mem_cache.storage.umbp import umbp_direct_linker
|
|
|
|
ctx = _make_ctx(self)
|
|
# The factory reads the linker settings from the bags.
|
|
enter_override(
|
|
self,
|
|
get_context().override_server_args(
|
|
enable_unified_cache_external_linker=True,
|
|
unified_cache_external_linker_backend="mori",
|
|
),
|
|
)
|
|
fake_components = MagicMock()
|
|
fake_components.ComponentType.FULL = "full"
|
|
fake_radix = MagicMock()
|
|
cache = fake_radix.UnifiedRadixCache.return_value
|
|
cache.components = ("full",)
|
|
counter = MagicMock(name="layer_done_counter")
|
|
cache.linker.layer_done_counter = counter
|
|
linker = MagicMock(name="linker")
|
|
|
|
with (
|
|
patch.dict(
|
|
"sys.modules",
|
|
{
|
|
"sglang.srt.mem_cache.unified_cache.components": fake_components,
|
|
"sglang.srt.mem_cache.unified_radix_cache": fake_radix,
|
|
},
|
|
),
|
|
patch.object(
|
|
umbp_direct_linker,
|
|
"UMBPDirectLinker",
|
|
return_value=linker,
|
|
) as linker_cls,
|
|
):
|
|
result = default_radix_cache_factory(ctx)
|
|
|
|
linker_cls.assert_called_once_with(
|
|
ctx.server_args,
|
|
ctx.params,
|
|
components={"full"},
|
|
)
|
|
cache.init_cache_linker.assert_called_once_with(linker)
|
|
ctx.params.token_to_kv_pool_allocator.get_kvcache.return_value.register_layer_transfer_counter.assert_called_once_with(
|
|
counter
|
|
)
|
|
ctx.tp_worker.register_hicache_layer_transfer_counter.assert_called_once_with(
|
|
counter
|
|
)
|
|
self.assertIs(result, cache)
|
|
|
|
def test_swa_radix_cache_when_hybrid_swa(self):
|
|
ctx = _make_ctx(self, is_hybrid_swa=True)
|
|
# SWA hybrid models now default to the unified radix tree.
|
|
fake_components = MagicMock()
|
|
fake_radix = MagicMock()
|
|
with patch.dict(
|
|
"sys.modules",
|
|
{
|
|
"sglang.srt.mem_cache.unified_cache.components": fake_components,
|
|
"sglang.srt.mem_cache.unified_radix_cache": fake_radix,
|
|
},
|
|
):
|
|
result = default_radix_cache_factory(ctx)
|
|
fake_radix.UnifiedRadixCache.assert_called_once_with(ctx.params)
|
|
self.assertIs(result, fake_radix.UnifiedRadixCache.return_value)
|
|
|
|
def test_pure_swa_radix_cache_when_all_swa(self):
|
|
ctx = _make_ctx(self, is_hybrid_swa=True, full_tokens_per_layer=0)
|
|
with patch(
|
|
"sglang.srt.mem_cache.pure_swa_radix_cache.PureSWARadixCache"
|
|
) as PureSWA:
|
|
PureSWA.return_value = MagicMock()
|
|
result = default_radix_cache_factory(ctx)
|
|
PureSWA.assert_called_once_with(params=ctx.params)
|
|
self.assertIs(result, PureSWA.return_value)
|
|
|
|
def test_mamba_radix_cache_when_hybrid_ssm(self):
|
|
ctx = _make_ctx(self, is_hybrid_ssm=True)
|
|
# Mamba hybrid models now default to the unified radix tree.
|
|
fake_components = MagicMock()
|
|
fake_radix = MagicMock()
|
|
with patch.dict(
|
|
"sys.modules",
|
|
{
|
|
"sglang.srt.mem_cache.unified_cache.components": fake_components,
|
|
"sglang.srt.mem_cache.unified_radix_cache": fake_radix,
|
|
},
|
|
):
|
|
result = default_radix_cache_factory(ctx)
|
|
fake_radix.UnifiedRadixCache.assert_called_once_with(ctx.params)
|
|
self.assertIs(result, fake_radix.UnifiedRadixCache.return_value)
|
|
|
|
def test_lmc_radix_cache_when_enable_lmcache(self):
|
|
ctx = _make_ctx(self, enable_lmcache=True)
|
|
# The lmcache backend raises at import time when the `lmcache`
|
|
# package isn't installed, so inject a stand-in module instead
|
|
# of letting patch() trigger the real import.
|
|
fake_module = MagicMock()
|
|
with patch.dict(
|
|
"sys.modules",
|
|
{"sglang.srt.mem_cache.storage.lmcache.lmc_radix_cache": fake_module},
|
|
):
|
|
result = default_radix_cache_factory(ctx)
|
|
fake_module.LMCRadixCache.assert_called_once_with(
|
|
params=ctx.params,
|
|
model_config=ctx.model_config,
|
|
tp_size=ctx.tp_size,
|
|
rank=ctx.tp_rank,
|
|
tp_group=ctx.tp_group,
|
|
)
|
|
self.assertIs(result, fake_module.LMCRadixCache.return_value)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|