@@ -5,12 +5,15 @@ import (
5
5
"runtime"
6
6
"strings"
7
7
8
+ "github.com/jaypipes/ghw/pkg/gpu"
8
9
"github.com/mudler/LocalAI/pkg/xsysinfo"
9
10
"github.com/rs/zerolog/log"
10
11
)
11
12
12
13
type SystemState struct {
13
14
GPUVendor string
15
+ gpus []* gpu.GraphicsCard
16
+ vram uint64
14
17
}
15
18
16
19
const (
@@ -91,24 +94,39 @@ func (s *SystemState) getSystemCapabilities() string {
91
94
}
92
95
93
96
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
+
94
103
return s .GPUVendor
95
104
}
96
105
97
106
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 )
99
114
log .Debug ().Str ("gpuVendor" , gpuVendor ).Msg ("GPU vendor" )
100
115
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
+
101
122
return & SystemState {
102
123
GPUVendor : gpuVendor ,
124
+ gpus : gpus ,
125
+ vram : vram ,
103
126
}, nil
104
127
}
105
128
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 ) {
112
130
for _ , gpu := range gpus {
113
131
if gpu .DeviceInfo != nil {
114
132
if gpu .DeviceInfo .Vendor != nil {
0 commit comments