[ROCm][Perf] Add opt-in a4w4 (FP4 activation) MoE for DeepSeek V4.1 on AITER (#58819)
Signed-off-by: fai <fangzhouai@gmail.com> Signed-off-by: Fangzhou Ai <31551580+Fangzhou-Ai@users.noreply.github.com> Co-authored-by: Cursor Agent (Claude Sonnet 5) <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor Agent
parent
e5f3d08d72
commit
77e8b02c8d
@@ -345,6 +345,7 @@ def _rocm_aiter_fused_moe_impl(
|
||||
shared_w1_scale: torch.Tensor | None = None,
|
||||
shared_w2_scale: torch.Tensor | None = None,
|
||||
shared_expert_id: int = -1,
|
||||
q_dtype_a: torch.dtype | None = None,
|
||||
) -> torch.Tensor:
|
||||
has_shared_expert = _validate_rocm_aiter_fused_moe_shared_expert_args(
|
||||
shared_w1,
|
||||
@@ -378,6 +379,12 @@ def _rocm_aiter_fused_moe_impl(
|
||||
shared_w2_scale=shared_w2_scale,
|
||||
shared_expert_id=shared_expert_id,
|
||||
)
|
||||
if q_dtype_a is not None:
|
||||
# DeepSeek V4.1 a4w4 override (use_mxfp4_w4a4_dsv4 in
|
||||
# rocm_aiter_moe.py). rocm_aiter_ops.fused_moe_supports_quant_dtype_a()
|
||||
# is checked at config time, so this is only reached on an AITER
|
||||
# build new enough to accept it.
|
||||
extra_kwargs["quant_dtype_a"] = q_dtype_a
|
||||
|
||||
return fused_moe(
|
||||
hidden_states,
|
||||
@@ -435,6 +442,7 @@ def _rocm_aiter_fused_moe_fake(
|
||||
shared_w1_scale: torch.Tensor | None = None,
|
||||
shared_w2_scale: torch.Tensor | None = None,
|
||||
shared_expert_id: int = -1,
|
||||
q_dtype_a: torch.dtype | None = None,
|
||||
) -> torch.Tensor:
|
||||
if output_dtype is not None:
|
||||
return torch.empty_like(hidden_states, dtype=output_dtype)
|
||||
@@ -2485,6 +2493,21 @@ class rocm_aiter_ops:
|
||||
|
||||
return "gate_mode" in inspect.signature(fused_moe).parameters
|
||||
|
||||
@classmethod
|
||||
@if_aiter_supported
|
||||
@functools.cache
|
||||
def fused_moe_supports_quant_dtype_a(cls) -> bool:
|
||||
"""Probe whether the installed aiter.fused_moe accepts `quant_dtype_a`.
|
||||
|
||||
Added in https://github.com/ROCm/aiter/pull/5439 (unreleased at
|
||||
merge time). Older AITER can't override the activation quant dtype.
|
||||
"""
|
||||
import inspect
|
||||
|
||||
from aiter.fused_moe import fused_moe
|
||||
|
||||
return "quant_dtype_a" in inspect.signature(fused_moe).parameters
|
||||
|
||||
@staticmethod
|
||||
def _probe_dsv4_i384_fhmoe_capability(num_tokens: int) -> bool:
|
||||
"""Probe AITER's CSV-backed DSV4 native-I384 FHMoE contract."""
|
||||
@@ -3005,6 +3028,7 @@ class rocm_aiter_ops:
|
||||
shared_w1_scale: torch.Tensor | None = None,
|
||||
shared_w2_scale: torch.Tensor | None = None,
|
||||
shared_expert_id: int = -1,
|
||||
q_dtype_a: torch.dtype | None = None,
|
||||
) -> torch.Tensor:
|
||||
return torch.ops.vllm.rocm_aiter_fused_moe(
|
||||
hidden_states,
|
||||
@@ -3036,6 +3060,7 @@ class rocm_aiter_ops:
|
||||
shared_w1_scale,
|
||||
shared_w2_scale,
|
||||
shared_expert_id,
|
||||
q_dtype_a,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user