94057c3d3e
PR Test (NPU) / check-changes (push) Has been cancelled
PR Test (NPU) / pr-gate (push) Has been cancelled
PR Test (NPU) / set-image-config (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-4-npu-a3 (push) Has been cancelled
PR Test (NPU) / stage-b-test-16-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-1-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-2-npu-a3 (push) Has been cancelled
PR Test (Arm64) / pr-gate (push) Has been cancelled
PR Test (Arm64) / check-changes (push) Has been cancelled
PR Test (Arm64) / build-test (push) Has been cancelled
PR Test (sgl-router) / gate (push) Has been cancelled
PR Test (sgl-router) / tier-1 — lint (push) Has been cancelled
PR Test (sgl-router) / tier-2 — build + test (push) Has been cancelled
PR Test (sgl-router) / tier-3 — docker (placeholder) (push) Has been cancelled
PR Test (sgl-router) / tier-3 — k8s integration (push) Has been cancelled
PR Test (sgl-router) / tier-3 — e2e (push) Has been cancelled
PR Test (sgl-router) / finish (push) Has been cancelled
PR Test (NPU) / single-node-poc (map[name:qwen3_6_27b_w8a8_1p_in64k_out1k_50ms runner:linux-aarch64-a3-2 test_case:test/registered/ascend/performance/qwen3_6_27b/test_npu_qwen3_6_27b_w8a8_1p_in64k_out1k_50ms.py test_type:perf]) (push) Has been cancelled
PR Test (NPU) / pr-test-npu-finish (push) Has been cancelled
PR Test (Xeon) / pr-gate (push) Has been cancelled
PR Test (Xeon) / check-changes (push) Has been cancelled
PR Test (Xeon) / build-test (, xeon-gnr, base-b-test-cpu) (push) Has been cancelled
PR Test (XPU) / check-changes (push) Has been cancelled
PR Test (XPU) / pr-gate (push) Has been cancelled
PR Test (XPU) / stage-a-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / wait-for-stage-a (push) Has been cancelled
PR Test (XPU) / stage-b-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / finish (push) Has been cancelled
CI Model Inventory / build-inventory (push) Has been cancelled
Lint / lint (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Compilation Check (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Manual Policy (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Request Processing (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Summary (push) Has been cancelled
PR Test (SMG) / build-wheel (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on windows (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (x86_64 - auto) (push) Has been cancelled
PR Test (SMG) / python-unit-tests (push) Has been cancelled
PR Test (SMG) / unit-tests (push) Has been cancelled
PR Test (SMG) / benchmarks (push) Has been cancelled
PR Test (SMG) / chat-completions (push) Has been cancelled
PR Test (SMG) / chat-completions-4gpu (push) Has been cancelled
PR Test (SMG) / e2e (push) Has been cancelled
PR Test (SMG) / docker-build-test (push) Has been cancelled
PR Test (SMG) / k8s-integration (push) Has been cancelled
PR Test (SMG) / finish (push) Has been cancelled
PR Test (SMG) / summarize-benchmarks (push) Has been cancelled
Release SGLang Model Gateway Docker Image / publish (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Build SDist (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Upload to PyPI (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (aarch64, 12.9, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (x86_64, 12.9, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu129 (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (aarch64, 13.0, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (x86_64, 13.0, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu130 (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 700) (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 720) (push) Has been cancelled
Release SGLang Kernels / release-rocm700 (push) Has been cancelled
Release SGLang Kernels / release-rocm720 (push) Has been cancelled
Release SGLang Kernels / build-musa43 (43, 3.10) (push) Has been cancelled
Release SGLang Kernels / release-musa43 (push) Has been cancelled
163 lines
5.9 KiB
Python
163 lines
5.9 KiB
Python
"""MiMo-V2-ASR model.
|
|
|
|
Reuses the LM scaffold of ``MiMoForCausalLM`` and adds audio encoder
|
|
components via ``AudioEncoderMixin``. The encoder modules are attached as
|
|
top-level attributes (no ``audio_encoder.`` prefix) so the checkpoint
|
|
state_dict aligns 1:1 with ``self.named_parameters()``.
|
|
"""
|
|
|
|
import logging
|
|
from typing import Any, Iterable, List, Optional, Tuple
|
|
|
|
import torch
|
|
|
|
from sglang.srt.managers.mm_utils import (
|
|
MultiModalityDataPaddingPatternMultimodalTokens,
|
|
general_mm_embed_routine,
|
|
)
|
|
from sglang.srt.managers.schedule_batch import MultimodalInputs
|
|
from sglang.srt.model_executor.forward_batch_info import ForwardBatch, PPProxyTensors
|
|
from sglang.srt.model_loader.weight_utils import default_weight_loader
|
|
from sglang.srt.models import mimo_audio as _mimo_audio_module
|
|
from sglang.srt.models.mimo import MiMoForCausalLM
|
|
from sglang.srt.models.mimo_audio import AudioEncoderMixin, MiMoAudioEncoderConfig
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def _maybe_override_audio_attn_for_blackwell() -> None:
|
|
"""Swap mimo_audio.flash_attn_varlen_func to upstream FA2 on GPUs that
|
|
sgl-kernel's FA3 doesn't support.
|
|
|
|
sgl-kernel FA3 only covers sm80/86/89/90 — on Blackwell consumer cards
|
|
(sm_120 / RTX 50xx) its varlen kernel raises NotImplementedError. ASR is
|
|
small enough to be deployed on those GPUs, so when FA3 isn't supported
|
|
we replace the module-level reference with upstream flash-attn (FA2),
|
|
which works on sm_120. No-op on supported GPUs (FA3 stays).
|
|
|
|
MiMo-V2 (the heavy multimodal model) is only deployed on H100/A100, so
|
|
this override never triggers in its hot path.
|
|
"""
|
|
try:
|
|
from sgl_kernel.flash_attn import is_fa3_supported
|
|
except ImportError:
|
|
return
|
|
if is_fa3_supported():
|
|
return
|
|
try:
|
|
from flash_attn import flash_attn_varlen_func
|
|
except ImportError as e:
|
|
raise RuntimeError(
|
|
"MiMo-V2-ASR audio encoder needs upstream flash-attn on this GPU "
|
|
"(sgl-kernel FA3 doesn't support sm_120). Install with "
|
|
"`pip install flash-attn --no-build-isolation`."
|
|
) from e
|
|
_mimo_audio_module.flash_attn_varlen_func = flash_attn_varlen_func
|
|
|
|
|
|
MiMoV2ASRConfig = Any
|
|
|
|
# Top-level audio sub-module name prefixes (after AUDIO_WEIGHT_REMAP). Loaded
|
|
# directly by default_weight_loader because the LM branch's qkv/gate-up fused
|
|
# stacked-params mapping doesn't apply to the vanilla HF Qwen2Model used
|
|
# inside the audio encoder.
|
|
_AUDIO_NAME_PREFIXES: Tuple[str, ...] = (
|
|
"projection.",
|
|
"input_local_transformer.",
|
|
"speech_embeddings.",
|
|
)
|
|
|
|
# Training-only weights present in checkpoint but not used at inference.
|
|
# Checked AFTER the audio-prefix load path so substring matching here is
|
|
# safe: legitimate audio weights (``input_local_transformer.*``) are
|
|
# already consumed by ``_AUDIO_NAME_PREFIXES`` above.
|
|
_SKIP_NAME_SUBSTRINGS: Tuple[str, ...] = (
|
|
"hidden_states_downcast",
|
|
"local_transformer",
|
|
)
|
|
|
|
|
|
class MiMoV2ASRForCausalLM(MiMoForCausalLM, AudioEncoderMixin):
|
|
def __init__(
|
|
self,
|
|
config: MiMoV2ASRConfig,
|
|
quant_config=None,
|
|
prefix: str = "",
|
|
) -> None:
|
|
_maybe_override_audio_attn_for_blackwell()
|
|
super().__init__(config, quant_config=quant_config, prefix=prefix)
|
|
self.build_audio_encoder(MiMoAudioEncoderConfig(**config.audio_config))
|
|
|
|
def pad_input_ids(self, input_ids: List[int], mm_inputs: MultimodalInputs):
|
|
pattern = MultiModalityDataPaddingPatternMultimodalTokens()
|
|
return pattern.pad_input_tokens(input_ids, mm_inputs)
|
|
|
|
def get_input_embeddings(self):
|
|
if getattr(self.config, "encoder_only", False):
|
|
return None
|
|
return self.model.embed_tokens
|
|
|
|
@torch.no_grad()
|
|
def forward(
|
|
self,
|
|
input_ids: torch.Tensor,
|
|
positions: torch.Tensor,
|
|
forward_batch: ForwardBatch,
|
|
input_embeds: torch.Tensor = None,
|
|
get_embedding: bool = False,
|
|
pp_proxy_tensors: Optional[PPProxyTensors] = None,
|
|
) -> torch.Tensor:
|
|
if getattr(self.config, "encoder_only", False):
|
|
raise NotImplementedError(
|
|
"forward() is not supported in encoder_only mode. "
|
|
"Use get_audio_feature() instead."
|
|
)
|
|
|
|
hidden_states = general_mm_embed_routine(
|
|
input_ids=input_ids,
|
|
forward_batch=forward_batch,
|
|
language_model=self.model,
|
|
multimodal_model=self,
|
|
positions=positions,
|
|
pp_proxy_tensors=pp_proxy_tensors,
|
|
)
|
|
|
|
if not get_embedding:
|
|
return self.logits_processor(
|
|
input_ids, hidden_states, self.lm_head, forward_batch
|
|
)
|
|
return self.pooler(hidden_states, forward_batch)
|
|
|
|
def load_weights(self, weights: Iterable[Tuple[str, torch.Tensor]]):
|
|
params_dict = dict(self.named_parameters())
|
|
deferred: List[Tuple[str, torch.Tensor]] = []
|
|
|
|
for name, loaded_weight in weights:
|
|
if name.startswith("audio_encoder."):
|
|
name = name[len("audio_encoder.") :]
|
|
name = self.remap_audio_weight_name(name)
|
|
|
|
if name.startswith(_AUDIO_NAME_PREFIXES):
|
|
if name not in params_dict:
|
|
logger.warning(
|
|
f"Audio param {name} not found in params_dict, skipping"
|
|
)
|
|
continue
|
|
param = params_dict[name]
|
|
weight_loader = getattr(param, "weight_loader", default_weight_loader)
|
|
if name.startswith("speech_embeddings."):
|
|
weight_loader(param, loaded_weight[: param.shape[0], :])
|
|
else:
|
|
weight_loader(param, loaded_weight)
|
|
continue
|
|
|
|
if any(s in name for s in _SKIP_NAME_SUBSTRINGS):
|
|
continue
|
|
|
|
deferred.append((name, loaded_weight))
|
|
|
|
super().load_weights(iter(deferred))
|
|
|
|
|
|
EntryClass = MiMoV2ASRForCausalLM
|