Skip to content
Open
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6daf388
MoE: correct + faster a16w4 (bf16 A x MXFP4 W) SiTUv2 kernel
coderfeli Aug 1, 2026
64d30fa
MoE: remove aiter's broken a16w4 kernel; port fully replaces it
coderfeli Aug 1, 2026
06bc8a1
MoE a16w4: consolidate package (5->3 files), CSV gemm2 tiles, route o…
coderfeli Aug 1, 2026
650012a
MoE a16w4: make tile config CSV-driven; reroute the FlyDSL a16wfp4 test
coderfeli Aug 1, 2026
eb60c9a
[a16w4] True drop-in: native layouts, route via compile_flydsl_moe_st…
coderfeli Aug 1, 2026
3e51910
MoE a16wmix: trim redundant comments (code byte-identical)
coderfeli Aug 2, 2026
5c48fdb
MoE a16w4: condense fused_moe intercept comments (code-token identical)
coderfeli Aug 2, 2026
19b8a94
MoE a16w4: drop launcher host-syncs + redundant zeros in run_flydsl_a…
coderfeli Aug 2, 2026
b948217
MoE a16wmix: make a16wmix_use_k16 a pure fn of arch; drop FORCE_K16 env
coderfeli Aug 2, 2026
c79a936
MoE a16wmix: split tile-config resolution into csv_dispatch.py
coderfeli Aug 2, 2026
222edb0
MoE a16wmix: move SiLU/SiTUv2 activation helpers into act.py
coderfeli Aug 2, 2026
1ce093e
MoE a16wmix: unify local _raw onto tensor_shim._to_raw
coderfeli Aug 2, 2026
e80b4e8
MoE a16wmix: pass use_k16 into the kernel builders (no get_rocm_arch …
coderfeli Aug 2, 2026
aa7c98d
MoE a16wmix: drop dead use_csv_config path + _kwave_from_kbatch
coderfeli Aug 2, 2026
0027b08
MoE a16w4: fold into the standard 2-stage path; drop bespoke run_flyd…
coderfeli Aug 2, 2026
a42c7af
MoE a16w4: restore inter_sorted pad-zeroing; trim fold comments; fold…
coderfeli Aug 2, 2026
19d1fb6
MoE a16wmix: drop redundant gemm2 CSV resolver; move act.py to shared…
coderfeli Aug 2, 2026
29885de
MoE a16wmix: strip tile_heuristic to mxfp4-only (drop dead int4/bf16 …
coderfeli Aug 2, 2026
d079eb4
MoE a16wmix: use native fx .bitcast(fx.Float32) for scale bit-reinter…
coderfeli Aug 2, 2026
eac2a7c
MoE a16wmix: flatten _get_compiled to the builder directly; drop dead…
coderfeli Aug 2, 2026
67ff316
MoE a16w4: make gemm1 fully CSV/registry-driven; delete the tile heur…
coderfeli Aug 2, 2026
dc6f39e
MoE a16w4: fix CI style (black/ruff), align mxfp4->fp4, trim comments
coderfeli Aug 2, 2026
f0cab37
MoE a16wmix: simplify shared ptr helpers
coderfeli Aug 2, 2026
f285ab7
MoE a16w4: retune small-M gemm1 tiles (close the tok1 launch-overhead…
coderfeli Aug 2, 2026
3fed5e8
MoE a16w4 AOT: fix "produced no kernel" for the folded port
coderfeli Aug 2, 2026
1643f3e
MoE a16w4 AOT: shrink _precompile_a16w4_to_cache (~90 LOC removed)
coderfeli Aug 2, 2026
e2cb38a
MoE a16w4 AOT: ruff C408 (dict() -> literal) in _precompile_a16w4_to_…
coderfeli Aug 2, 2026
05bd519
MoE a16w4: runtime SiTUv2 beta + no-clamp; fix k3 non-default beta
coderfeli Aug 3, 2026
64d956b
Merge remote-tracking branch 'origin/main' into a16w4-beta-fix
coderfeli Aug 3, 2026
a86818f
Merge remote-tracking branch 'origin/main' into a16w4-beta-fix
coderfeli Aug 3, 2026
657a2d1
Merge branch 'main' into flydsl-a16w4-mxfp-moe
coderfeli Aug 4, 2026
7015312
MoE a16w4: fix SiTUv2 accuracy — clamp at runtime swiglu_limit (match…
coderfeli Aug 4, 2026
0325b80
Merge remote-tracking branch 'origin/main' into a16w4-beta-fix
coderfeli Aug 4, 2026
e98a8a1
Merge branch 'main' into flydsl-a16w4-mxfp-moe
coderfeli Aug 5, 2026
91e2009
MoE a16w4: align to main's GGUU layout + FlyDSL tuner support + retune
coderfeli Aug 6, 2026
51eac0e
MoE a16w4 tuner: consolidate stage2 candidate guards (no-op refactor)
coderfeli Aug 6, 2026
3186fc5
Merge branch 'main' into flydsl-a16w4-mxfp-moe
coderfeli Aug 7, 2026
aee40c3
MoE a16w4 tuner: kernel-only timing (fix inflated us) + retune
coderfeli Aug 7, 2026
390e40c
MoE a16w-mix: extract shared helpers to utils.py + modernize ptr/wait…
coderfeli Aug 7, 2026
1697cea
Fix Black formatting in gemm_moe_tune.py
coderfeli Aug 8, 2026
e2fb8da
a16w4: guard num_acc_n>=1, skip throwaway stage1 out buffer, test bet…
coderfeli Aug 8, 2026
d33da17
a16w-mix: inline trivial helpers, drop _get_compiled wrappers, ir->fx…
coderfeli Aug 8, 2026
dc288cc
Merge branch 'main' into flydsl-a16w4-mxfp-moe
coderfeli Aug 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 141 additions & 26 deletions aiter/aot/flydsl/moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def _make_a_user(a_dtype_user_shape):
sorted_token_ids, sorted_expert_ids, num_valid_ids = _make_routing()

if stage == 1:
if b_dtype in ("fp4", "mxfp4") and a_dtype in ("bf16", "fp8"):
if b_dtype == "fp4" and a_dtype in ("bf16", "fp8"):
tile_n = resolve_flydsl_stage1_tile_n(inter_dim, tile_n)

a = _make_a_user(_user_a_shape())
Expand Down Expand Up @@ -582,9 +582,7 @@ def _make_a_user(a_dtype_user_shape):
),
stream=0,
swiglu_limit=runtime_swiglu_limit(None, act),
pass_swiglu_limit=not (
a_dtype == "bf16" and b_dtype in ("fp4", "mxfp4")
),
pass_swiglu_limit=not (a_dtype == "bf16" and b_dtype == "fp4"),
)
else:
args = _s1_args_std(
Expand Down Expand Up @@ -842,6 +840,102 @@ def _make_a_user(a_dtype_user_shape):
)


def _precompile_a16w4_to_cache(
*,
stage: int,
model_dim: int,
inter_dim: int,
experts: int,
topk: int,
tile_m: int,
tile_n: int,
tile_k: int,
act: str = "silu",
b_nt: int = 2,
xcd_swizzle: int = 0,
k_wave: int = 1,
**kwargs,
):
"""AOT for the folded a16w4 (bf16 A x fp4 W) port (moe_2stage_a16wmix).

The port launch ABI (raw fx.Int64 device pointers) differs from the generic MX
gemm (``_s1_args_fp4``), so it can't reuse ``_precompile_to_cache``'s arg
builders. Instead drive the SAME runtime launchers (``flydsl_a16w4_gemm{1,2}``)
the fused-MoE op uses, under ``COMPILE_ONLY=1`` — the cache key then matches
runtime by construction (``waves_per_eu=None``, ``persist=False``,
``w_layout="standard"``, g2 tile downgrade are all applied inside the
launcher). The compiled artifact is keyed only on the kernel's constexpr
params (shapes/tiles/topk/act), never on the launch pointers, grid, or
``n_tokens``, so a single 1-elem real placeholder covers every buffer (real,
not fake, because the launcher calls ``.data_ptr()``; COMPILE_ONLY guarantees
it is never dereferenced).
"""
import torch

from aiter.ops.flydsl.kernels.moe_2stage_a16wmix import (
flydsl_a16w4_gemm1,
flydsl_a16w4_gemm2,
)

z = torch.zeros(1, dtype=torch.int32, device="cpu")
common = {
"sorted_expert_ids": z,
"cumsum_tensor": z,
"NE": experts,
"D_HIDDEN": model_dim,
"D_INTER": inter_dim,
"topk": topk,
"tile_m": tile_m,
"b_nt": b_nt,
"xcd_swizzle": xcd_swizzle,
"waves_per_eu": None,
"stream": 0,
}
with compile_only_env():
if stage == 1:
flydsl_a16w4_gemm1(
a_bf16=z,
w1_u8=z,
w1_scale_u8=z,
m_indices=z,
inter_sorted_bf16=z,
n_tokens=1,
tile_n=tile_n,
tile_k=tile_k,
k_wave=k_wave,
act=("situv2" if act in ("situv2", "situ") else act),
w_layout="standard",
**common,
)
else:
# Mirror the runtime stage2 g2 tile downgrade (moe_kernels
# _flydsl_moe_stage2_impl a16w4 branch).
g2_tile_n = (
tile_n
if model_dim % tile_n == 0
else (256 if model_dim % 256 == 0 else 128)
)
g2_tile_k = (
tile_k
if inter_dim % tile_k == 0
else (128 if inter_dim % 128 == 0 else 64)
)
flydsl_a16w4_gemm2(
inter_sorted_bf16=z,
w2_u8=z,
w2_scale_u8=z,
sorted_token_ids=z,
sorted_weights=z,
flat_out=z,
M_logical=1,
max_sorted=1,
tile_n=g2_tile_n,
tile_k=g2_tile_k,
w_dtype="fp4",
**common,
)


def _precompile_epilogue_to_cache(act: str, inter_dim: int, topk: int):
"""Precompile the CK-Tile split-K post-activation epilogue kernel.

Expand Down Expand Up @@ -941,37 +1035,58 @@ def compile_one_config(

from torch._subclasses.fake_tensor import FakeTensorMode

# The folded a16w4 (bf16 A x fp4 W) port takes raw .data_ptr() device
# pointers, which FakeTensors don't have; drive its dedicated precompile with
# real (COMPILE_ONLY) tensors outside FakeTensorMode.
is_a16w4 = (
not is_epilogue
and kwargs.get("shared_expert_id", -1) < 0
and kwargs.get("a_dtype") == "bf16"
and kwargs.get("b_dtype") == "fp4"
)

t0 = time.time()
try:
with (
override_env("FLYDSL_GPU_ARCH", aot_arch),
FakeTensorMode(),
):
if is_epilogue:
_precompile_epilogue_to_cache(
act=kwargs.get("act", "silu"),
inter_dim=inter_dim,
topk=topk,
)
else:
shared_expert_id = kwargs.pop("shared_expert_id", -1)
if shared_expert_id >= 0:
from aiter.aot.flydsl.fhmoe import (
precompile_fhmoe_to_cache,
)

precompile = precompile_fhmoe_to_cache
kwargs["shared_expert_id"] = shared_expert_id
else:
precompile = _precompile_to_cache
precompile(
if is_a16w4:
with override_env("FLYDSL_GPU_ARCH", aot_arch):
_precompile_a16w4_to_cache(
model_dim=model_dim,
inter_dim=inter_dim,
experts=experts,
topk=topk,
cu_num=cu_num,
**kwargs,
)
else:
with (
override_env("FLYDSL_GPU_ARCH", aot_arch),
FakeTensorMode(),
):
if is_epilogue:
_precompile_epilogue_to_cache(
act=kwargs.get("act", "silu"),
inter_dim=inter_dim,
topk=topk,
)
else:
shared_expert_id = kwargs.pop("shared_expert_id", -1)
if shared_expert_id >= 0:
from aiter.aot.flydsl.fhmoe import (
precompile_fhmoe_to_cache,
)

precompile = precompile_fhmoe_to_cache
kwargs["shared_expert_id"] = shared_expert_id
else:
precompile = _precompile_to_cache
precompile(
model_dim=model_dim,
inter_dim=inter_dim,
experts=experts,
topk=topk,
cu_num=cu_num,
**kwargs,
)
elapsed = time.time() - t0
result["compile_time"] = elapsed
print(f" [OK] compile {elapsed:6.1f}s {shape_str} arch={aot_arch}")
Expand Down
Loading
Loading