Skip to content

Improve pre-M5 metal memory usage for SDPA D512 - #4518

Open
dhiltgen wants to merge 2 commits into
ml-explore:mainfrom
dhiltgen:sdpa-prenax-d512
Open

dhiltgen wants to merge 2 commits into
ml-explore:mainfrom
dhiltgen:sdpa-prenax-d512

Conversation

@dhiltgen

Copy link
Copy Markdown
Contributor

This helps improve the memory usage of D512 attention on M4 and older GPUs with models such as gemma4.

Testing with mlx-community/gemma-4-31b-it-nvfp4 and mlx-community/gemma-4-12B-it-nvfp4 via mlx_lm.benchmark g128

System Model Prompt Build Prompt tps Generation tps Peak memory
M4 Pro, 64 GB Gemma 4 12B 16K main 246.530 29.410 9.736 GB
M4 Pro, 64 GB Gemma 4 12B 16K this branch 246.767 29.418 9.032 GB
M3 Ultra, 512 GB Gemma 4 31B 16K main 326.389 26.949 23.952 GB
M3 Ultra, 512 GB Gemma 4 31B 16K this branch 327.970 26.930 22.531 GB
M3 Ultra, 512 GB Gemma 4 12B 65K main 664.250 53.256 13.919 GB
M3 Ultra, 512 GB Gemma 4 12B 65K this branch 710.878 53.681 10.290 GB
  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: co-developed with a coding agent

@zcbenz
zcbenz marked this pull request as ready for review September 24, 2026 00:36
@dhiltgen
dhiltgen force-pushed the sdpa-prenax-d512 branch 2 times, most recently from e524899 to 34d92e0 Compare September 25, 2026 15:53
Comment thread python/tests/test_fast_sdpa.py Outdated
test_grad(loss_slow, loss_fast, [q, k, v])

@unittest.skipIf(not mx.metal.is_available(), "Metal kernel path only")
def test_sdpa_d512_default_metal(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you merge the test to test_sdpa_full_head_dim_256?

This branch has not been deployed

No deployments
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.

2 participants