Repository navigation
metal: MUL_MAT_ID_BACK kernel, so a MoE LoRA's backward runs on the GPU (stacked on #82; continuum card 14b64aa9) - #83
Merged
joelteply merged 1 commit intoOct 31, 2026
Conversation
joelteply
changed the base branch from
cormac/mul-mat-id-backward
to
889580fc/seq-state-across-stream-counts
October 31, 2026 22:48
…PU (stacked on #82; continuum card 14b64aa9) #82 adds GGML_OP_MUL_MAT_ID_BACK with a CPU kernel; on Metal the scheduler would run that one op on the CPU inside a GPU graph. This is the Metal kernel. - kernels/out_prod.metal: kernel_mul_mat_id_back, in kernel_out_prod's template shape <T0, block_q, nl, dequantize_func>. One threadgroup per routed slot (i, t); each thread owns columns of that slot's row and walks the expert's rows, so every dst element has one writer and no expert is copied or transposed in device memory. nl == 0 reads F32/F16/BF16 element by element; nl > 0 dequantizes 16 consecutive elements of a row in registers (ne00 % 16 == 0). Instantiated for f32, f16, bf16 (GGML_METAL_HAS_BF16), q4_0, q4_1, q5_0, q5_1, q8_0 and q2_K-q6_K: out_prod's set. - ggml-metal-ops.cpp: - ggml_metal_op_mul_mat_id_back dispatches (n_used, n_tokens) threadgroups; - ggml_metal_op_mul_mat_id_back_supported refuses the pointer-table gather (src[3]); - out_prod's weight-type switch is now one predicate, ggml_metal_frozen_weight_readable, shared by both training kernels. - ggml-metal-device.*: - the pipeline getter (kernel_mul_mat_id_back_<type>); - supports_op, with bf16 requiring has_bfloat. Not run here: enrico's Metal driver is wedged, and the Metal toolchain could not be installed to compile-check the shader. The C++ side compiles (clang -fsyntax-only on ggml-metal-ops.cpp). Proof is on the M5: - `test-backend-ops test -o MUL_MAT_ID_BACK -b Metal` against CPU, for every expert type in test_mul_mat_id_back; - `test-backend-ops grad -o MUL_MAT_ID -b Metal`. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply
force-pushed
the
0a3a5106/metal-mul-mat-id-back-kernel-so-a-moe-lo
branch
from
October 31, 2026 22:48
a7b1ab7 to
a726c39
Compare
Author
|
PASS at a726c39 (Fable). Verified on the M5 (Apple M5 Max, Metal, serving down), built from this head: |
joelteply
merged commit Oct 31, 2026
6606d1a
into
889580fc/seq-state-across-stream-counts
18 of 33 checks passed
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.
#82 adds GGML_OP_MUL_MAT_ID_BACK with a CPU kernel; on Metal the scheduler would run that one
op on the CPU inside a GPU graph. This is the Metal kernel.
<T0, block_q, nl, dequantize_func>. One threadgroup per routed slot (i, t); each thread owns
columns of that slot's row and walks the expert's rows, so every dst element has one writer
and no expert is copied or transposed in device memory. nl == 0 reads F32/F16/BF16 element by
element; nl > 0 dequantizes 16 consecutive elements of a row in registers (ne00 % 16 == 0).
Instantiated for f32, f16, bf16 (GGML_METAL_HAS_BF16), q4_0, q4_1, q5_0, q5_1, q8_0 and
q2_K-q6_K: out_prod's set.
shared by both training kernels.
Not run here: enrico's Metal driver is wedged, and the Metal toolchain could not be installed
to compile-check the shader. The C++ side compiles (clang -fsyntax-only on ggml-metal-ops.cpp).
Proof is on the M5:
test-backend-ops test -o MUL_MAT_ID_BACK -b Metalagainst CPU, for every expert type intest_mul_mat_id_back;
test-backend-ops grad -o MUL_MAT_ID -b Metal.Co-Authored-By: Claude Opus 5.5 (1M context) noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE