From f9e368b7c4a9604dbfebeb602d08a17d322d5805 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Thu, 23 Jan 2025 16:35:44 +0100 Subject: [PATCH] chore(refactor): group cpu cap detection (#4674) Signed-off-by: Ettore Di Giacinto --- pkg/model/initializers.go | 49 ++++++++++++++------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/pkg/model/initializers.go b/pkg/model/initializers.go index d5f1459b..9fc0c18c 100644 --- a/pkg/model/initializers.go +++ b/pkg/model/initializers.go @@ -66,6 +66,17 @@ const ( LocalStoreBackend = "local-store" ) +var llamaCPPVariants = []string{ + LLamaCPPAVX2, + LLamaCPPAVX, + LLamaCPPFallback, + LLamaCPPCUDA, + LLamaCPPHipblas, + LLamaCPPSycl16, + LLamaCPPSycl32, + LLamaCPPGRPC, +} + func backendPath(assetDir, backend string) string { return filepath.Join(assetDir, "backend-assets", "grpc", backend) } @@ -107,40 +118,14 @@ ENTRY: if AutoDetect { // if we find the llama.cpp variants, show them of as a single backend (llama-cpp) as later we are going to pick that up // when starting the service - foundLCPPAVX, foundLCPPAVX2, foundLCPPFallback, foundLCPPGRPC, foundLCPPCuda, foundLCPPHipblas, foundSycl16, foundSycl32 := false, false, false, false, false, false, false, false + foundVariants := map[string]bool{} if _, ok := backends[LLamaCPP]; !ok { for _, e := range entry { - if strings.Contains(e.Name(), LLamaCPPAVX2) && !foundLCPPAVX2 { - backends[LLamaCPP] = append(backends[LLamaCPP], LLamaCPPAVX2) - foundLCPPAVX2 = true - } - if strings.Contains(e.Name(), LLamaCPPAVX) && !foundLCPPAVX { - backends[LLamaCPP] = append(backends[LLamaCPP], LLamaCPPAVX) - foundLCPPAVX = true - } - if strings.Contains(e.Name(), LLamaCPPFallback) && !foundLCPPFallback { - backends[LLamaCPP] = append(backends[LLamaCPP], LLamaCPPFallback) - foundLCPPFallback = true - } - if strings.Contains(e.Name(), LLamaCPPGRPC) && !foundLCPPGRPC { - backends[LLamaCPP] = append(backends[LLamaCPP], LLamaCPPGRPC) - foundLCPPGRPC = true - } - if strings.Contains(e.Name(), LLamaCPPCUDA) && !foundLCPPCuda { - backends[LLamaCPP] = append(backends[LLamaCPP], LLamaCPPCUDA) - foundLCPPCuda = true - } - if strings.Contains(e.Name(), LLamaCPPHipblas) && !foundLCPPHipblas { - backends[LLamaCPP] = append(backends[LLamaCPP], LLamaCPPHipblas) - foundLCPPHipblas = true - } - if strings.Contains(e.Name(), LLamaCPPSycl16) && !foundSycl16 { - backends[LLamaCPP] = append(backends[LLamaCPP], LLamaCPPSycl16) - foundSycl16 = true - } - if strings.Contains(e.Name(), LLamaCPPSycl32) && !foundSycl32 { - backends[LLamaCPP] = append(backends[LLamaCPP], LLamaCPPSycl32) - foundSycl32 = true + for _, v := range llamaCPPVariants { + if strings.Contains(e.Name(), v) && !foundVariants[v] { + backends[LLamaCPP] = append(backends[LLamaCPP], v) + foundVariants[v] = true + } } } }