Skip to content

Commit b3c90f0

Browse files
committed
fix(gpu-detection): default to CPU if there is less than 4GB of GPU available
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 2b44467 commit b3c90f0

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

pkg/system/capabilities.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import (
55
"runtime"
66
"strings"
77

8+
"github.com/jaypipes/ghw/pkg/gpu"
89
"github.com/mudler/LocalAI/pkg/xsysinfo"
910
"github.com/rs/zerolog/log"
1011
)
1112

1213
type SystemState struct {
1314
GPUVendor string
15+
gpus []*gpu.GraphicsCard
16+
vram uint64
1417
}
1518

1619
const (
@@ -91,24 +94,39 @@ func (s *SystemState) getSystemCapabilities() string {
9194
}
9295

9396
log.Info().Str("Capability", s.GPUVendor).Msgf("Capability automatically detected, set %s to override", capabilityEnv)
97+
// If vram is less than 4GB, let's default to CPU but warn the user that they can override that via env
98+
if s.vram <= 4*1024*1024*1024 {
99+
log.Warn().Msgf("VRAM is less than 4GB, defaulting to CPU. Set %s to override", capabilityEnv)
100+
return defaultCapability
101+
}
102+
94103
return s.GPUVendor
95104
}
96105

97106
func GetSystemState() (*SystemState, error) {
98-
gpuVendor, _ := detectGPUVendor()
107+
gpus, err := xsysinfo.GPUs()
108+
if err != nil {
109+
return nil, err
110+
}
111+
112+
log.Debug().Any("gpus", gpus).Msg("GPUs")
113+
gpuVendor, _ := detectGPUVendor(gpus)
99114
log.Debug().Str("gpuVendor", gpuVendor).Msg("GPU vendor")
100115

116+
vram, err := xsysinfo.TotalAvailableVRAM()
117+
if err != nil {
118+
return nil, err
119+
}
120+
log.Debug().Any("vram", vram).Msg("Total available VRAM")
121+
101122
return &SystemState{
102123
GPUVendor: gpuVendor,
124+
gpus: gpus,
125+
vram: vram,
103126
}, nil
104127
}
105128

106-
func detectGPUVendor() (string, error) {
107-
gpus, err := xsysinfo.GPUs()
108-
if err != nil {
109-
return "", err
110-
}
111-
129+
func detectGPUVendor(gpus []*gpu.GraphicsCard) (string, error) {
112130
for _, gpu := range gpus {
113131
if gpu.DeviceInfo != nil {
114132
if gpu.DeviceInfo.Vendor != nil {

0 commit comments

Comments
 (0)