Fit FP32 wide-head attention tiles within Metal shared memory - #17
Draft
Gajesh2007 wants to merge 1 commit into
Draft
Fit FP32 wide-head attention tiles within Metal shared memory#17Gajesh2007 wants to merge 1 commit into
Gajesh2007 wants to merge 1 commit into
Conversation
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.
Summary
Forced full attention with FP32 head dimensions 192 or 256 can exceed Metal's 32 KiB threadgroup-memory limit. On M4 Max, the D256
bq32/bk16/wm4specialization requires 53,760 bytes and fails to load.Use
bq16/wm2, withbk16for D192 andbk8for D256. The padded shared arrays require 27,904 and 28,928 bytes respectively. Computation stays FP32; existing default-routing heuristics and other dtypes are unchanged.Before
After
flowchart LR A[Forced FP32 full attention] --> B{Head dimension} B -->|192| C[bq16 bk16 wm2] B -->|256| D[bq16 bk8 wm2] B -->|other| E[Existing tile] C --> F[Fused attention result] D --> F E --> FValidation
Apple M4 Max, Swift 6.3, using the new C/Swift explicit-fused binding: five tests passed, covering default-route compatibility, pitched BOOL masks and sinks against a dense reference for D64/D192/D256, wide-head GQA8, unsupported D512 refusal, and an allocation check below 16 MiB where a composed score tensor alone would occupy 32 MiB.
The companion packed-KV integration also passed 40 tests, including exact Qwen and GPT-OSS attention geometries. Performance qualification is in progress in Layr-Labs/d-inference#860; this patch fixes kernel eligibility and does not claim a throughput improvement.