Skip to content

perf: tune DFlash2 M=8 verification for M1 and M2 - #7

Open
aunali1 wants to merge 4 commits into
jundot:mainfrom
aunali1:codex/dflash2-m1-cycle-overhead
Open

perf: tune DFlash2 M=8 verification for M1 and M2#7
aunali1 wants to merge 4 commits into
jundot:mainfrom
aunali1:codex/dflash2-m1-cycle-overhead

Conversation

@aunali1

@aunali1 aunali1 commented Aug 20, 2026

Copy link
Copy Markdown

What

  • Promote DFlash2 W4A16 drafts to W4A32 on Apple GPUs where bfloat16 is emulated.
  • Add shape-specialized scalar M=8 verification kernels for Apple GPU G13/G14.
  • Add profiled FP16-matrix/FP32-accumulation kernels for W4A32 DFlash2 draft projections.
  • Reuse the M=8 path for the seven-row draft vocabulary projection through zero padding.
  • Prewarm only the selected activation path.
  • Keep stock MLX QMM as the fallback on other GPU generations, dtypes, bit widths, and unsupported shapes.
  • Add parity, numeric-contract, fingerprint, runtime-policy tests, and a reproducible microbenchmark.

Why

DFlash2 uses an eight-token block, but M1/M2 previously fell through to stock MLX QMM for M=8 verification. FP16 DFlash2 draft activations also produced non-finite logits on the tested M1 Max, while bfloat16 is emulated through FP32 on this GPU generation.

The runtime now selects W4A32 for DFlash2 on affected GPUs and uses kernels profiled for its fixed projection shapes.

Performance

Hardware: M1 Max, applegpu_g13s.

Invocation:

PYTHONPATH=$PWD python -m tools.benchmarks.verify_m8_microbench \
  --k 5120 --n 17408 --dtype bfloat16 \
  --warmup 20 --iterations 100

Results for K=5120, N=17408:

  • production M=8: 0.6331875 ms
  • stock M=8: 1.647833 ms
  • production M=4: 0.4984165 ms
  • M=8 versus M=4 verified-row throughput: 1.574309x

For K=5120, N=1024, M=8 versus M=4 verified-row throughput is 1.811133x.

M=8 still has greater single-launch latency than M=4, but verifies twice as many rows and therefore has higher row throughput.

Validation

  • Modified-path tests: 128 passed, 7 skipped
  • Full suite: 1360 passed, 18 skipped
  • M=8 parity, contract, deterministic fingerprint, and finite-output cases pass
  • Python compilation, fatal Ruff checks, and git diff --check pass
  • Downstream oMLX DFlash engine tests: 115 passed

The full suite has one existing M=16 gate/up numeric-bound failure on applegpu_g13s: observed deviation 0.0078125 versus the pinned 0.001 bound. It is unchanged by this M=8 work.

A separate exact-partial-tail greedy mismatch also reproduces with the custom verifier disabled. This draft does not claim to resolve that pre-existing issue.

Add scalar K-major, narrow-output, and FP16-matrix kernels selected for Apple GPU G13/G14 projection shapes.

Keep stock MLX QMM fallbacks for unsupported devices and shapes, and cover the new paths with parity, numeric-contract, and deterministic fingerprint tests.
Teach VerifyQuantizedLinear to dispatch BF16 and FP16 target verification through the tuned M=8 kernels.

Add the W4A32 draft and vocabulary projection path, including seven-row zero padding, scoped fallbacks, and selected-kernel prewarming.
Resolve W4A16 DFlash2 drafts to W4A32 on affected Apple GPUs so draft logits remain finite.

Report the effective quantization and activation dtype, prewarm the matching projection path, and install the target vocabulary wrapper during runtime bundle construction.
Add a focused harness that compares production M=8 verification with production M=4 and stock MLX QMM, including a single-variant mode for Metal tracing.
@aunali1
aunali1 force-pushed the codex/dflash2-m1-cycle-overhead branch from 90fcffe to ab995ea Compare August 20, 2026 16:31
@aunali1
aunali1 marked this pull request as ready for review August 20, 2026 16:34
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