Skip to content

Enable INT8-activation prefill MoE experts for Inkling-2-Mini MLX - #855

Draft
oniisanlabs wants to merge 1 commit into
incoai:mainfrom
oniisanlabs:perf/inkling2-moe-int8-prefill
Draft

oniisanlabs wants to merge 1 commit into
incoai:mainfrom
oniisanlabs:perf/inkling2-moe-int8-prefill

Conversation

@oniisanlabs

@oniisanlabs oniisanlabs commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Enable the existing INT8-activation MoE prefill passes (moe_int8.metal) for Inkling-2-Mini's routing (sharedSlices == 0, SoftcappedSwiglu<4, 25>) on MLX af4g64 and af5g64 checkpoints on Apple10/Apple11 GPUs, bringing Inkling-2-Mini in line with every other MoE family in Splash (Qwen3.6-35B-A3B, Qwen3.5-122B, Qwen3.8-Flash-Next, and Flint).

What changed (+43 / -26 production lines across 4 files)

  • runtime/metal/kernels/common/gguf_tile.h: added EpUpWithGateSoftcap4_25 epilogue reusing SoftcappedSwiglu<4, 25> (rounding up to bfloat before activation, matching moe_gguf.metal).
  • runtime/metal/kernels/shared/moe_int8.metal: instantiated Shared = 0 (_s0) + EpUpWithGateSoftcap4_25 (_softcap4_25) kernels for af4g64 and af5g64.
  • runtime/ops/MoE.cpp: in addInt8Experts, bound weights.slotTable in the unused shared-plane slots when shape.sharedSlices == 0 (matching addExperts) and appended routing.activationSuffix to the "up" pass name.
  • runtime/ops/KernelSelection.cpp: generalized moeInt8Experts to all kCompiledMoeRoutings and skipped the shared-segment format check when routing->sharedSlices == 0.
  • Tests & benchmark:
    • Removed the activationSuffix skip in gguf_moe_test.mm so gguf-moe-biased exercises af4g64 and af5g64 INT8 passes against the FP64 reference and bitwise across chunk sizes (263/33/16/1).
    • Updated int8ExpertRoutings in kernel_selection_test.cc and the 14 Apple10/11 Inkling-2-Mini moe-prefill/moe-workspace hashes in kernel_selection_golden.txt.
    • Added the inkling2 shape to dev/benchmarks/gguf_moe_benchmark.mm and fixed int8 mode overriding M64 back to M32 when forcing int8Passes = true.

GPU Benchmarks (20-core Apple M5 Pro, macOS 26.6.2, hardware gpuSeconds)

1. Per-layer MoE (gguf-moe-benchmark int8 inkling2, 15 rounds ABAB)

Even against the 64-row BF16 staged tile (M64) at 1,024 and 2,048 rows:

Format Rows Routes/expert Baseline Tile Staged BF16 ms/layer INT8 ms/layer Ratio Speedup
af4g64 96 6 M32 2.3966 2.3781 0.992 -0.8%
af4g64 128 8 M32 2.5161 2.5048 0.996 -0.4%
af4g64 160 10 M32 2.5972 2.5538 0.983 -1.7%
af4g64 192 12 M32 2.6948 2.6940 1.000 0.0%
af4g64 256 16 M32 3.0565 2.9099 0.952 -4.8%
af4g64 384 24 M32 3.5199 3.2054 0.911 -8.9%
af4g64 512 32 M32 4.0468 3.5478 0.877 -12.3%
af4g64 768 48 M32 5.3428 4.4207 0.827 -17.3%
af4g64 1024 64 M64 6.7106 5.3972 0.804 -19.6% (1.24×)
af4g64 2048 128 M64 12.2746 9.1491 0.745 -25.5% (1.34×)
af5g64 512 32 M32 4.5852 4.3211 0.942 -5.8%
af5g64 768 48 M32 6.2987 5.3619 0.851 -14.9%
af5g64 1024 64 M64 7.4757 6.2658 0.838 -16.2% (1.19×)
af5g64 2048 128 M64 13.8011 11.0220 0.799 -20.1% (1.25×)

2. Full-shape 48-application Inkling-2-Mini MLX (af4g64, 4 ABBA pairs)

Note: No real mlx-community/Inkling-2-Mini-4bit checkpoint is installed locally, so this drives the production PrefillArena, DecodeArena, QwenTarget, and build/splash.metallib with full-shape synthetic af4g64 weight pools (4 unique expert pools ≈ 2.4 GB > 50× SLC), with Int8Activations::On on both main and this branch (so both use INT8 dense attention projections; only the MoE experts differ). A real-checkpoint teacher-logits KL and decode-profile ABBA check during review is welcome.

Workload main med PR med Paired med Δ Speedup PR faster
prefill-256 178.51 ms 163.05 ms -7.49% 1.08× 4 / 4
prefill-512 313.36 ms 263.85 ms -15.81% 1.19× 4 / 4
prefill-1024 591.99 ms 481.10 ms -18.28% 1.22× 4 / 4
prefill-2048 1165.81 ms 948.45 ms -18.64% 1.23× 4 / 4
decode-b1-1 20.10 ms 19.45 ms -2.24% 1.02× 4 / 4
decode-b1-8 36.75 ms 36.21 ms -0.95% 1.01× 3 / 4

Trade-offs & Scope

  • Memory: Adds +45.36 MiB to PrefillArena (381.35 → 428.92 MiB) for resident MLX 4-bit/5-bit Inkling-2-Mini on Apple10/11 (same as Qwen3.6-35B-A3B's +45 MiB in Splash 1.7.1). Zero memory change for GGUF, Apple9, streamed experts, or decode.
  • Numerics: Same per-64-element INT8 activation quantization on prefill chunks ≥ 96 rows already used by Qwen3.6-35B-A3B / Qwen3.5-122B / Flint (--activations bf16 preserves exact BF16). Decode and chunks < 96 rows remain unchanged. In gguf-moe-biased, worst relative error vs FP64 is 1.7e-3 (gate/up) and 8.2e-3 (down) for af4g64, and 1.8e-3 / 7.1e-3 for af5g64, with 50/50 rows bitwise identical across 263/33/16/1-row chunks.

Testing

  • python3 dev/tools/check_architecture.py — PASS
  • make test-engine-cpu — PASS (including kernel-selection over all 5,145 groups and model-execution-plans)
  • kernel-selection --library build/splash.metallib — PASS (all 1,624 pipelines across 5,653,188 plans present in build/splash.metallib)
  • MTL_SHADER_VALIDATION=1 Metal suites:
    • gguf-moe-biased — PASS (exercises new af4g64 and af5g64 _s0 + _softcap4_25 INT8 passes)
    • gguf-moe — PASS
    • gguf-moe-sigmoid — PASS
    • inkling2-target (shader-validated + bitwise) — PASS

See it in action
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Compile the int8 MoE expert prefill passes for Inkling-2-Mini's routing
(0 shared slices, SoftcappedSwiglu<4, 25>) in af4g64 and af5g64 so
resident MLX 4-bit/5-bit Inkling-2-Mini checkpoints use Apple10/11 int8
MoE prefill like every other MoE family:

- runtime/metal/kernels/common/gguf_tile.h: add EpUpWithGateSoftcap4_25
  epilogue using SoftcappedSwiglu<4, 25>.
- runtime/metal/kernels/shared/moe_int8.metal: instantiate _s0 and
  _softcap4_25 kernels for af4g64 and af5g64.
- runtime/ops/MoE.cpp: in addInt8Experts, bind slotTable in unused
  shared-plane slots when sharedSlices == 0 and append activationSuffix
  on the up pass.
- runtime/ops/KernelSelection.cpp: allow all kCompiledMoeRoutings in
  moeInt8Experts and skip the shared-segment check when sharedSlices == 0.
- Enable int8 MoE tests for Inkling-2-Mini's routing in gguf_moe_test.mm
  and kernel_selection_test.cc, update the 14 Apple10/11 Inkling-2-Mini
  entries in kernel_selection_golden.txt, and add inkling2 support to
  gguf_moe_benchmark.mm.

Measured on 20-core Apple M5 Pro (macOS 26.6.2):
- gguf-moe-benchmark int8 inkling2 (15 rounds ABAB):
  - af4g64: -12.3% at 512 rows, -19.6% (1.24x vs M64) at 1024 rows,
    -25.5% (1.34x vs M64, 12.27 -> 9.15 ms/layer) at 2048 rows.
  - af5g64: -16.2% (1.19x vs M64) at 1024 rows, -20.1% (1.25x vs M64)
    at 2048 rows.
- Full-shape synthetic 48-app Inkling-2-Mini af4g64 prefill (4 ABBA pairs):
  - 256 rows: -7.5% (1.08x), 512: -15.8% (1.19x), 1024: -18.3% (1.22x),
    2048: -18.6% (1.23x, 1165.8 -> 948.5 ms).
@oniisanlabs

Copy link
Copy Markdown
Contributor Author

Converting to draft after testing against a real downloaded mlx-community/Inkling-2-Mini-4bit checkpoint (and checking mlx-community/Inkling-2-Mini-oQ4e-mtp metadata):

  • Both checkpoints keep the release's native NVFP4 routed experts in layers 0–19 (44 of 48 applications) and MXFP8 (or af4g64 in oQ4e) in layers 20–23; only the attention projections/head are af4g64.
  • As a result, af4g64/af5g64-only all-or-nothing moeInt8Experts does not activate on mlx-community/Inkling-2-Mini-4bit (it only helps full-affine af4g64/af5g64-expert conversions).
  • (Side note: dev/tools/kernel_identity.py confirmed all 2,309 existing kernels in splash.metallib remain AIR-identical, with only the 6 new _s0 kernels added.)

I'll explore extending INT8 MoE prefill to NVFP4 (plus per-block selection so layers 0–19 run INT8 while MXFP8 layers 20–23 stay on staged BF16), which would accelerate real mlx-community/Inkling-2-Mini-4bit, oQ4e, thinkingmachines/Inkling-2-Mini, and NVFP4 Qwen checkpoints, and update or replace this PR once verified on the real checkpoint.

@oniisanlabs
oniisanlabs marked this pull request as draft November 26, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant