[Rebase] Rebase to vllm releases/v0.22.0 (#3891)

Signed-off-by: tzhouam <tzhouam@connect.ust.hk>
Signed-off-by: ZhengWG <zwg0606@gmail.com>
Signed-off-by: david6666666 <530634352@qq.com>
Signed-off-by: Yueqian Lin <linyueqian@outlook.com>
Signed-off-by: nainiu258 <cperfect02@163.com>
Signed-off-by: nainiu258 <101917677+nainiu258@users.noreply.github.com>
Signed-off-by: JasonJ2021 <jasonj@zju.edu.cn>
Signed-off-by: Zhou Taichang <tzhouam@connect.ust.hk>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Co-authored-by: skf <54565339+skf-1999@users.noreply.github.com>
Co-authored-by: Zheng Wengang <zwg0606@gmail.com>
Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
Co-authored-by: WeiQing Chen <40507679+david6666666@users.noreply.github.com>
Co-authored-by: SYLAR <125541396+lishunyang12@users.noreply.github.com>
Co-authored-by: Yueqian Lin <linyueqian@outlook.com>
Co-authored-by: nainiu258 <101917677+nainiu258@users.noreply.github.com>
Co-authored-by: Jason <72191212+JasonJ2021@users.noreply.github.com>
Co-authored-by: Yueqian Lin <70319226+linyueqian@users.noreply.github.com>
This commit is contained in:
62 files changed
+998 -354

No files matched your search

+57 -1
View File
@@ -36,6 +36,7 @@ from vllm_omni.platforms import current_omni_platform
if TYPE_CHECKING:
from vllm.v1.core.sched.output import SchedulerOutput
from vllm.v1.outputs import RoutedExpertsLists
else:
xgr = LazyLoader("xgr", globals(), "xgrammar")
xgr_torch_compile = LazyLoader(
@@ -57,6 +58,52 @@ class OmniGPUModelRunner(GPUModelRunner):
# when we initialize the metadata builders if enabled
self.omni_prefix_cache = None
def _omni_routed_experts_d2h(self, scheduler_output) -> None:
"""Issue routed-experts D2H copy matching upstream GPUModelRunner pattern.
Upstream does this inline in ``execute_model``:
buf = self.routed_experts_capturer.get_device_buffer()
total = scheduler_output.total_num_scheduled_tokens
self.routed_experts_cpu[:total].copy_(buf[:total], non_blocking=True)
self.routed_experts_slot_mapping_cpu[:total].copy_(
self.routed_experts_slot_mapping_device[:total], non_blocking=True)
"""
if not self.routed_experts_initialized:
return
buf = self.routed_experts_capturer.get_device_buffer()
total = scheduler_output.total_num_scheduled_tokens
self.routed_experts_cpu[:total].copy_(buf[:total], non_blocking=True)
if hasattr(self, "routed_experts_slot_mapping_device"):
self.routed_experts_slot_mapping_cpu[:total].copy_(
self.routed_experts_slot_mapping_device[:total],
non_blocking=True,
)
def _omni_extract_routed_experts(self, scheduler_output) -> "RoutedExpertsLists | None":
"""Extract routed experts matching upstream GPUModelRunner pattern.
Upstream (sync path, sample_tokens):
total = scheduler_output.total_num_scheduled_tokens
output.routed_experts = RoutedExpertsLists(
routing_data=self.routed_experts_cpu[:total].numpy(),
slot_mapping=self.routed_experts_slot_mapping_cpu[:total].numpy(),
)
Returns RoutedExpertsLists (batch-level, with slot_mapping) so that
downstream schedulers can use slot_mapping to map back to requests.
"""
from vllm.v1.outputs import RoutedExpertsLists
if not self.routed_experts_initialized:
return None
total = scheduler_output.total_num_scheduled_tokens
if total <= 0:
return None
return RoutedExpertsLists(
routing_data=self.routed_experts_cpu[:total].numpy(),
slot_mapping=self.routed_experts_slot_mapping_cpu[:total].numpy(),
)
def initialize_metadata_builders(self, kv_cache_config, kernel_block_sizes):
"""Override to fix scheduler_metadata buffer size for FA3 + CUDA graph.
@@ -747,6 +794,15 @@ class OmniGPUModelRunner(GPUModelRunner):
raise ValueError(f"Invalid hidden states type: {type(hidden_states)}")
return text_hidden_states, multimodal_outputs
def _dummy_sampler_run(self, hidden_states: torch.Tensor) -> torch.Tensor:
# Models loaded with load_format=dummy (e.g. MossTTSNano) may
# produce CPU hidden_states while the upstream sampler warmup
# expects GPU tensors. Skip the warmup in that case — a
# meaningful warmup requires real weights anyway.
if hidden_states.device != self.device:
return torch.tensor([])
return super()._dummy_sampler_run(hidden_states=hidden_states)
@torch.inference_mode()
def _dummy_run(
self,
@@ -1100,7 +1156,7 @@ class OmniGPUModelRunner(GPUModelRunner):
self.eplb_step(is_dummy=True, is_profile=is_profile)
logit_indices = np.cumsum(num_scheduled_tokens) - 1
logit_indices_device = torch.from_numpy(logit_indices).to(self.device, non_blocking=True)
logit_indices_device = torch.from_numpy(logit_indices).to(hidden_states.device, non_blocking=True)
return hidden_states, hidden_states[logit_indices_device]
# ------------------------------------------------------------------