explaingit

robertlangdonn/mlx-metal-kernels

Analysis updated 2026-05-18

0PythonAudience · researcherComplexity · 5/5Setup · hard

TLDR

mlx-metal-kernels is a five-stage learning project writing GPU kernels for LLM inference in Metal on an Apple M3, honestly benchmarked against Apple's own expert kernels.

Mindmap

mindmap
  root((mlx-metal-kernels))
    What it does
      Learns Metal GPU kernels
      Benchmarks against Apple experts
      Five progressive rungs
    Rungs
      Fused SwiGLU
      RMSNorm reduction
      Honest timing tooling
      RMSNorm v4
      Online softmax attention
    Tech stack
      Python
      MLX
      Metal
      Apple Silicon
    Lessons
      Elementwise ops already optimized
      Reductions worth hand writing
      Tiling is the hard part
    Audience
      ML systems learners
      Apple Silicon researchers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Learn when hand-writing a GPU kernel beats a compiler's automatic fusion versus when it does not.

USE CASE 2

Study a working example of a normalization kernel that uses cross-thread reduction on Apple Silicon.

USE CASE 3

See an honest, benchmarked implementation of online softmax attention on Metal, including its performance gap.

What is it built with?

PythonMLXMetalApple Silicon

How does it compare?

robertlangdonn/mlx-metal-kernels0xallam/my-recipe0xhassaan/nn-from-scratch
Stars00
LanguagePythonPythonPython
Last pushed2022-11-22
MaintenanceDormant
Setup difficultyhardmoderatemoderate
Complexity5/52/54/5
Audienceresearchergeneraldeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · hard Time to first run · 1h+

Requires MLX and Apple Silicon hardware, each rung is run as a separate Python script.

No license information found in the README.

In plain English

mlx-metal-kernels is a personal learning project documenting an attempt to write low-level GPU kernels for running language models, from scratch, using Apple's Metal graphics technology on a 16 GB M3 Mac. It uses MLX, Apple's machine learning framework, and its metal_kernel feature to write custom code that runs directly on the GPU. The author is upfront that the kernels themselves are ordinary and not novel research, the real point of the project is the honest comparison against Apple's own expert-written kernels and the lessons learned about when hand-writing a kernel is actually worth it. The project walks through five stages, called rungs, each with its own write-up file. The first rung fuses a common neural network operation and finds it only matches the speed of MLX's built-in compiler, showing that simple elementwise operations are usually already optimized well. The second rung writes a normalization kernel that beats the built-in compiler by roughly two times, because it involves a cross-thread reduction the compiler cannot generate on its own. The third rung builds honest timing tooling so results can be fairly ranked. The fourth rung refines the normalization kernel further to match Apple's own expert kernel in speed. The fifth rung implements an attention technique called online softmax, which turns out correct but thirteen to thirty three times slower than Apple's expert version, showing that the real difficulty lies in tiling and matrix multiplication hardware use rather than the algorithm itself. Each rung can be run as a standalone Python script. The project requires MLX and Apple Silicon hardware to run, and results are measured on wall clock time rather than hardware performance counters, with no end-to-end speed impact demonstrated yet. It is aimed at developers curious about GPU kernel programming and Apple's MLX ecosystem.

Copy-paste prompts

Prompt 1
Explain why the RMSNorm kernel in this project beats mx.compile but the SwiGLU kernel does not.
Prompt 2
Walk me through running each of the five rungs in this repo on my own Apple Silicon Mac.
Prompt 3
What does the online softmax attention kernel in rung 5 do, and why is it slower than Apple's version?
Prompt 4
Summarize the decision rule this project's author learned about when to hand-write a GPU kernel.

Frequently asked questions

What is mlx-metal-kernels?

mlx-metal-kernels is a five-stage learning project writing GPU kernels for LLM inference in Metal on an Apple M3, honestly benchmarked against Apple's own expert kernels.

What language is mlx-metal-kernels written in?

Mainly Python. The stack also includes Python, MLX, Metal.

What license does mlx-metal-kernels use?

No license information found in the README.

How hard is mlx-metal-kernels to set up?

Setup difficulty is rated hard, with roughly 1h+ to a first successful run.

Who is mlx-metal-kernels for?

Mainly researcher.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.