flydsl_rewrite_quantized_moe

Rewrites quantized Triton fused-MoE GEMM kernels into FlyDSL for AMD MI300X GPUs.

178|52|Updated Jul 30, 2025
One-click install
npx skills add https://github.com/AMD-AGI/GEAK --skill flydsl-rewrite-quantized-moe-amd-agi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: flydsl_rewrite_quantized_moe
Source: https://github.com/AMD-AGI/GEAK/tree/main/perf_knowledge/expert_skills/skills/flydsl_rewrite_quantized_moe
Command: npx skills add https://github.com/AMD-AGI/GEAK --skill flydsl-rewrite-quantized-moe-amd-agi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Triton-based int4 (W4A16) and fp8 blockscale quantized fused-MoE kernels on AMD MI300X (gfx942) hit a performance ceiling around 1.1x from body-level tuning because the int4 unpack loop is latency-bound at 15-20% HBM utilization, leaving large speedups unreachable without a full kernel rewrite. ## Core Features & Use Cases - Triton-to-FlyDSL kernel rewrite: Maps quantized grouped-GEMM math onto existing FlyDSL compile_* MFMA primitives (moe_gemm_2stage, moe_blockscale_2stage) instead of writing kernels from scratch, achieving 3.6-6.2x over the Triton golden. - Exact numerics handling: Folds the GPTQ zero-point (zp=8) into weights so symmetric FlyDSL int4 matches GPTQ no-zp math, with a split correction term for per-group zero-points. - Memory contract enforcement: Mandates [M, hidden] stage-2 output via in-kernel accumulate to prevent the +896 MiB transient that OOMs e2e serving despite isolated wins. - Use Case: A hot fused_moe_kernel_gptq_awq kernel in a Kimi-K2.6 vLLM deployment is identified as the bottleneck; this skill rewrites it in candidate.py as a compiled FlyDSL kernel, validates parity (cosine ~0.999994), and benchmarks same-session speedup across decode and prefill regimes. ## Quick Start Ask the agent to rewrite the hot int4 W4A16 Triton fused-MoE kernel in candidate.py into a FlyDSL kernel and validate correctness and same-session speedup on gfx942.

Frequently Asked Questions about flydsl_rewrite_quantized_moe

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I rewrite a Triton fused-MoE kernel to FlyDSL?

Edit candidate.py so make_candidate builds and compiles a FlyDSL kernel once, returning a zero-arg callable that only launches it. Map the math onto an existing compile_* primitive such as moe_gemm_2stage.compile_moe_gemm2 for int4 W4A16 rather than writing a kernel from scratch.

How to convert GPTQ int4 W4A16 weights for FlyDSL kernels?

FlyDSL int4 is symmetric w_signed*scale with w_signed in [-8,7], and GPTQ no-zp is (uint4-8)*scale, so folding the constant zp=8 into the weight makes them identical. Per-group zero-points split out as a small additive correction matmul.

Why does an isolated FlyDSL MoE win fail at e2e serving?

The isolated bench has no KV cache competing for HBM, so a large stage-2 buffer that looks free there starves the serving KV pool and OOMs. Stage-2 output must be [M, hidden] via in-kernel accumulate; the expanded [M*top_k, hidden] path caused a +896 MiB transient and e2e reject.

Does this FlyDSL rewrite work for fp8 blockscale MoE kernels?

Yes, fp8 blockscale fused-MoE maps onto moe_blockscale_2stage.compile_moe_blockscale_gemm1/2 primitives. Note that mixed_moe_gemm_2stage is mxfp4, not GPTQ, so it must not be used for W4A16 with zero-points.

When should I not use a FlyDSL kernel rewrite?

Skip it when the operator is not a quantized MoE/GEMM, when no FlyDSL primitive reconciles the math, or when Triton config and body tuning still has headroom. In those cases the skill is inert and the workflow falls back to the generic Triton path.