[perf]: dispatch wide-M affine H3 MLX linears through dequant plus dense GEMM - #1788
Conversation
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🤖 CI
🔴 PR merge requirementsWaiting for
This rule is failing.
|
|
This PR has merge conflicts with the base branch. Please rebase: git fetch origin main
git rebase origin/main
# Resolve any conflicts, then:
git push --force-with-lease |
SolitaryThinker
left a comment
There was a problem hiding this comment.
Request changes — reviewed exact head 77ef31081919e908c4eb274c8036d30dad1c7f4a and replayed its unique commit onto current main (a4d9a75e2, merged #1776).
[P1] Scope the default dequant+dense dispatch to H3, or validate every shared consumer — fastvideo/mlx_runtime/fastwan.py:326-366
affine_dq_gemm_min_m() defaults on and _quantized_linear() is called by the shared linear() helper. That helper is used throughout both FastWan and wan22.py, so this H3-calibrated threshold silently changes every affine-quantized Wan linear with at least 768 leading rows as well. The supplied crossover evidence covers one H3 Q shape on an M4 Max; it does not cover Wan K/N shapes, its memory profile, or end-to-end numerical parity, and the committed microtest itself permits nonzero drift. This can regress performance/memory or alter existing Wan generation by default. Please gate this from the H3 path, keep the shared default off, or provide production-shape Wan performance plus end-to-end parity evidence before enabling it globally.
[P1] Add the new parity suite to the MLX CI commands — fastvideo/tests/mlx/test_mlx_affine_dq_gemm.py:1
Both jobs in current .github/workflows/ci-macos-mlx.yml invoke an explicit list of MLX test files, and neither list includes this new file. The generic Linux fastcheck path skips it at pytest.importorskip("mlx.core"), so no required CI lane executes the only dispatch/parity coverage for this default-on numerical path. This PR does not satisfy the add-model component parity gate until the file is added to both the macOS/Metal and Linux-CPU MLX test lists and produces a non-skip pass.
[P2] Evaluate the disabled-path result — fastvideo/tests/mlx/test_mlx_affine_dq_gemm.py:116-117
MLX is lazy, but this test discards linear(x, quantized) and then evaluates only the already-materialized input x. The qmm result graph therefore never executes, so a runtime failure in the advertised FASTVIDEO_MLX_DQ_GEMM=0 fallback still passes. Keep the result, call mx.eval(got), and compare it with _qmm as the below-threshold test does.
Stack/CI note: the PR still has merge conflicts and is parented on 1559dfd, before the blocker fixes merged with #1776; it needs a rebase onto current main. The fastcheck unit lane is red, but its private Buildkite log is unavailable through the supported triage path, so I am not attributing that failure without evidence.
Reviewed lanes: shared component dispatch, numerical parity/CI coverage, conversion impact, and final evidence. I could not run MLX locally on this Linux host; the author-reported Apple runs were considered, but the required CI integration is still absent.
MLX quantized_matmul is slower than dequantize plus steel GEMM at H3's packed token width. Keep stored INT6 weights and use a measured M=768 floor without caching dequantized matrices.
77ef310 to
78c7c90
Compare
|
Addressed the requested changes on head
@SolitaryThinker, this is ready for re-review. |
Summary
mx.dequantizeplus dense BF16 GEMM when the measured crossover applies. Stored INT4/INT6/INT8 weights stay quantized, and dequantized matrices are not cached.mx.quantized_matmul. The H3 path opts into this dispatch explicitly.M >= 768. SetFASTVIDEO_MLX_DQ_GEMM=0to disable the H3 dispatch or provide an integer to override the floor.Measured gates
Existing A/B measurements on an Apple M4 Max with 36 GiB unified memory, MLX 0.31.2, INT6, 832x480x124, four steps, seed 2026, tiled VAE, dense attention, and no temporal fast mode:
quantized_matmul, which is why the default floor remains 768.Validation
63 passedon MLX 0.31.2: affine dispatch, H3 parity, VSA, and fast-mode suites.63 passedon MLX 0.32.2: the same focused suites.quantized_matmulexactly.quantized_matmulat wide M.test_mlx_affine_dq_gemm.py.