perf: tune DFlash2 M=8 verification for M1 and M2 - #7
Open
aunali1 wants to merge 4 commits into
Open
Conversation
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
force-pushed
the
codex/dflash2-m1-cycle-overhead
branch
from
August 20, 2026 16:31
90fcffe to
ab995ea
Compare
aunali1
marked this pull request as ready for review
August 20, 2026 16:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
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 100Results for K=5120, N=17408:
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
git diff --checkpassThe 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.