Improving matrix multiplication speed on Apple Silicon chips
Strassen-Winograd Matrix Multiplies and Apple Silicon: Two Fast Things That Go Fast Together
Distributed, Parallel, and Cluster ComputingMachine Learning
Summary
Matrix multiplication takes up most of the computing time when running local large language models on Apple Silicon chips. The authors found that using a special method called Strassen-Winograd multiplication can speed up these calculations by doing fewer total operations but using more memory. They combined this method with other tricks specific to language models to reduce the delay before the first output token appears by about 5.5% to 20%, depending on model size and precision. Their approach also fixes common numerical errors and keeps the quality of the results intact.
What this means in practice
- •For machine learning engineers: Speed up local large language model inference on Apple M1 to M4 chips by integrating optimized Strassen-Winograd multiplication with existing GEMM libraries.
- •For hardware acceleration developers: Use sub-cubic matrix multiplication methods in unified-memory systems to improve compute efficiency despite increased memory traffic.
Authors
David G. Andersen
Abstract
Matrix multiplication accounts for 84--94% of prompt-processing (prefill) runtime in local large language model (LLM) serving on Apple Silicon. Unified-memory Apple M1--M4 systems are designed with a relatively balanced compute/memory bandwidth ratio that makes using Strassen-Winograd-style sub-cubic matrix multiplication algorithms worthwhile: These algorithms reduce total computation at the expense of extra memory traffic. DropKS is a lightweight wrapper around system GEMM libraries that speeds large (roughly 2,048 x 2,048 and larger) matrix multiplies. It combines an optimized Strassen-Winograd implementation with LLM-specific folding of dequantization into adjacent operators, and corrects an important source of numerical error to which SW algorithms are vulnerable at low precision by selectively peeling rows with large values (<bos> peeling). End to end in mlx-lm, DropKS reduces time-to-first token, or TTFT, in Llama-3 by 5.5--12.3%. On 4-bit and 8-bit quantized 8B (Llama-3) and 27B (Qwen 3.8) models, the combination of techniques it provides reduces TTFT by 8.5--20% while preserving corpus perplexity and token agreement.