[MR V2] Migrate to Model Runner V2

Squashed migration rebased onto current main. Collapses the 46-commit
dev/migrate-MR-v2 history (10 merge commits + superseded pre-rebase work)
into a single commit, so the diff reflects only the genuine MR-V2 feature
(worker_v2/ runners + model_states, omni schedulers, stage engine pipeline,
pooling_output serialization bridge). Content already merged to main
separately (step_audio2, tts_adapters, npu/_310p, etc.) drops out.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Taichang ZhouandClaude Opus 4.8 committed 2026-06-20 07:19:40 +00:00
1 parent cead615288
commit 9678ae58cf
74 files changed
+8244 -95

No files matched your search

+49 -6
View File
@@ -19,6 +19,7 @@ from vllm.v1.outputs import ModelRunnerOutput
from vllm.v1.request import Request, RequestStatus, StreamingUpdate
from vllm.v1.spec_decode.metrics import SpecDecodingStats
from vllm_omni.compat import make_filtered_call
from vllm_omni.core.sched.omni_scheduler_mixin import OmniSchedulerMixin
from vllm_omni.core.sched.omni_scheduling_coordinator import (
OmniSchedulingCoordinator,
@@ -28,12 +29,40 @@ from vllm_omni.core.sched.utils import omni_routed_experts_for_request
from vllm_omni.distributed.omni_connectors.transfer_adapter.chunk_transfer_adapter import (
OmniChunkTransferAdapter,
)
from vllm_omni.engine import OmniEngineCoreOutput
from vllm_omni.engine.serialization import deserialize_additional_information
from vllm_omni.engine.serialization import (
deserialize_additional_information,
serialize_additional_information,
)
from vllm_omni.outputs import OmniConnectorOutput
logger = init_logger(__name__)
_KNOWN_ENGINE_CORE_OUTPUT_COMPAT_FIELDS = {
"num_cached_tokens",
"num_external_computed_tokens",
"is_segment_finished",
"new_prompt_len_snapshot",
}
def _make_engine_core_output(**kwargs):
output, unknown = make_filtered_call(
EngineCoreOutput,
known_extra_fields=_KNOWN_ENGINE_CORE_OUTPUT_COMPAT_FIELDS,
**kwargs,
)
if unknown:
logger.warning("Unknown fields passed to EngineCoreOutput: %s", sorted(unknown))
return output
def _get_request_num_cached_tokens(request) -> int:
return max(getattr(request, "num_cached_tokens", 0), 0)
def _get_request_num_external_computed_tokens(request) -> int:
return max(getattr(request, "num_external_computed_tokens", 0), 0)
@dataclass
class KVCacheTransferData:
@@ -249,6 +278,7 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
req_id=nr.req_id,
external_req_id=(getattr(request, "external_req_id", None) if request else None),
prompt_token_ids=nr.prompt_token_ids,
prefill_token_ids=getattr(nr, "prefill_token_ids", None),
mm_features=nr.mm_features,
sampling_params=nr.sampling_params,
pooling_params=nr.pooling_params,
@@ -328,7 +358,7 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
req = self.requests.get(req_id)
if req is not None and not req.is_finished():
outputs[req.client_index].append(
OmniEngineCoreOutput(
_make_engine_core_output(
request_id=req_id,
new_token_ids=[],
kv_transfer_params={"kv_ready": True},
@@ -466,21 +496,33 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
# Get prompt logprobs for this request.
prompt_logprobs_tensors = prompt_logprobs_dict.get(req_id)
if new_token_ids or mm_output is not None or pooler_output is not None or kv_transfer_params or stopped:
# vLLM 0.23 strictly decodes EngineCoreOutput.pooling_output as a
# torch.Tensor. MR V2 runners hand off a per-request dict here, so
# serialize it onto the bytes channel; StagePool._poll_stage_raw
# rehydrates it. Tensor pooling outputs ride pooling_output as before.
pooling_output_wire = pooler_output
pooling_output_payload = None
if isinstance(pooler_output, dict):
pooling_output_payload = serialize_additional_information(pooler_output)
pooling_output_wire = None
# Add EngineCoreOutput for this Request.
outputs[request.client_index].append(
OmniEngineCoreOutput(
_make_engine_core_output(
request_id=req_id,
new_token_ids=new_token_ids,
finish_reason=finish_reason,
new_logprobs=new_logprobs,
new_prompt_logprobs_tensors=prompt_logprobs_tensors,
pooling_output=pooler_output,
pooling_output=pooling_output_wire,
pooling_output_payload=pooling_output_payload,
multimodal_output=mm_output,
stop_reason=request.stop_reason,
events=request.take_events(),
prefill_stats=request.take_prefill_stats(),
kv_transfer_params=kv_transfer_params,
trace_headers=request.trace_headers,
num_cached_tokens=_get_request_num_cached_tokens(request),
num_external_computed_tokens=_get_request_num_external_computed_tokens(request),
routed_experts=routed_experts,
num_nans_in_logits=request.num_nans_in_logits,
is_segment_finished=is_segment_finished,
@@ -507,12 +549,13 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
self.finish_requests(failed_kv_load_req_ids, RequestStatus.FINISHED_ERROR)
for request in requests:
outputs[request.client_index].append(
OmniEngineCoreOutput(
_make_engine_core_output(
request_id=request.request_id,
new_token_ids=[],
finish_reason=request.get_finished_reason(),
events=request.take_events(),
trace_headers=request.trace_headers,
num_cached_tokens=_get_request_num_cached_tokens(request),
)
)
if self.chunk_transfer_adapter is not None:
@@ -1,5 +1,6 @@
from __future__ import annotations
import os
import time
from collections import defaultdict
from typing import Any
@@ -23,6 +24,7 @@ from vllm.v1.metrics.perf import PerfStats
from vllm.v1.request import Request, RequestStatus, StreamingUpdate
from vllm.v1.spec_decode.metrics import SpecDecodingStats
from vllm_omni.compat import make_filtered_call
from vllm_omni.core.sched.omni_scheduler_mixin import OmniSchedulerMixin
from vllm_omni.core.sched.omni_scheduling_coordinator import (
OmniSchedulingCoordinator,
@@ -34,10 +36,38 @@ from vllm_omni.distributed.omni_connectors.transfer_adapter.chunk_transfer_adapt
OmniChunkTransferAdapter,
)
from vllm_omni.engine import OmniEngineCoreOutput
from vllm_omni.engine.serialization import serialize_additional_information
from vllm_omni.outputs import OmniConnectorOutput, OmniModelRunnerOutput
logger = init_logger(__name__)
VLLM_OMNI_USE_V2_RUNNER = bool(int(os.environ.get("VLLM_OMNI_USE_V2_RUNNER", "0")))
_KNOWN_ENGINE_CORE_OUTPUT_COMPAT_FIELDS = {
"num_cached_tokens",
"num_external_computed_tokens",
}
def _make_engine_core_output(**kwargs):
output, unknown = make_filtered_call(
EngineCoreOutput,
known_extra_fields=_KNOWN_ENGINE_CORE_OUTPUT_COMPAT_FIELDS,
**kwargs,
)
if unknown:
logger.warning("Unknown fields passed to EngineCoreOutput: %s", sorted(unknown))
return output
def _get_request_num_cached_tokens(request) -> int:
return max(getattr(request, "num_cached_tokens", 0), 0)
def _set_request_num_cached_tokens_if_present(request, value: int) -> None:
if hasattr(request, "num_cached_tokens"):
request.num_cached_tokens = value
class OmniGenerationScheduler(OmniSchedulerMixin, VLLMScheduler):
def __init__(self, *args, **kwargs):
@@ -314,6 +344,7 @@ class OmniGenerationScheduler(OmniSchedulerMixin, VLLMScheduler):
req_id=nr.req_id,
external_req_id=(getattr(request, "external_req_id", None) if request else None),
prompt_token_ids=nr.prompt_token_ids,
prefill_token_ids=nr.prompt_token_ids,
mm_features=nr.mm_features,
sampling_params=nr.sampling_params,
pooling_params=nr.pooling_params,
@@ -561,21 +592,36 @@ class OmniGenerationScheduler(OmniSchedulerMixin, VLLMScheduler):
# Get prompt logprobs for this request.
prompt_logprobs_tensors = prompt_logprobs_dict.get(req_id)
if new_token_ids or mm_output is not None or pooler_output is not None or kv_transfer_params or stopped:
num_cached = _get_request_num_cached_tokens(request)
if num_cached < 0:
logger.warning("Negative num_cached_tokens (%d) for request %s, clamping to 0", num_cached, req_id)
num_cached = 0
# vLLM 0.23 strictly decodes EngineCoreOutput.pooling_output as a
# torch.Tensor; a dict-shaped MR V2 payload rides the bytes channel
# instead (rehydrated in StagePool._poll_stage_raw). See OmniARScheduler.
pooling_output_wire = pooler_output
pooling_output_payload = None
if isinstance(pooler_output, dict):
pooling_output_payload = serialize_additional_information(pooler_output)
pooling_output_wire = None
# Add EngineCoreOutput for this Request.
outputs[request.client_index].append(
OmniEngineCoreOutput(
_make_engine_core_output(
request_id=req_id,
new_token_ids=new_token_ids,
finish_reason=finish_reason,
new_logprobs=new_logprobs,
new_prompt_logprobs_tensors=prompt_logprobs_tensors,
pooling_output=pooler_output,
pooling_output=pooling_output_wire,
pooling_output_payload=pooling_output_payload,
multimodal_output=mm_output,
stop_reason=request.stop_reason,
events=request.take_events(),
prefill_stats=request.take_prefill_stats(),
kv_transfer_params=kv_transfer_params,
trace_headers=request.trace_headers,
num_cached_tokens=num_cached,
num_external_computed_tokens=getattr(request, "num_external_computed_tokens", 0),
routed_experts=routed_experts,
num_nans_in_logits=request.num_nans_in_logits,
)
@@ -627,13 +673,20 @@ class OmniGenerationScheduler(OmniSchedulerMixin, VLLMScheduler):
requests = [self.requests[req_id] for req_id in failed_kv_load_req_ids]
self.finish_requests(failed_kv_load_req_ids, RequestStatus.FINISHED_ERROR)
for request in requests:
num_cached = _get_request_num_cached_tokens(request)
if num_cached < 0:
logger.warning(
"Negative num_cached_tokens (%d) for request %s, clamping to 0", num_cached, request.request_id
)
num_cached = 0
outputs[request.client_index].append(
OmniEngineCoreOutput(
_make_engine_core_output(
request_id=request.request_id,
new_token_ids=[],
finish_reason=request.get_finished_reason(),
events=request.take_events(),
trace_headers=request.trace_headers,
num_cached_tokens=num_cached,
)
)
if self.chunk_transfer_adapter is not None: