[Core] Refactor omni prefix cache into Manager/Controller (#6654)
Signed-off-by: ZhengWG <zwg0606@gmail.com> Co-authored-by: amy-why-3459 <wuhaiyan17@huawei.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
25 files changed
+5710
-2149
No files matched your search
@@ -24,29 +24,40 @@ _MODEL = "Qwen/Qwen3-Omni-30B-A3B-Instruct"
|
||||
_CI_DEPLOY = get_deploy_config_path("ci/qwen3_omni_moe.yaml")
|
||||
|
||||
|
||||
# For prefix caching checks against we enable it on the thinker and talker via CLI override
|
||||
# and enable prompt token details so that we can determine if any tokens were cached.
|
||||
# We also explicitly set block size so that we can make sure the cached token counts are a
|
||||
# multiple of the block size.
|
||||
# Prefix cache is opt-in on the deploy YAML. CI overlay also pins
|
||||
# ``async_chunk: False``; the existing server keeps ``--no-async-chunk``.
|
||||
# Production Qwen YAML is ``async_chunk: true``, so a sibling server boots
|
||||
# with ``--async-chunk`` and the same cache overrides (async output builder).
|
||||
BLOCK_SIZE = 16
|
||||
_PREFIX_CACHE_SERVER_ARGS = [
|
||||
"--block-size",
|
||||
str(BLOCK_SIZE),
|
||||
"--stage-overrides",
|
||||
'{"0": {"enable_prefix_caching": true}, "1": {"enable_prefix_caching": true}}',
|
||||
"--enable-prompt-tokens-details",
|
||||
]
|
||||
test_params = [
|
||||
pytest.param(
|
||||
OmniServerParams(
|
||||
model=_MODEL,
|
||||
stage_config_path=_CI_DEPLOY,
|
||||
use_stage_cli=True,
|
||||
server_args=[
|
||||
"--no-async-chunk",
|
||||
"--block-size",
|
||||
str(BLOCK_SIZE),
|
||||
"--stage-overrides",
|
||||
'{"0": {"enable_prefix_caching": true}, "1": {"enable_prefix_caching": true}}',
|
||||
"--enable-prompt-tokens-details",
|
||||
],
|
||||
server_args=["--no-async-chunk", *_PREFIX_CACHE_SERVER_ARGS],
|
||||
),
|
||||
id="default",
|
||||
)
|
||||
]
|
||||
prefix_cache_async_chunk_params = [
|
||||
pytest.param(
|
||||
OmniServerParams(
|
||||
model=_MODEL,
|
||||
stage_config_path=_CI_DEPLOY,
|
||||
use_stage_cli=True,
|
||||
server_args=["--async-chunk", *_PREFIX_CACHE_SERVER_ARGS],
|
||||
),
|
||||
id="prefix_cache_async_chunk",
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def get_system_prompt():
|
||||
@@ -245,6 +256,83 @@ def test_thinker_prefix_caching_audio_output(omni_server, online_client) -> None
|
||||
_run_prefix_cache_check(online_client, request_config)
|
||||
|
||||
|
||||
def _assert_omni_payload_complete(resp) -> None:
|
||||
"""Async-chunk + prefix-cache must still deliver a full downstream payload."""
|
||||
assert resp.success
|
||||
assert resp.text_content
|
||||
has_audio = bool(resp.audio_bytes) or bool(resp.audio_data)
|
||||
assert has_audio
|
||||
|
||||
|
||||
@pytest.mark.advanced_model
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.omni
|
||||
@hardware_test(res={"cuda": "H100", "rocm": "MI325"}, num_cards=2)
|
||||
@pytest.mark.parametrize("omni_server", prefix_cache_async_chunk_params, indirect=True)
|
||||
def test_thinker_prefix_caching_async_chunk_identical(omni_server, online_client) -> None:
|
||||
"""Production path: ``async_chunk: true`` plus thinker/talker prefix cache.
|
||||
|
||||
Two identical streaming requests. The second must report a block-aligned
|
||||
cache hit and still produce text + audio (async output builder).
|
||||
"""
|
||||
messages = dummy_messages_from_mix_data(
|
||||
system_prompt=get_system_prompt(),
|
||||
content_text=get_prompt(),
|
||||
)
|
||||
request_config = {
|
||||
"model": omni_server.model,
|
||||
"messages": messages,
|
||||
"stream": True,
|
||||
"stream_options": {"include_usage": True},
|
||||
}
|
||||
first_response, cached_response = _run_prefix_cache_check(online_client, request_config)
|
||||
_assert_omni_payload_complete(first_response)
|
||||
_assert_omni_payload_complete(cached_response)
|
||||
|
||||
|
||||
@pytest.mark.advanced_model
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.omni
|
||||
@hardware_test(res={"cuda": "H100", "rocm": "MI325"}, num_cards=2)
|
||||
@pytest.mark.parametrize("omni_server", prefix_cache_async_chunk_params, indirect=True)
|
||||
def test_thinker_prefix_caching_async_chunk_shared_image_prefix(omni_server, online_client) -> None:
|
||||
"""Shared image / system prefix, different user text — not a full-prompt replay.
|
||||
|
||||
The second request must still hit cached tokens (block-aligned, less than
|
||||
its prompt). A merge that only works when ``hit_upto == prompt_len`` would
|
||||
fail this.
|
||||
"""
|
||||
image_data_url = f"data:image/jpeg;base64,{generate_synthetic_image(224, 224)['base64']}"
|
||||
first_messages = dummy_messages_from_mix_data(
|
||||
system_prompt=get_system_prompt(),
|
||||
image_data_url=image_data_url,
|
||||
content_text=get_prompt("text_image"),
|
||||
)
|
||||
second_messages = dummy_messages_from_mix_data(
|
||||
system_prompt=get_system_prompt(),
|
||||
image_data_url=image_data_url,
|
||||
content_text="How many squares are in this image? Answer in 20 words.",
|
||||
)
|
||||
first_cfg = {
|
||||
"model": omni_server.model,
|
||||
"messages": first_messages,
|
||||
"stream": True,
|
||||
"stream_options": {"include_usage": True},
|
||||
"modalities": ["text"],
|
||||
}
|
||||
second_cfg = {**first_cfg, "messages": second_messages}
|
||||
first_response = online_client.send_omni_request(first_cfg, request_num=1)[0]
|
||||
cached_response = online_client.send_omni_request(second_cfg, request_num=1)[0]
|
||||
assert first_response.success and cached_response.success
|
||||
assert first_response.text_content and cached_response.text_content
|
||||
num_cached = cached_response.cached_tokens
|
||||
num_prompt = cached_response.prompt_tokens
|
||||
assert num_cached is not None and num_prompt is not None
|
||||
assert num_cached > 0
|
||||
assert num_cached % BLOCK_SIZE == 0
|
||||
assert num_cached < num_prompt
|
||||
|
||||
|
||||
@pytest.mark.advanced_model
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.omni
|
||||
|
||||
Reference in new issue
Block a user