Skip to content
KernelIndex
Search⌘K

submission 569308

egghao · python · License unknown

Use it

Vendorable · source mirrored · license unknownView source →

No package. Vendor the mirrored source: 76 lines, June 9 Researcher Reciprocity License v1.0.

solution.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-amd-moe-mxfp4-569308?include=source"
interfacepython
Compatibility
measured onAMD Instinct MI355X
declared hardwareAMD Instinct MI355X
architecturesgfx950
dtypesbf16, fp32, fp8_e8m0, int32, mxfp4

Benchmark evidence

1 measurement across 1 GPU, fastest first.

Operation / workload
Hardware
Latency
Rank
Observed
AMD MXFP4 MoEsuite of 7 cases
AMD Instinct MI355X
186.8µs
#713 of 782
2026-03-16

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:02e11c5b618741790e059b1976cf6ac28cc6ee317abfe4ab6fc4054887195dfc
license declaredunknown
license concludedunknown
authorsegghao
imported2026-08-26

Techniques

Extracted from the mirrored source by pattern, never inferred. Each row cites its line.

fp4DeepSeek-R1 style MXFP4 Mixture-of-Experts — AMD MI355X submission.

Kernel source

solution.py76 lines
"""
DeepSeek-R1 style MXFP4 Mixture-of-Experts — AMD MI355X submission.

Fused MoE kernel: MXFP4 quant activations → two-stage GEMM + SwiGLU → weighted reduce.

Input tuple:
  hidden_states:                [M, d_hidden]                           bf16
  gate_up_weight:               [E, 2*d_expert_pad, d_hidden_pad//2]    fp4x2  (raw)
  down_weight:                  [E, d_hidden_pad, d_expert_pad//2]      fp4x2  (raw)
  gate_up_weight_scale:         [E, 2*d_expert_pad, d_hidden_pad//32]   e8m0   (raw)
  down_weight_scale:            [E, d_hidden_pad, d_expert_pad//32]     e8m0   (raw)
  gate_up_weight_shuffled:      [E, 2*d_expert_pad, d_hidden_pad//2]    fp4x2  (pre-shuffled)
  down_weight_shuffled:         [E, d_hidden_pad, d_expert_pad//2]      fp4x2  (pre-shuffled)
  gate_up_weight_scale_shuffled:[padded, flat]                          e8m0   (pre-shuffled)
  down_weight_scale_shuffled:   [padded, flat]                          e8m0   (pre-shuffled)
  topk_weights:                 [M, total_top_k]                        float32
  topk_ids:                     [M, total_top_k]                        int32
  config:                       dict

Output: [M, d_hidden] bfloat16
"""

import torch
from aiter import ActivationType, QuantType
from aiter.fused_moe import fused_moe


def custom_kernel(data):
    """
    MXFP4 fused MoE using aiter.fused_moe.

    Strategy:
      - Use pre-shuffled gate_up and down weights (CK (16,16) tile layout).
      - Use pre-shuffled scales (e8m0_shuffle applied at input generation time).
      - aiter.fused_moe internally quantises activations to MXFP4 (per_1x32)
        and runs the two-stage CK pipeline: gate_up GEMM+SwiGLU → down GEMM.
      - Shared experts are already encoded in topk_ids / topk_weights by the caller.
    """
    (
        hidden_states,
        gate_up_weight,
        down_weight,
        gate_up_weight_scale,
        down_weight_scale,
        gate_up_weight_shuffled,
        down_weight_shuffled,
        gate_up_weight_scale_shuffled,
        down_weight_scale_shuffled,
        topk_weights,
        topk_ids,
        config,
    ) = data

    hidden_pad = config["d_hidden_pad"] - config["d_hidden"]
    intermediate_pad = config["d_expert_pad"] - config["d_expert"]

    output = fused_moe(
        hidden_states,
        gate_up_weight_shuffled,
        down_weight_shuffled,
        topk_weights,
        topk_ids,
        expert_mask=None,
        activation=ActivationType.Silu,
        quant_type=QuantType.per_1x32,
        doweight_stage1=False,
        w1_scale=gate_up_weight_scale_shuffled,
        w2_scale=down_weight_scale_shuffled,
        a1_scale=None,
        a2_scale=None,
        hidden_pad=hidden_pad,
        intermediate_pad=intermediate_pad,
    )

    return output
scrolls · 76 lines total

Source code from GPU Mode and the KernelBot dataset · June 9 Researcher Reciprocity License v1.0

Best evidence level for this revision: reported

JSON