Vendor an enable the Metal GGML backend
Categories
(Core :: Machine Learning: On Device, enhancement, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox157 | --- | fixed |
People
(Reporter: padenot, Assigned: padenot)
References
(Blocks 1 open bug)
Details
Attachments
(2 external files, 3 obsolete files)
This will provide hardware acceleration on macOS with Metal. Another choice is CoreML.
| Assignee | ||
Comment 1•4 months ago
|
||
This includes the Metal shader source in asm and compiles it. Specific
symbols are then picked up by the implementation, and the byte range is
fed to the Metal shader compiler. The resulting object file is
subsequently cached by the OS.
First compilation is in the order of 4-5s, subsequent instantiation is
10-15ms.
This backend will always ever run in a dedicated process, that has a
sandbox very similar to the GPU process, but doesn't have access to the
display server, fonts, and other facilities related to rendering. It can
access one more folder than the GPU process (read/write) to cache the
compiled shaders.
This benefits llama.cpp, but also whisper.cpp, that is introduced in a
later patch. This can multiply the performance by multiple dozen times
(depending on the hardware and use-case). More importantly, it
completely offload inference to the GPU. While (e.g.) real-time local
speech recognition is running with this backend, about:processes
show all thread of the HWInference process as "idle".
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Comment 2•4 months ago
|
||
The severity field is not set for this bug.
:gregtatum, could you have a look please?
For more information, please visit BugBot documentation.
Updated•4 months ago
|
| Assignee | ||
Comment 3•3 months ago
|
||
The Metal libggml backend can register a GPU device that then fails during real
backend init (e.g. CI VMs or older Intel Macs, where the device exists but the
command queue / shader library can't be created). Because the vendored library
is built without exceptions, a failure inside llama_context would abort instead
of falling back. Probe the GPU backend once and force CPU offload off when it is
unusable.
Updated•3 months ago
|
| Assignee | ||
Comment 5•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.
Updated•2 months ago
|
Comment 6•2 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/d6582396cb89
https://hg.mozilla.org/mozilla-central/rev/a8d279045916
Comment 9•2 months ago
|
||
Reverted this because it was causing @ ggml_metal_encoder_set_pipeline related mochitests failures.
- Revert link
- Push with failures
- Failure Log
- Failure line: PROCESS-CRASH | ADB9796F-FF88-4AC1-969E-E2C78DF0900A | application crashed [@ ggml_metal_encoder_set_pipeline] | dom/media/webspeech/recognition/test/test_concurrent_session.html
| Assignee | ||
Updated•2 months ago
|
| Assignee | ||
Comment 10•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 11•2 months ago
|
||
Editing ggml-metal.metal did not change the built binary, very confusing.
Updated•2 months ago
|
Comment 12•2 months ago
|
||
A patch has been attached on this bug, which was already closed. Filing a separate bug will ensure better tracking. If this was not by mistake and further action is needed, please alert the appropriate party. (Or: if the patch doesn't change behavior -- e.g. landing a test case, or fixing a typo -- then feel free to disregard this message)
Comment 13•2 months ago
|
||
Comment on attachment 9635353 [details]
Bug 2051973 - Vendor the Metal backend at the pinned llama.cpp revision. r?#ai-platform-reviewers
Revision D322929 was moved to bug 2068580. Setting attachment 9635353 [details] to obsolete.
Comment 14•2 months ago
|
||
Comment on attachment 9637486 [details]
Bug 2051973 - Fall back to the general mat-vec kernel when Metal lacks the _short one. r?#valentinp
Revision D324025 was moved to bug 2068580. Setting attachment 9637486 [details] to obsolete.
Comment 15•2 months ago
|
||
Comment on attachment 9637487 [details]
Bug 2051973 - Reassemble the embedded Metal shader when it changes. r?valentinp
Revision D324026 was moved to bug 2068580. Setting attachment 9637487 [details] to obsolete.
Updated•2 months ago
|
Description
•