Skip to content

metal : optimize Gated DeltaNet prefill with 8-lane SIMD subgroups - #33645

Open
semenishinDmitry wants to merge 1 commit into
ggml-org:masterfrom
semenishinDmitry:contrib/metal-gdn-eight-lane
Open

semenishinDmitry wants to merge 1 commit into
ggml-org:masterfrom
semenishinDmitry:contrib/metal-gdn-eight-lane

Conversation

@semenishinDmitry

Copy link
Copy Markdown

Overview

Add an eight-lane SIMD specialization for FP32 Metal Gated DeltaNet prefill. Each 32-lane SIMD group processes four independent state rows, reducing GPU time on Apple M5.

Additional information

The specialization handles 128-wide state rows with a scalar gate, one sequence, one state snapshot, and no replay. It requires aligned vector accesses, a 32-lane pipeline, and a physical GDN sequence length of at least 128 tokens. Other inputs use the existing Metal kernel.

oMLX documents the eight-lane mapping. Issue #30287 describes a related four-lane GGML implementation on M5 Max. oMLX kernel · #30287

Benchmarks and validation

Compared with upstream 59b716523f1ba73be12a9f0f51eb4c072b7fa523 on Apple M5. Ranges show the median speedup in each of two paired sessions.

Physical GDN tokens GPU speedup Wall-clock speedup
128 1.68–1.69× 1.50–1.52×
512 1.43–1.47× 1.33–1.37×
4096 3.16–3.39× 3.06–3.30×

On Qwen3.5-0.8B Q4_K_M with a 2,048-token prompt and microbatch size 512, median TTFT went from 455.6 to 421.1 ms. llama-bench prefill throughput improved by 3.6% and 12.1% in the two sessions. All 30 paired greedy continuations matched. Decode throughput varied across sessions.

The candidate passed 101/101 Metal GDN tests against the CPU reference. Pipeline logs confirmed the eight-lane kernel ran in the fused GDN+CPY case at 129 tokens. Perplexity over 5,100 evaluated tokens was 8.1056 ± 0.32792 on upstream and 8.1056 ± 0.32791 on the candidate.

Debug and Release CTest each passed 24/24. Unfiltered backend CI aborted on a Metal Flash Attention assertion for a 257-entry K/V row list, reproduced on both clean upstream and the candidate. With the two affected fixtures excluded, Metal passed 21,638/21,638 backend cases.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES. Codex assisted with adapting the Metal specialization, reviewing the patch, writing validation and benchmark tools, running measurements, and drafting this description.

Written with Codex

@semenishinDmitry
semenishinDmitry requested review from a team and ggerganov as code owners December 3, 2026 22:49
@github-actions github-actions Bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning Apple Metal https://en.wikipedia.org/wiki/Metal_(API) labels Dec 3, 2026

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

Apple Metal https://en.wikipedia.org/wiki/Metal_(API) ggml changes relating to the ggml tensor library for machine learning testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant