Skip to content

perf: use native Metal matrix multiplication by default - #81

Merged
zhenghaoz merged 2 commits into
mainfrom
codex/perf-metal-native-matmul
Nov 9, 2026
Merged

zhenghaoz merged 2 commits into
mainfrom
codex/perf-metal-native-matmul

Conversation

@zhenghaoz

Copy link
Copy Markdown
Contributor

Metal inference previously rewrote eligible matrix products into matrix-vector products even with model-default activation precision, preventing ggml from selecting its faster native MM/MMA kernels.

Let ggml choose the native matrix or vector kernel by default, following llama.cpp's approach. Keep the existing vector-product fallback when explicit or model-required F32 activations must be preserved.

Validation

  • Passed test-clap-c-api-allocation, test-clap-graph-pipeline, test-clap-tensor-ops, and test-clap-tensor-ops-cpu.
  • Apple M1, Release build, larger_clap_general-q4_k_m.gguf, text query dog: a 32-file ESC-50 subset took 18.57 s → 5.84 s median over three runs per version (3.18× throughput).
  • A full search of the 2,000-file esc5 directory completed in 338.65 s. The top-ten paths and order matched the original implementation.

Precision

Native Metal matrix kernels can round operands to F16 despite F32 accumulation. The maximum observed cosine-score difference was approximately 0.000719; some close results changed order in the 32-file subset. Explicit/model-required F32 activation behavior retains the original fallback.

Full-directory timing is reported separately from the subset speedup; the original full-directory run was interrupted by measurement pauses and is not used for a full-directory speedup claim.

@zhenghaoz
zhenghaoz merged commit 4b7db8a into main Nov 9, 2026
9 checks passed
@zhenghaoz
zhenghaoz deleted the codex/perf-metal-native-matmul branch November 9, 2026 13:44
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.

1 participant