[Metal:Perf] Fused-Q4 M8 tile and K-split for speculative-block decode - #4772
Merged
Conversation
The fused Q4 GEMM stage kernel uses an M32 matmul2d tile. A speculative
block is 8 rows, so it runs at quarter occupancy, and for projections
with few output tiles it also dispatches too few threadgroups to
saturate bandwidth.
Add two variants behind FUSED_Q4_REAL_UNPACK:
- conv1x1_fused_q4_gemm_stage_m8: descriptor sized to M=8.
- conv1x1_fused_q4_gemm_stage_ksplit{,_m8} + _ksplit_reduce: split K
four ways across gid.z into fp32 partials, then sum + bias +
activation in a second pass.
Both are gated on KVMeta::spec_block so nothing outside speculative
decoding changes path.
New switches, all default to auto (unset):
MNN_METAL_FUSED_Q4_KSPLIT =1 force on, =0 force off
MNN_METAL_FUSED_Q4_M8 =0 force off (=1 same as unset, the tile is
MNN_METAL_FUSED_Q4_KSPLIT_M8 only correct for area <= 8)
K-split reassociates the K accumulation, so output is not
bit-identical: on an iPad tier-9 sweep 8 of 9 prompts match the
baseline verbatim and one diverges on a near-tie greedy argmax.
The area-gate part of this work already landed with the fused-Q4
spec-block gate.
Discussed-in: Merge-Request 29266048 , URL: https://code.alibaba-inc.com/AliNN/AliNNPrivate/codereview/29266048
GitOrigin-RevId: c465bb4195f3722161c2338440b301f43e052b01
|
|
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.
Automated sync from the internal MNN development repository.
sync/ali-to-githubCommits
456032377d[Metal:Perf] Fused-Q4 M8 tile and K-split for speculative-block decode — 花熊 zhanghuaxiang.zhx@taobao.com