[Qwen4Exp] support Sequence Parallelism for Qwen3.8-Flash-Next (#56322)
Signed-off-by: huanghaoyan.hhy <huanghaoyan.hhy@alibaba-inc.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
258b97ff6b
commit
c75cb63cd2
@@ -3,6 +3,7 @@
|
||||
|
||||
from .interfaces import (
|
||||
HasInnerState,
|
||||
SupportsHCSP,
|
||||
SupportsLoRA,
|
||||
SupportsMRoPE,
|
||||
SupportsMultiModal,
|
||||
@@ -10,6 +11,7 @@ from .interfaces import (
|
||||
SupportsPP,
|
||||
SupportsTranscription,
|
||||
has_inner_state,
|
||||
supports_hc_sp,
|
||||
supports_lora,
|
||||
supports_mrope,
|
||||
supports_multimodal,
|
||||
@@ -33,6 +35,8 @@ __all__ = [
|
||||
"is_text_generation_model",
|
||||
"HasInnerState",
|
||||
"has_inner_state",
|
||||
"SupportsHCSP",
|
||||
"supports_hc_sp",
|
||||
"SupportsLoRA",
|
||||
"supports_lora",
|
||||
"SupportsMultiModal",
|
||||
|
||||
@@ -912,11 +912,21 @@ class Qwen4ExpForConditionalGenerationConfig(Qwen3_5ForConditionalGenerationConf
|
||||
|
||||
@staticmethod
|
||||
def verify_and_update_config(vllm_config: "VllmConfig") -> None:
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
Qwen3_5ForConditionalGenerationConfig.verify_and_update_config(vllm_config)
|
||||
text_config = vllm_config.model_config.hf_text_config
|
||||
if text_config.hc_count <= 1:
|
||||
raise ValueError("Qwen4Exp requires hc_count > 1")
|
||||
parallel_config = vllm_config.parallel_config
|
||||
# MoE SP also enables HC SP without the explicit HC flag.
|
||||
if (
|
||||
current_platform.is_cuda()
|
||||
and parallel_config.use_sequence_parallel_moe
|
||||
and parallel_config.pipeline_parallel_size != 1
|
||||
):
|
||||
raise ValueError("Qwen4Exp MoE SP requires PP=1")
|
||||
|
||||
uses_ple_or_qsa = bool(text_config.ple_layer_ids) or (
|
||||
getattr(text_config, "indexer_n_heads", None) is not None
|
||||
)
|
||||
|
||||
@@ -858,6 +858,27 @@ def _supports_pp_inspect(model: type[object] | object) -> bool:
|
||||
return supports_kw(model_forward, "intermediate_tensors")
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class SupportsHCSP(Protocol):
|
||||
"""Support sequence-parallel HC without changing MoE parallelism."""
|
||||
|
||||
supports_hc_sp: ClassVar[Literal[True]] = True
|
||||
|
||||
|
||||
@overload
|
||||
def supports_hc_sp(model: type[object]) -> TypeIs[type[SupportsHCSP]]: ...
|
||||
|
||||
|
||||
@overload
|
||||
def supports_hc_sp(model: object) -> TypeIs[SupportsHCSP]: ...
|
||||
|
||||
|
||||
def supports_hc_sp(
|
||||
model: type[object] | object,
|
||||
) -> TypeIs[type[SupportsHCSP]] | TypeIs[SupportsHCSP]:
|
||||
return getattr(model, "supports_hc_sp", False)
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class HasInnerState(Protocol):
|
||||
"""The interface required for all models that has inner state."""
|
||||
|
||||
@@ -129,7 +129,12 @@ def _should_replicate_misaligned_shared_expert(
|
||||
|
||||
|
||||
class Qwen3NextSparseMoeBlock(nn.Module):
|
||||
def __init__(self, vllm_config: VllmConfig, prefix: str = ""):
|
||||
def __init__(
|
||||
self,
|
||||
vllm_config: VllmConfig,
|
||||
prefix: str = "",
|
||||
reduce_results: bool = True,
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
config = vllm_config.model_config.hf_text_config
|
||||
@@ -231,6 +236,7 @@ class Qwen3NextSparseMoeBlock(nn.Module):
|
||||
num_redundant_experts=self.n_redundant_experts,
|
||||
is_sequence_parallel=self.is_sequence_parallel,
|
||||
n_shared_experts=1 if self.shared_expert is None else None,
|
||||
reduce_results=reduce_results,
|
||||
fuse_shared_experts=self.is_fused_shared_expert_enabled,
|
||||
shared_expert_prefix=f"{prefix}.shared_expert",
|
||||
shared_expert_gate=self.shared_expert_gate
|
||||
|
||||
@@ -49,6 +49,7 @@ from .interfaces import (
|
||||
is_attention_free,
|
||||
is_hybrid,
|
||||
requires_raw_input_tokens,
|
||||
supports_hc_sp,
|
||||
supports_mamba_prefix_caching,
|
||||
supports_multimodal,
|
||||
supports_multimodal_encoder_tp_data,
|
||||
@@ -873,6 +874,7 @@ class _ModelInfo:
|
||||
requires_raw_input_tokens: bool
|
||||
supports_multimodal_encoder_tp_data: bool
|
||||
supports_pp: bool
|
||||
supports_hc_sp: bool
|
||||
has_inner_state: bool
|
||||
is_attention_free: bool
|
||||
is_hybrid: bool
|
||||
@@ -903,6 +905,7 @@ class _ModelInfo:
|
||||
model
|
||||
),
|
||||
supports_pp=supports_pp(model),
|
||||
supports_hc_sp=supports_hc_sp(model),
|
||||
has_inner_state=has_inner_state(model),
|
||||
is_attention_free=is_attention_free(model),
|
||||
is_hybrid=is_hybrid(model),
|
||||
@@ -1463,6 +1466,15 @@ class _ModelRegistry:
|
||||
model_info, _ = self.inspect_model_cls(architectures, model_config)
|
||||
return model_info.supports_pp
|
||||
|
||||
def is_hc_sp_supported_model(
|
||||
self,
|
||||
architectures: str | list[str],
|
||||
model_config: ModelConfig,
|
||||
) -> bool:
|
||||
"""Check support for HC SP without changing MoE parallelism."""
|
||||
model_info, _ = self.inspect_model_cls(architectures, model_config)
|
||||
return model_info.supports_hc_sp
|
||||
|
||||
def model_has_inner_state(
|
||||
self,
|
||||
architectures: str | list[str],
|
||||
|
||||
Reference in New Issue
Block a user