MCPcopy Index your code
hub / github.com/mudler/LocalAI / IsBackendCompatible

Method IsBackendCompatible

pkg/system/capabilities.go:218–268  ·  view source on GitHub ↗

IsBackendCompatible checks if a backend (identified by name and URI) is compatible with the current system capability. This function uses getSystemCapabilities to ensure consistency with capability detection (including VRAM checks, environment overrides, etc.).

(name, uri string)

Source from the content-addressed store, hash-verified

216// with the current system capability. This function uses getSystemCapabilities to ensure
217// consistency with capability detection (including VRAM checks, environment overrides, etc.).
218func (s *SystemState) IsBackendCompatible(name, uri string) bool {
219 if s.CapabilityFilterDisabled() {
220 return true
221 }
222
223 combined := strings.ToLower(name + " " + uri)
224 capability := s.getSystemCapabilities()
225
226 // Check for darwin/macOS-specific backends (mlx, metal, darwin)
227 isDarwinBackend := strings.Contains(combined, backendTokenDarwin) ||
228 strings.Contains(combined, backendTokenMLX) ||
229 strings.Contains(combined, backendTokenMetal)
230 if isDarwinBackend {
231 // Darwin backends require the system to be running on darwin with metal or darwin-x86 capability
232 return capability == metal || capability == darwinX86
233 }
234
235 // Check for NVIDIA L4T-specific backends (arm64 Linux with NVIDIA GPU)
236 // This must be checked before the general NVIDIA check as L4T backends
237 // may also contain "cuda" or "nvidia" in their names
238 isL4TBackend := strings.Contains(combined, backendTokenL4T)
239 if isL4TBackend {
240 return strings.HasPrefix(capability, nvidiaL4T)
241 }
242
243 // Check for NVIDIA/CUDA-specific backends (non-L4T)
244 isNvidiaBackend := strings.Contains(combined, backendTokenCUDA) ||
245 strings.Contains(combined, Nvidia)
246 if isNvidiaBackend {
247 // NVIDIA backends are compatible with nvidia, nvidia-cuda-12, nvidia-cuda-13, and l4t capabilities
248 return strings.HasPrefix(capability, Nvidia)
249 }
250
251 // Check for AMD/ROCm-specific backends
252 isAMDBackend := strings.Contains(combined, backendTokenROCM) ||
253 strings.Contains(combined, backendTokenHIP) ||
254 strings.Contains(combined, AMD)
255 if isAMDBackend {
256 return capability == AMD
257 }
258
259 // Check for Intel/SYCL-specific backends
260 isIntelBackend := strings.Contains(combined, backendTokenSYCL) ||
261 strings.Contains(combined, Intel)
262 if isIntelBackend {
263 return capability == Intel
264 }
265
266 // CPU backends are always compatible
267 return true
268}

Callers 2

IsCompatibleWithMethod · 0.80

Calls 3

getSystemCapabilitiesMethod · 0.95
ContainsMethod · 0.80

Tested by

no test coverage detected