-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat: auto select llama-cpp cuda runtime #2306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7df6910
ecd71b1
e9bca66
20b442a
c29825b
4bb8963
f0a688b
4ce686a
94d96c7
d917ec8
4e44e00
079ffeb
e7fc049
18bd7a8
578e34f
6586b09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -319,7 +319,14 @@ build-minimal: | |
| build-api: | ||
| BUILD_GRPC_FOR_BACKEND_LLAMA=true BUILD_API_ONLY=true GO_TAGS=none $(MAKE) build | ||
|
|
||
| dist: build | ||
| dist: | ||
| STATIC=true $(MAKE) backend-assets/grpc/llama-cpp-avx2 | ||
| ifeq ($(OS),Darwin) | ||
| $(info ${GREEN}I Skip CUDA build on MacOS${RESET}) | ||
| else | ||
| $(MAKE) backend-assets/grpc/llama-cpp-cuda | ||
| endif | ||
| $(MAKE) build | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct, I've split that off initially just for I've added the cuda switch here and not at the top because we don't need container images or the generic |
||
| mkdir -p release | ||
| # if BUILD_ID is empty, then we don't append it to the binary name | ||
| ifeq ($(BUILD_ID),) | ||
|
|
@@ -677,6 +684,13 @@ ifeq ($(BUILD_TYPE),metal) | |
| cp backend/cpp/llama-fallback/llama.cpp/build/bin/default.metallib backend-assets/grpc/ | ||
| endif | ||
|
|
||
| backend-assets/grpc/llama-cpp-cuda: backend-assets/grpc | ||
| cp -rf backend/cpp/llama backend/cpp/llama-cuda | ||
| $(MAKE) -C backend/cpp/llama-cuda purge | ||
| $(info ${GREEN}I llama-cpp build info:cuda${RESET}) | ||
| CMAKE_ARGS="$(CMAKE_ARGS) -DLLAMA_AVX=on -DLLAMA_AVX2=off -DLLAMA_AVX512=off -DLLAMA_FMA=off -DLLAMA_F16C=off -DLLAMA_CUDA=ON" $(MAKE) VARIANT="llama-cuda" build-llama-cpp-grpc-server | ||
| cp -rfv backend/cpp/llama-cuda/grpc-server backend-assets/grpc/llama-cpp-cuda | ||
|
|
||
| backend-assets/grpc/llama-ggml: sources/go-llama.cpp sources/go-llama.cpp/libbinding.a backend-assets/grpc | ||
| CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(CURDIR)/sources/go-llama.cpp LIBRARY_PATH=$(CURDIR)/sources/go-llama.cpp \ | ||
| $(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/llama-ggml ./backend/go/llm/llama-ggml/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import ( | |
| "time" | ||
|
|
||
| grpc "github.com/go-skynet/LocalAI/pkg/grpc" | ||
| "github.com/go-skynet/LocalAI/pkg/xsysinfo" | ||
| "github.com/phayes/freeport" | ||
| "github.com/rs/zerolog/log" | ||
| "golang.org/x/sys/cpu" | ||
|
|
@@ -29,10 +30,12 @@ const ( | |
| LlamaGGML = "llama-ggml" | ||
|
|
||
| LLamaCPP = "llama-cpp" | ||
|
|
||
| LLamaCPPCUDA12 = "llama-cpp-cuda12" | ||
| LLamaCPPAVX2 = "llama-cpp-avx2" | ||
| LLamaCPPAVX = "llama-cpp-avx" | ||
| LLamaCPPFallback = "llama-cpp-fallback" | ||
| LLamaCPPCUDA = "llama-cpp-cuda" | ||
|
|
||
| Gpt4AllLlamaBackend = "gpt4all-llama" | ||
| Gpt4AllMptBackend = "gpt4all-mpt" | ||
|
|
@@ -72,8 +75,7 @@ ENTRY: | |
| } | ||
| } | ||
| if !e.IsDir() { | ||
| //backends = append(backends, e.Name()) | ||
| if !strings.Contains(e.Name(), LLamaCPP) { | ||
| if !strings.Contains(e.Name(), LLamaCPP) || strings.Contains(e.Name(), LLamaCPPFallback) { | ||
| backends[e.Name()] = []string{} | ||
| } | ||
| } | ||
|
|
@@ -104,7 +106,7 @@ ENTRY: | |
| // First has more priority | ||
| priorityList := []string{ | ||
| // First llama.cpp and llama-ggml | ||
| LLamaCPP, LlamaGGML, Gpt4All, | ||
| LLamaCPP, LlamaGGML, Gpt4All, LLamaCPPFallback, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why fallback here?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, but what if they fail when being started? What I was trying to do here is recovering from failures outside our control, but more related to the environment where this starts e.g. missing shared libraries goes undetected until the grpc process is started. Example:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, makes sense. Current GPU detection is pretty naive so that should definitely be improved by checking for the cuda libs. |
||
| } | ||
|
|
||
| toTheEnd := []string{ | ||
|
|
@@ -190,17 +192,33 @@ func (ml *ModelLoader) grpcModel(backend string, o *Options) func(string, string | |
| } else { | ||
| grpcProcess := backendPath(o.assetDir, backend) | ||
|
|
||
| foundCUDA := false | ||
| // for llama-cpp, check CPU capabilities and load the appropriate variant | ||
| if backend == LLamaCPP { | ||
| if cpu.X86.HasAVX2 { | ||
| log.Info().Msgf("[%s] attempting to load with AVX2 variant", backend) | ||
| grpcProcess = backendPath(o.assetDir, LLamaCPPAVX2) | ||
| } else if cpu.X86.HasAVX { | ||
| log.Info().Msgf("[%s] attempting to load with AVX variant", backend) | ||
| grpcProcess = backendPath(o.assetDir, LLamaCPPAVX) | ||
| } else { | ||
| log.Info().Msgf("[%s] attempting to load with fallback variant", backend) | ||
| grpcProcess = backendPath(o.assetDir, LLamaCPPFallback) | ||
| gpus, err := xsysinfo.GPUs() | ||
| if err == nil { | ||
| for _, gpu := range gpus { | ||
| if strings.Contains(gpu.String(), "nvidia") { | ||
| log.Info().Msgf("[%s] attempting to load with CUDA variant", backend) | ||
| grpcProcess = backendPath(o.assetDir, LLamaCPPCUDA) | ||
| if _, err := os.Stat(grpcProcess); err == nil { | ||
| foundCUDA = true | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if !foundCUDA { | ||
| if cpu.X86.HasAVX2 { | ||
| log.Info().Msgf("[%s] attempting to load with AVX2 variant", backend) | ||
| grpcProcess = backendPath(o.assetDir, LLamaCPPAVX2) | ||
| } else if cpu.X86.HasAVX { | ||
| log.Info().Msgf("[%s] attempting to load with AVX variant", backend) | ||
| grpcProcess = backendPath(o.assetDir, LLamaCPPAVX) | ||
| } else { | ||
| log.Info().Msgf("[%s] attempting to load with fallback variant", backend) | ||
| grpcProcess = backendPath(o.assetDir, LLamaCPPFallback) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.