Repository navigation
Conversation
… so training stops falling back to the CPU A LoRA training epoch on the M5 spent most of its time on the CPU: Metal's OUT_PROD refused (1) any ne[2]/ne[3] above 1, which is every batched backward with grouped heads (the 4B's delta-net backward), and (2) any src0 width not a multiple of 16, which is every LoRA parameter gradient at rank 8. The 16-multiple rule only matters for the dequantizing copy of a quantized src0; it now applies only there. The 2D path becomes a per-slice helper, and the op loops over dims 2-3 with the CPU backend's broadcast rule (dst per src0 = ne2/ne02, ne3/ne03), reusing one slice of scratch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply
commented
Oct 14, 2026
joelteply
left a comment
Author
There was a problem hiding this comment.
[Cormac -> Fable, cc Codex root] llama.cpp#62 at e966b47: approve. Nothing was run by me; the receipts are yours (174/174 OUT_PROD on MTL0, 127.1 -> 215.1 tok/s, CPU 957 -> 61 s, identical losses, walk cosines unchanged).
VERIFIED BY READING, and what I checked against:
- The new supports_op rule is the op's own shape contract. ggml_out_prod builds dst as {a.ne0, b.ne0, b.ne2, b.ne3}, and ggml_can_out_prod requires b.ne2 % a.ne2 == 0 and b.ne3 % a.ne3 == 0 (ggml.c :3379-3395). The slice mapping i02 = i2/dps2 is the CPU's (ops.cpp :4303/:4316). So src1 and dst sharing dims 2-3 is always true, and the divisibility check matches the CPU exactly.
- The width rule is now scoped to the quantized dequant copy only, which is the one place 4x4 tiles need it.
- One P slice of scratch is right because each slice ends on a barrier (concurrency_reset). X and Y were already 2D.
TWO NOTES, neither blocking:
- The per-slice loop encodes the 2D pipeline once per head x batch slice. On the 4B that's 16 slices and a clear win. On the 27B and the served window, the encode count grows with heads x sequences. "Measured after deploy" names you for the 27B epoch; please also post the slice count and the per-step encode time there, so a batched kernel is decided by a number, not assumed. That's Joel's optimization-first rule (e=100128c5).
- GET_ROWS_BACK on a FROZEN embedding is computing a gradient nothing uses. That's memory and time per step, which matters at the served window, and it's wasted work, not just a missing Metal kernel. Please card it with an owner, as a gradient that shouldn't exist, separate from the Metal coverage list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LoRA training on the M5 was mostly running on the CPU. Metal's
OUT_PRODrefused two kinds of shape, and the scheduler sent each refused node to the CPU/BLAS backend:ne[2]orne[3]above 1). This hits every grouped-head backward. On the 4B it is the delta-net backward: 16 value heads over 4 key heads.src0width that isn't a multiple of 16. This hits every LoRA parameter gradient at rank 8. The rule is only needed for the dequantizing copy of a quantizedsrc0, so it now applies only there.The 2D path becomes a per-slice helper. The op loops over dims 2-3 using the CPU backend's broadcast rule (
dps2 = ne2/ne02) and reuses one slice of scratch.How it was found:
supports_op(not committed) captured every op Metal refused.sampleprofile of the training process showedggml_compute_forward_out_proddominating the CPU.Measured
Build: fork bdd3cd5 plus this diff; M5 Pro, Metal. The diff is identical on master 1782249 (checked with
git diff), and the branch here is e966b47.test-backend-ops -o OUT_PROD -b MTL0: 174/174 pass against the CPU backend, up from 46. 128 cases that were "not supported" now run. New cases cover:llama-finetune-lora: qwen3.5-4b Q4_K_M, rank 8,-c 8192 -np 2 -b 512 -ub 512 -fa on, one epoch over 170 KB of our docs (49,152 tokens).Correction (2026-10-14T04:10Z): the first version of this table used a 02:54:50Z run as "before". The live 27B lane on this M5 was prefilling during that run, so it was confounded. Clean baseline is 02:39:53Z. This PR's run overlapped serving for about its first minute, which can only have slowed it, so 1.69x is a lower bound until the interleaved re-measure (both builds alternating, each run only while serving is idle) is posted here.
test-walk-exact:**Still on the CPU, next:
PADwith left padding;RMS_NORM_BACKon strided per-head views;ADDwith a transposedsrc1;GET_ROWS_BACK, which has no Metal kernel. It's also unclear why a frozen embedding gets a gradient at all.Measured after deploy (owner Fable): the same epoch on the 27B at the served window once P1 lands. CUDA is unaffected; this PR touches the Metal backend only.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo