Update llama.cpp metal backend
Categories
(Core :: Machine Learning: On Device, defect)
Tracking
()
People
(Reporter: padenot, Assigned: padenot)
Details
Attachments
(6 external files)
Comment 1•2 months ago
|
||
When filing bugs on this component, please add a bug description here, as it's hard for maintainers to know what's going on with cryptic bugs filed like this. For instance, why are you needing to update it. Is there a specific backend you are targeting? Is there some kind of mismatch going on? Does this affect speech recognition? We actively triage and this is marked as a defect that will show up in our triage. This looks like a "task" rather a "defect".
| Assignee | ||
Comment 2•2 months ago
|
||
The Metal files were taken from an older llama.cpp than the revision moz.yaml
pins, which is why they had to be in "keep" rather than revendored.
This vendors the backend at 74ade527 instead, matching llama.cpp. At that rev,
it is split into a few files. The embedding of the shader source is unchanged: the
.metal file still has the embed_ggml-common.h and ggml-metal-impl.h
placeholders generate_metal_embed.py substitutes. etc.
ggml-metal-device.m and ggml-metal-device.cpp would compile to the same object
name, so run_parser.py renames the former to ggml-metal-device-m.m, like it
already does for ggml.c and ggml-cpu.c.
Two patches are needed on top: <memory> for std::unique_ptr in ggml-metal.cpp,
and a guard around -[MTLSharedEvent waitUntilSignaledValue:timeoutMS:], which
is macOS 12 while we deploy to 10.15 (11.0 on aarch64).
mach vendor --patch-mode check now reproduces the tree.
| Assignee | ||
Comment 3•2 months ago
|
||
ggml_metal_library_get_pipeline_mul_mv asks for a _short kernel variant when
ne00 < 32. On the macOS 15 machines the Metal compiler does not emit those
specializations from the vendored shader source, so the lookup fails with
MTLLibraryErrorDomain Code=5 "Function kernel_mul_mv_f32_f32_short was not
found in the library"
get_pipeline_mul_mv returns a null pipeline and the caller encodes it without
checking.
llama.cpp doesn't use this path, parakeet.cpp does, we can simply use the general
kernel, which lives in the same source, it is emitted everywhere, and handles any size.
| Assignee | ||
Comment 4•2 months ago
|
||
Editing ggml-metal.metal did not change the built binary, very confusing.
| Assignee | ||
Comment 5•2 months ago
|
||
I mistakenly attached the patches to bug 2051973, this should have been clear from the start, sorry I just found out and fixed it.
https://hg.mozilla.org/mozilla-central/rev/f771b516e40f
https://hg.mozilla.org/mozilla-central/rev/d9f68a527c41
https://hg.mozilla.org/mozilla-central/rev/52cdfd8dd5f4
| Assignee | ||
Comment 8•2 months ago
|
||
The Metal files were taken from an older llama.cpp than the revision moz.yaml
pins, which is why they had to be in "keep" rather than revendored.
This vendors the backend at 74ade527 instead, matching llama.cpp. At that rev,
it is split into a few files. The embedding of the shader source is unchanged: the
.metal file still has the embed_ggml-common.h and ggml-metal-impl.h
placeholders generate_metal_embed.py substitutes. etc.
ggml-metal-device.m and ggml-metal-device.cpp would compile to the same object
name, so run_parser.py renames the former to ggml-metal-device-m.m, like it
already does for ggml.c and ggml-cpu.c.
Two patches are needed on top: <memory> for std::unique_ptr in ggml-metal.cpp,
and a guard around -[MTLSharedEvent waitUntilSignaledValue:timeoutMS:], which
is macOS 12 while we deploy to 10.15 (11.0 on aarch64).
mach vendor --patch-mode check now reproduces the tree.
Original Revision: https://phabricator.services.mozilla.com/D322929
Updated•2 months ago
|
| Assignee | ||
Comment 9•2 months ago
|
||
ggml_metal_library_get_pipeline_mul_mv asks for a _short kernel variant when
ne00 < 32. On the macOS 15 machines the Metal compiler does not emit those
specializations from the vendored shader source, so the lookup fails with
MTLLibraryErrorDomain Code=5 "Function kernel_mul_mv_f32_f32_short was not
found in the library"
get_pipeline_mul_mv returns a null pipeline and the caller encodes it without
checking.
llama.cpp doesn't use this path, parakeet.cpp does, we can simply use the general
kernel, which lives in the same source, it is emitted everywhere, and handles any size.
Original Revision: https://phabricator.services.mozilla.com/D324025
Updated•2 months ago
|
| Assignee | ||
Comment 10•2 months ago
|
||
Editing ggml-metal.metal did not change the built binary, very confusing.
Original Revision: https://phabricator.services.mozilla.com/D324026
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Comment 11•2 months ago
|
||
| uplift | ||
Description
•