[AuxOutput] Add block-keyed storage for routed-expert outputs (#45635)

Signed-off-by: aoshen02 <aoshen@inferact.ai>
Signed-off-by: Nick Hill <nickhill123@gmail.com>
Co-authored-by: aoshen02 <aoshen@inferact.ai>
Co-authored-by: OpenAI Codex <codex@openai.com>
Co-authored-by: Roger Wang <hey@rogerw.io>
Co-authored-by: Nick Hill <nickhill123@gmail.com>
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Hongxin Xu
2026-09-21 10:25:05 +00:00
committed by GitHub
co-authored by aoshen02 OpenAI Codex Roger Wang Nick Hill Codex
parent 0aee727ff6
commit 0b7f11a1ee
32 changed files with 3604 additions and 877 deletions
+1 -2
View File
@@ -354,8 +354,7 @@ def test_abort_request_when_structured_output_fsm_cannot_advance():
scheduler.finished_req_ids_dict = None
scheduler.grammar_compile_error_reqs = set()
scheduler.vllm_config = Mock()
scheduler.vllm_config.model_config.enable_return_routed_experts = False
scheduler.enable_return_routed_experts = False
scheduler.aux_output_connector = None
scheduler.return_sampling_mask = False
scheduler.recompute_kv_load_failures = False
scheduler.defer_block_free = False
+71 -23
View File
@@ -19,6 +19,10 @@ from vllm.config import (
SpeculativeConfig,
VllmConfig,
)
from vllm.distributed.aux_output_connector.connector import (
AuxOutputSchedulerConnector,
AuxRequestOutput,
)
from vllm.distributed.ec_transfer.ec_connector.metrics import ECConnectorStats
from vllm.distributed.kv_transfer.kv_connector.v1.hisparse.connector import (
HiSparseConnector,
@@ -55,7 +59,6 @@ from vllm.v1.outputs import (
ECConnectorOutput,
KVConnectorOutput,
ModelRunnerOutput,
RoutedExpertsLists,
SamplingMaskLists,
make_empty_encoder_model_runner_output,
)
@@ -136,21 +139,18 @@ def test_add_requests():
assert len(scheduler.waiting) == i + 1
def test_routed_experts_prompt_start_at_prompt_end():
@pytest.mark.parametrize("max_tokens", [1, 2])
def test_routed_experts_prompt_start_at_prompt_end(max_tokens):
"""A prompt-end offset should return empty routing data, not crash."""
scheduler = create_scheduler()
(request,) = create_requests(num_requests=1)
(request,) = create_requests(num_requests=1, max_tokens=max_tokens)
request.sampling_params.routed_experts_prompt_start = request.num_prompt_tokens
scheduler.aux_output_connector = AuxOutputSchedulerConnector()
scheduler.add_request(request)
scheduler_output = scheduler.schedule()
num_tokens = scheduler_output.num_scheduled_tokens[request.request_id]
manager = Mock()
manager.routed_experts_by_slot = np.empty((0, 1, 1), dtype=np.uint8)
manager.get.return_value = np.empty((0, 1, 1), dtype=np.uint8)
scheduler.enable_return_routed_experts = True
scheduler.routed_experts_mgr = manager
scheduler._re_block_ids = {request.request_id: []}
assert scheduler_output.aux_output_connector_metadata.requests == {
request.request_id: request.num_prompt_tokens
}
outputs = scheduler.update_from_output(
scheduler_output,
@@ -161,21 +161,23 @@ def test_routed_experts_prompt_start_at_prompt_end():
logprobs=None,
prompt_logprobs_dict={},
pooler_output=[],
routed_experts=RoutedExpertsLists(
routing_data=np.zeros((num_tokens, 1, 1), dtype=np.uint8),
slot_mapping=np.arange(num_tokens),
),
aux_output_connector_output={
request.request_id: AuxRequestOutput(
request.num_prompt_tokens,
np.empty((0, 1, 1), dtype=np.uint8),
)
},
),
)
manager.get.assert_called_once_with(
[], request.num_prompt_tokens, token_start=request.num_prompt_tokens
)
assert outputs[request.client_index].outputs[0].routed_experts.shape == (0, 1, 1)
output = outputs[request.client_index].outputs[0]
assert output.new_token_ids == [0]
assert output.routed_experts.shape == (0, 1, 1)
def test_finish_request():
scheduler = create_scheduler()
scheduler.aux_output_connector = Mock()
requests = create_requests(num_requests=10)
for request in requests:
scheduler.add_request(request)
@@ -184,6 +186,7 @@ def test_finish_request():
scheduler.finish_requests(request.request_id, RequestStatus.FINISHED_ABORTED)
assert request.request_id not in scheduler.requests
assert len(scheduler.waiting) == 9 - i
scheduler.aux_output_connector.request_finished.assert_called_with(request)
def test_get_num_unfinished_requests():
@@ -1373,6 +1376,31 @@ def test_preemption_re_records_prefix_cache_query():
assert stats.preempted_requests == 1
def test_preemption_processes_stale_aux_output():
scheduler = create_scheduler(enable_prefix_caching=True)
request = create_requests(num_requests=1)[0]
scheduler.add_request(request)
scheduler_output = scheduler.schedule()
scheduler.running.remove(request)
scheduler.aux_output_connector = Mock()
scheduler._preempt_request(request, 0.0)
scheduler.aux_output_connector.request_finished.assert_called_once_with(request)
scheduler.update_from_output(
scheduler_output,
ModelRunnerOutput(
req_ids=[request.request_id],
req_id_to_index={request.request_id: 0},
sampled_token_ids=[[1000]],
logprobs=None,
prompt_logprobs_dict={},
pooler_output=[],
),
)
scheduler.aux_output_connector.take_output.assert_called_once_with(request, None)
def test_prefix_cache_stats_not_recorded_when_caching_disabled():
"""With prefix caching off there is no local lookup, so admitting a request
records no phantom miss."""
@@ -1461,6 +1489,7 @@ def test_prefix_cache_stats_counted_once_for_retried_then_scheduled_request():
def test_scheduler_reset_prefix_cache():
scheduler = create_scheduler(enable_prefix_caching=True)
scheduler.aux_output_connector = Mock()
requests = create_requests(num_requests=10)
for request in requests:
scheduler.add_request(request)
@@ -1477,10 +1506,20 @@ def test_scheduler_reset_prefix_cache():
# Reset prefix cache should fail since there are still running requests
# and they are taking KV cache
assert not scheduler.reset_prefix_cache()
scheduler.aux_output_connector.reset.assert_not_called()
with pytest.raises(RuntimeError, match=r"pause\(mode='keep'\)"):
scheduler.reset_prefix_cache(reset_running_requests=True)
# pause(mode="keep") also waits for scheduled model outputs to drain.
scheduler.set_pause_state(PauseState.PAUSED_ALL)
with pytest.raises(RuntimeError, match="model output is in flight"):
scheduler.reset_prefix_cache(reset_running_requests=True)
for request in requests:
request.num_in_flight_tokens = 0
# Reset prefix cache with reset_running_requests=True. All running requests
# Should be pushed back to the waiting queue and kv cache should be freed
assert scheduler.reset_prefix_cache(reset_running_requests=True)
scheduler.aux_output_connector.reset.assert_called_once_with()
# Verify requests moved from running to waiting
assert len(scheduler.waiting) == len(requests)
@@ -1490,6 +1529,16 @@ def test_scheduler_reset_prefix_cache():
assert scheduler.waiting[i] == request
@pytest.mark.parametrize("reset_successful", [False, True])
def test_aux_output_reset_follows_kv_reset_result(reset_successful: bool):
scheduler = create_scheduler(enable_prefix_caching=True)
scheduler.aux_output_connector = Mock()
scheduler.kv_cache_manager.reset_prefix_cache = Mock(return_value=reset_successful)
assert scheduler.reset_prefix_cache() is reset_successful
assert scheduler.aux_output_connector.reset.call_count == int(reset_successful)
def test_kv_cache_release_after_keep_pause_preserves_requests():
"""A completed keep pause permits release and recomputation of live requests."""
scheduler = create_scheduler(max_num_seqs=1, enable_prefix_caching=True)
@@ -3791,10 +3840,9 @@ def test_abort_request_when_structured_output_fsm_cannot_advance():
scheduler.kv_event_publisher = Mock()
scheduler.finished_req_ids = set()
scheduler.finished_req_ids_dict = None
scheduler.aux_output_connector = None
scheduler.grammar_compile_error_reqs = set()
scheduler.vllm_config = Mock()
scheduler.vllm_config.model_config.enable_return_routed_experts = False
scheduler.enable_return_routed_experts = False
scheduler.return_sampling_mask = False
scheduler.recompute_kv_load_failures = False
scheduler.defer_block_free = False