Skip to content

vllm.models.hy_v4_flash.nvidia.moe

Flash latent experts with HYV4's routing, shared experts and weight format.

Classes:

LatentUpProjection

Bases: ReplicatedLinear

Routed latent-to-hidden projection.

When bias-free and unquantized it commutes with the TP sum, so the routed and shared outputs share one all-reduce, and it takes the shared output as the GEMM's accumulate input instead of a separate add.

Source code in vllm/models/hy_v4_flash/nvidia/moe.py
class LatentUpProjection(ReplicatedLinear):
    """Routed latent-to-hidden projection.

    When bias-free and unquantized it commutes with the TP sum, so the routed
    and shared outputs share one all-reduce, and it takes the shared output as
    the GEMM's accumulate input instead of a separate add.
    """

    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)
        plain = self.bias is None and isinstance(
            self.quant_method, UnquantizedLinearMethod
        )
        self.reduce_commutative = self.accumulates_residual = plain

    def forward(
        self, x: torch.Tensor, residual: torch.Tensor | None = None
    ) -> tuple[torch.Tensor, None]:
        if residual is None:
            return super().forward(x)
        assert self.accumulates_residual
        return residual.addmm_(x, self.weight.t()), None

_defers_allreduce(config)

Whether the MLP leaves its output TP-partial for the sandwich norm to reduce in a fused all-reduce + RMSNorm.

Source code in vllm/models/hy_v4_flash/nvidia/moe.py
def _defers_allreduce(config: HYV4FlashConfig) -> bool:
    """Whether the MLP leaves its output TP-partial for the sandwich norm to
    reduce in a fused all-reduce + RMSNorm."""
    parallel_config = get_current_vllm_config().parallel_config
    return bool(
        config.sandwich_norm
        and not parallel_config.enable_expert_parallel
        and not parallel_config.use_sequence_parallel_moe
    )