[Feat] Add native Mooncake KV transfer from AR to DiT (#7166)
Signed-off-by: asukaqaq-s <1311722138@qq.com> Signed-off-by: Acerak01-fy <wfy2003324@163.com> Co-authored-by: Acerak01-fy <wfy2003324@163.com> Co-authored-by: amy-why-3459 <wuhaiyan17@huawei.com>
This commit is contained in:
53 files changed
+2564
-204
No files matched your search
@@ -22,6 +22,7 @@ from vllm.v1.engine.exceptions import EngineDeadError
|
||||
from vllm.v1.metrics.stats import IterationStats
|
||||
|
||||
from vllm_omni.engine import OmniEngineCoreOutput
|
||||
from vllm_omni.engine.errors import NativeKVHandoffError
|
||||
from vllm_omni.engine.messages import (
|
||||
AbortRequestMessage,
|
||||
AbortResultMessage,
|
||||
@@ -1414,6 +1415,105 @@ async def test_handle_streaming_update_unknown_request_is_dropped() -> None:
|
||||
assert "req-unknown" not in orchestrator.request_states
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("native_kv", [False, True])
|
||||
async def test_add_request_attaches_native_kv_ticket_before_dispatch(mocker, native_kv) -> None:
|
||||
sampling = SamplingParams(extra_args={"keep": "sampling"})
|
||||
prompt = SimpleNamespace(sampling_params=SamplingParams(extra_args={"keep": "prompt"}))
|
||||
source = StagePool(
|
||||
0,
|
||||
FakeStageClient(),
|
||||
stage_vllm_config=SimpleNamespace(
|
||||
kv_transfer_config=SimpleNamespace(kv_role="kv_producer") if native_kv else None
|
||||
),
|
||||
)
|
||||
target = StagePool(1, FakeStageClient(stage_type="diffusion", final_output=True))
|
||||
orchestrator = Orchestrator(
|
||||
request_async_queue=asyncio.Queue(),
|
||||
output_async_queue=asyncio.Queue(),
|
||||
rpc_async_queue=asyncio.Queue(),
|
||||
stage_pools=[source, target],
|
||||
)
|
||||
|
||||
async def check_dispatch(request_id, req_state, request, **kwargs):
|
||||
assert req_state.native_kv_transfer_id == ("xfer-req" if native_kv else None)
|
||||
for params, preserved in ((sampling, "sampling"), (request.sampling_params, "prompt")):
|
||||
assert params.extra_args["keep"] == preserved
|
||||
if native_kv:
|
||||
assert params.extra_args["kv_transfer_params"] == {
|
||||
"transfer_id": "xfer-req",
|
||||
"do_remote_decode": True,
|
||||
"do_remote_prefill": False,
|
||||
}
|
||||
else:
|
||||
assert "kv_transfer_params" not in params.extra_args
|
||||
return 0
|
||||
|
||||
dispatch = mocker.patch.object(source, "submit_initial", side_effect=check_dispatch)
|
||||
await orchestrator._handle_add_request(
|
||||
StageSubmissionMessage(
|
||||
type="add_request",
|
||||
request_id="req",
|
||||
prompt=prompt,
|
||||
original_prompt={},
|
||||
output_prompt_text=None,
|
||||
sampling_params_list=[sampling, OmniDiffusionSamplingParams()],
|
||||
final_stage_id=1,
|
||||
preprocess_ms=0,
|
||||
request_timestamp=0,
|
||||
enqueue_ts=0,
|
||||
)
|
||||
)
|
||||
dispatch.assert_awaited_once()
|
||||
|
||||
|
||||
def test_native_handoff_uses_bound_replica_and_reports_missing_binding(mocker) -> None:
|
||||
orchestrator = object.__new__(Orchestrator)
|
||||
orchestrator.stage_pools = [mocker.Mock()]
|
||||
orchestrator.stage_pools[0].get_bound_client.return_value = None
|
||||
req_state = SimpleNamespace(native_kv_transfer_id="xfer-req")
|
||||
output = SimpleNamespace(kv_transfer_params={"num_transfer_tokens": 4})
|
||||
|
||||
with pytest.raises(NativeKVHandoffError, match="bound AR replica"):
|
||||
orchestrator._diffusion_submit_kwargs("req", 0, SimpleNamespace(engine_input_source=[0]), req_state, output)
|
||||
orchestrator.stage_pools[0].get_bound_client.assert_called_once_with("req")
|
||||
# The pool default points at replica 0; this request actually used replica 1.
|
||||
orchestrator.stage_pools[0].stage_vllm_config = SimpleNamespace(
|
||||
kv_transfer_config=SimpleNamespace(engine_id="ar-0")
|
||||
)
|
||||
config = SimpleNamespace(engine_id="ar-1", kv_connector_extra_config={"bootstrap_addr": "http://host:8999"})
|
||||
orchestrator.stage_pools[0].get_bound_client.return_value = SimpleNamespace(
|
||||
vllm_config=SimpleNamespace(kv_transfer_config=config)
|
||||
)
|
||||
params = orchestrator._diffusion_submit_kwargs(
|
||||
"req", 0, SimpleNamespace(engine_input_source=[0]), req_state, output
|
||||
)
|
||||
assert params["kv_transfer_params"]["remote_engine_id"] == "ar-1"
|
||||
assert params["kv_transfer_params"]["remote_bootstrap_addr"] == "http://host:8999"
|
||||
assert "remote_engine_id" not in output.kv_transfer_params
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_native_handoff_failure_is_request_scoped(mocker):
|
||||
orchestrator = object.__new__(Orchestrator)
|
||||
fail = mocker.patch.object(orchestrator, "_fail_request_client_error", new_callable=mocker.AsyncMock)
|
||||
|
||||
def lost_binding():
|
||||
raise NativeKVHandoffError("bound AR replica is unavailable")
|
||||
|
||||
assert not await orchestrator._dispatch_or_fail_request(
|
||||
lost_binding, req_id="req", stage_id=1, operation="inter-stage forward"
|
||||
)
|
||||
fail.assert_awaited_once_with(
|
||||
"req",
|
||||
1,
|
||||
"bound AR replica is unavailable",
|
||||
status_code=502,
|
||||
error_type="NativeKVHandoffError",
|
||||
release_owners=True,
|
||||
)
|
||||
|
||||
|
||||
async def test_handle_streaming_update_passes_prompt_text_to_stage_pool() -> None:
|
||||
class RecordingPool:
|
||||
def __init__(self) -> None:
|
||||
|
||||
Reference in new issue
Block a user