LostRuins / koboldcpp

A simple one-file way to run various GGML and GGUF models with KoboldAI's UI
https://github.com/lostruins/koboldcpp
GNU Affero General Public License v3.0
4.36k stars 312 forks source link

Another `llama_new_context_with_model: failed to initialize Metal backend` issue #964

Open RDearnaley opened 5 days ago

RDearnaley commented 5 days ago

I got the same error message as #744, again on Mac using Metal:

llama_new_context_with_model: failed to initialize Metal backend

Removing-DGGML_METAL_NDEBUG from the Makefile as was done in #744 I got a different set of debug messages:

gml_metal_init: allocating
ggml_metal_init: found device: Apple M2 Ultra
ggml_metal_init: picking default device: Apple M2 Ultra
ggml_metal_init: default.metallib not found, loading from source
ggml_metal_init: GGML_METAL_PATH_RESOURCES = nil
ggml_metal_init: error: could not use bundle path to find ggml-metal-merged.metal, falling back to trying cwd
ggml_metal_init: loading 'ggml-metal.metal'
ggml_metal_init: error: Error Domain=NSCocoaErrorDomain Code=260 "The file “ggml-metal.metal” couldn’t be opened because there is no such file." UserInfo={NSFilePath=ggml-metal.metal, NSUnderlyingError=0x600001c4af40 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
llama_new_context_with_model: failed to initialize Metal backend

Setting the environment variable GGML_METAL_PATH_RESOURCES to the location ~/Documents/GitHub/koboldcpp/ggml/src containing the file it's looking for solved this problem. So I have a workaround, but presumably this shouldn't be necessary.

LostRuins commented 4 days ago

Hi, sorry about that, does it work if you change this additional line into the makefile like this

https://github.com/LostRuins/koboldcpp/commit/06d9068c97bdadbe5830d5a4a9a107c7bc112365#

ggml-metal.o: ggml/src/ggml-metal.m ggml/include/ggml-metal.h
    @echo "== Preparing merged Metal file =="
    @sed -e '/#include "ggml-common.h"/r ggml/src/ggml-common.h' -e '/#include "ggml-common.h"/d' < ggml/src/ggml-metal.metal > ggml/src/ggml-metal-merged.metal
    @cp ggml/src/ggml-metal-merged.metal ./ggml-metal-merged.metal
    $(CC) $(CFLAGS) -c $< -o $@

@beebopkim do you have the same issue?

kmilner commented 4 days ago

@LostRuins That fixes it for me after a clean build.