Skip to content

Commit f0b47cf

Browse files
authored
fix(backends gallery): trim string when reading cap from file (#5909)
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent ee625fc commit f0b47cf

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

core/gallery/backend_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gallery
33
import (
44
"github.com/mudler/LocalAI/core/config"
55
"github.com/mudler/LocalAI/pkg/system"
6+
"github.com/rs/zerolog/log"
67
)
78

89
// BackendMetadata represents the metadata stored in a JSON file for each installed backend
@@ -33,9 +34,11 @@ func (backend *GalleryBackend) FindBestBackendFromMeta(systemState *system.Syste
3334

3435
realBackend := backend.CapabilitiesMap[systemState.Capability(backend.CapabilitiesMap)]
3536
if realBackend == "" {
37+
log.Debug().Str("backend", backend.Name).Str("reportedCapability", systemState.Capability(backend.CapabilitiesMap)).Msg("No backend found for reported capability")
3638
return nil
3739
}
3840

41+
log.Debug().Str("backend", backend.Name).Str("reportedCapability", systemState.Capability(backend.CapabilitiesMap)).Msg("Found backend for reported capability")
3942
return backends.FindByName(realBackend)
4043
}
4144

core/services/backends.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func (g *GalleryService) backendHandler(op *GalleryOp[gallery.GalleryBackend], s
2424
g.modelLoader.DeleteExternalBackend(op.GalleryElementName)
2525
} else {
2626
log.Warn().Msgf("installing backend %s", op.GalleryElementName)
27+
log.Debug().Msgf("backend galleries: %v", g.appConfig.BackendGalleries)
2728
err = gallery.InstallBackendFromGallery(g.appConfig.BackendGalleries, systemState, op.GalleryElementName, g.appConfig.BackendsPath, progressCallback, true)
2829
if err == nil {
2930
err = gallery.RegisterBackends(g.appConfig.BackendsPath, g.modelLoader)

pkg/system/capabilities.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,24 @@ func (s *SystemState) Capability(capMap map[string]string) string {
2525

2626
// Check if the reported capability is in the map
2727
if _, exists := capMap[reportedCapability]; exists {
28+
log.Debug().Str("reportedCapability", reportedCapability).Any("capMap", capMap).Msg("Using reported capability")
2829
return reportedCapability
2930
}
3031

32+
log.Debug().Str("reportedCapability", reportedCapability).Any("capMap", capMap).Msg("The requested capability was not found, using default capability")
3133
// Otherwise, return the default capability (catch-all)
3234
return defaultCapability
3335
}
3436

3537
func (s *SystemState) getSystemCapabilities() string {
3638
if os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY") != "" {
39+
log.Debug().Str("LOCALAI_FORCE_META_BACKEND_CAPABILITY", os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY")).Msg("Using forced capability")
3740
return os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY")
3841
}
3942

4043
capabilityRunFile := "/run/localai/capability"
4144
if os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY_RUN_FILE") != "" {
45+
log.Debug().Str("LOCALAI_FORCE_META_BACKEND_CAPABILITY_RUN_FILE", os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY_RUN_FILE")).Msg("Using forced capability run file")
4246
capabilityRunFile = os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY_RUN_FILE")
4347
}
4448

@@ -48,31 +52,37 @@ func (s *SystemState) getSystemCapabilities() string {
4852
if _, err := os.Stat(capabilityRunFile); err == nil {
4953
capability, err := os.ReadFile(capabilityRunFile)
5054
if err == nil {
51-
return string(capability)
55+
log.Debug().Str("capability", string(capability)).Msg("Using capability from run file")
56+
return strings.Trim(strings.TrimSpace(string(capability)), "\n")
5257
}
5358
}
5459

5560
// If we are on mac and arm64, we will return metal
5661
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
62+
log.Debug().Msg("Using metal capability")
5763
return metal
5864
}
5965

6066
// If we are on mac and x86, we will return darwin-x86
6167
if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" {
68+
log.Debug().Msg("Using darwin-x86 capability")
6269
return darwinX86
6370
}
6471

6572
// If arm64 on linux and a nvidia gpu is detected, we will return nvidia-l4t
6673
if runtime.GOOS == "linux" && runtime.GOARCH == "arm64" {
6774
if s.GPUVendor == "nvidia" {
75+
log.Debug().Msg("Using nvidia-l4t capability")
6876
return nvidiaL4T
6977
}
7078
}
7179

7280
if s.GPUVendor == "" {
81+
log.Debug().Msg("Using default capability")
7382
return defaultCapability
7483
}
7584

85+
log.Debug().Str("GPUVendor", s.GPUVendor).Msg("Using GPU vendor capability")
7686
return s.GPUVendor
7787
}
7888

0 commit comments

Comments
 (0)