Skip to content

Commit 1c9a1a6

Browse files
committed
feat(backend): fallback with autodetect
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent ad85c5a commit 1c9a1a6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pkg/model/initializers.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,27 @@ func (ml *ModelLoader) GreedyLoader(opts ...Option) (grpc.Backend, error) {
509509
err = errors.Join(err, fmt.Errorf("backend %s returned no usable model", key))
510510
log.Info().Msgf("[%s] Fails: %s", key, "backend returned no usable model")
511511
}
512+
513+
if autoDetect && key == LLamaCPP && err != nil {
514+
backendToUse := LLamaCPPFallback
515+
if xsysinfo.HasCPUCaps(cpuid.AVX2) {
516+
backendToUse = LLamaCPPAVX2
517+
} else if xsysinfo.HasCPUCaps(cpuid.AVX) {
518+
backendToUse = LLamaCPPAVX
519+
}
520+
521+
// Autodetection failed, try the fallback
522+
log.Info().Msgf("[%s] Autodetection failed, trying the fallback", key)
523+
options = append(options, WithBackendString(backendToUse))
524+
model, modelerr = ml.BackendLoader(options...)
525+
if modelerr == nil && model != nil {
526+
log.Info().Msgf("[%s] Loads OK", key)
527+
return model, nil
528+
} else {
529+
err = errors.Join(err, fmt.Errorf("[%s]: %w", key, modelerr))
530+
log.Info().Msgf("[%s] Fails: %s", key, modelerr.Error())
531+
}
532+
}
512533
}
513534

514535
return nil, fmt.Errorf("could not load model - all backends returned error: %s", err.Error())

0 commit comments

Comments
 (0)