vllm.models.deepseek_v41.amd.akr_moe
¶
DeepSeek-V4.1 MoE block on amd_kernels: routes router, draft_router and
shared_expert.
router / draft_router: gate GEMM, sqrt-softplus, correction bias, top-k,
renormalize and routed scaling in one entry, for the target layers (384
experts, top 6) and the DSpark draft layers (128 experts, top 3).
shared_expert: the shared expert's gate_up and clamped SiLU-mul as MXFP8
for the mhc_ffn epilogue (shared down + routed add + FFN post-mix);
SHARED_PLAN picks per static row count which gate_up runs. Standalone
the stock chain on the FFN seam's MXFP8 copy wins at every row count, so
the route declines there. The stock linears' preshuffled weights are read
as they are; only their scales get a copy (about 0.5 MB per layer).
While any of these routes is on, a MegaMoE layer runs its shared expert after the routed experts on the same stream: beside MegaMoE's persistent, spin-waiting stage-1 kernel the overlapped gate_up GEMM stalled both for 1.3-13.7 ms per occurrence on DEP8 decode.
Classes:
-
Router–DeepseekV4MoE.akr: the router route of one MoE layer (gateNone when -
SharedExpert–DeepseekV4MLP.akr: the shared-expert route of one MoE layer. The down
Functions:
-
forward_parts–The routed output and the shared expert's MXFP8 activation, for a caller
-
shared_takes_codes–Whether the shared expert reads the FFN seam's MXFP8 codes at
mrows. -
wants_x_quant–Whether the FFN seam should also emit MXFP8 codes for
moeatmrows:
Router
¶
DeepseekV4MoE.akr: the router route of one MoE layer (gate None when
the layer's router is not eligible: only the serial shared expert).
Methods:
-
route–fp32 top-k weights and int32 expert ids, or None for the stock router.
Source code in vllm/models/deepseek_v41/amd/akr_moe.py
route(moe, x)
¶
fp32 top-k weights and int32 expert ids, or None for the stock router.
Source code in vllm/models/deepseek_v41/amd/akr_moe.py
SharedExpert
¶
DeepseekV4MLP.akr: the shared-expert route of one MoE layer. The down
projection stays the stock linear, on the MXFP8 activation.
Methods:
-
activation–gate_up and the clamped SiLU-mul as MXFP8, or None for the stock
-
chain–activationand the stock down projection (the unfused form of the -
forward–None: standalone, the stock chain on the seam's MXFP8 copy wins or
Source code in vllm/models/deepseek_v41/amd/akr_moe.py
activation(mlp, x, x_quant)
¶
gate_up and the clamped SiLU-mul as MXFP8, or None for the stock chain.
Source code in vllm/models/deepseek_v41/amd/akr_moe.py
chain(mlp, x, x_quant)
¶
activation and the stock down projection (the unfused form of the
mhc_ffn epilogue's input; tests and warm-up).
Source code in vllm/models/deepseek_v41/amd/akr_moe.py
forward(mlp, x, x_quant)
¶
None: standalone, the stock chain on the seam's MXFP8 copy wins or ties (within 0.2 us) at every row count from 16 to 768 on MI355X (dev1133), by up to 3.7 us.
Source code in vllm/models/deepseek_v41/amd/akr_moe.py
_stock_takes_codes(mlp)
¶
Whether the stock shared expert's gate_up reads an attached MXFP8 copy.
Source code in vllm/models/deepseek_v41/amd/akr_moe.py
forward_parts(moe, x, input_ids, x_quant)
¶
The routed output and the shared expert's MXFP8 activation, for a caller that runs the shared down projection in its own epilogue. None, having done nothing, where the shared-expert route does not serve.
Source code in vllm/models/deepseek_v41/amd/akr_moe.py
shared_takes_codes(m)
¶
Whether the shared expert reads the FFN seam's MXFP8 codes at m rows.
Source code in vllm/models/deepseek_v41/amd/akr_moe.py
wants_x_quant(moe, m)
¶
Whether the FFN seam should also emit MXFP8 codes for moe at m rows:
the fused EP8 experts read them, and so does the shared expert where its
gate_up runs on codes (the route's plan, or the stock linear where the
route does not serve).