mirror of
https://github.com/mudler/LocalAI.git
synced 2026-02-22 11:19:39 -06:00
fix(backend-detection): default to CPU if there is less than 4GB of GPU available (#6057)
fix(gpu-detection): default to CPU if there is less than 4GB of GPU available Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
committed by
GitHub
parent
b52bfaf1b3
commit
19c92c70c5
@@ -5,12 +5,15 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/jaypipes/ghw/pkg/gpu"
|
||||
"github.com/mudler/LocalAI/pkg/xsysinfo"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type SystemState struct {
|
||||
GPUVendor string
|
||||
gpus []*gpu.GraphicsCard
|
||||
VRAM uint64
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -91,24 +94,32 @@ func (s *SystemState) getSystemCapabilities() string {
|
||||
}
|
||||
|
||||
log.Info().Str("Capability", s.GPUVendor).Msgf("Capability automatically detected, set %s to override", capabilityEnv)
|
||||
// If vram is less than 4GB, let's default to CPU but warn the user that they can override that via env
|
||||
if s.VRAM <= 4*1024*1024*1024 {
|
||||
log.Warn().Msgf("VRAM is less than 4GB, defaulting to CPU. Set %s to override", capabilityEnv)
|
||||
return defaultCapability
|
||||
}
|
||||
|
||||
return s.GPUVendor
|
||||
}
|
||||
|
||||
func GetSystemState() (*SystemState, error) {
|
||||
gpuVendor, _ := detectGPUVendor()
|
||||
// Detection is best-effort here, we don't want to fail if it fails
|
||||
gpus, _ := xsysinfo.GPUs()
|
||||
log.Debug().Any("gpus", gpus).Msg("GPUs")
|
||||
gpuVendor, _ := detectGPUVendor(gpus)
|
||||
log.Debug().Str("gpuVendor", gpuVendor).Msg("GPU vendor")
|
||||
vram, _ := xsysinfo.TotalAvailableVRAM()
|
||||
log.Debug().Any("vram", vram).Msg("Total available VRAM")
|
||||
|
||||
return &SystemState{
|
||||
GPUVendor: gpuVendor,
|
||||
gpus: gpus,
|
||||
VRAM: vram,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func detectGPUVendor() (string, error) {
|
||||
gpus, err := xsysinfo.GPUs()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
func detectGPUVendor(gpus []*gpu.GraphicsCard) (string, error) {
|
||||
for _, gpu := range gpus {
|
||||
if gpu.DeviceInfo != nil {
|
||||
if gpu.DeviceInfo.Vendor != nil {
|
||||
|
||||
Reference in New Issue
Block a user