Compare commits

...

1 Commits

Author SHA1 Message Date
Jeffrey Morgan
6023044af3 replace assets on load 2024-03-08 00:44:22 -08:00
3 changed files with 11 additions and 34 deletions

View File

@ -7,8 +7,6 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"github.com/jmorganca/ollama/version"
) )
func AssetsDir() (string, error) { func AssetsDir() (string, error) {
@ -16,25 +14,8 @@ func AssetsDir() (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
baseDir := filepath.Join(home, ".ollama", "assets")
libDirs, err := os.ReadDir(baseDir) return filepath.Join(home, ".ollama", "assets"), nil
if err == nil {
for _, d := range libDirs {
if d.Name() == version.Version {
continue
}
// Special case the rocm dependencies, which are handled by the installer
if d.Name() == "rocm" {
continue
}
slog.Debug("stale lib detected, cleaning up " + d.Name())
err = os.RemoveAll(filepath.Join(baseDir, d.Name()))
if err != nil {
slog.Warn(fmt.Sprintf("unable to clean up stale library %s: %s", filepath.Join(baseDir, d.Name()), err))
}
}
}
return filepath.Join(baseDir, version.Version), nil
} }
func UpdatePath(dir string) { func UpdatePath(dir string) {

View File

@ -143,25 +143,15 @@ func newLlmServer(gpuInfo gpu.GpuInfo, model string, adapters, projectors []stri
} }
} }
// We stage into a temp directory, and if we've been idle for a while, it may have been reaped err := fmt.Errorf("unable to locate suitable llm library")
_, err := os.Stat(dynLibs[0])
if err != nil {
slog.Info(fmt.Sprintf("%s has disappeared, reloading libraries", dynLibs[0]))
err = nativeInit()
if err != nil {
return nil, err
}
}
err2 := fmt.Errorf("unable to locate suitable llm library")
for _, dynLib := range dynLibs { for _, dynLib := range dynLibs {
srv, err := newDynExtServer(dynLib, model, adapters, projectors, opts) srv, err := newDynExtServer(dynLib, model, adapters, projectors, opts)
if err == nil { if err == nil {
return srv, nil return srv, nil
} }
slog.Warn(fmt.Sprintf("Failed to load dynamic library %s %s", dynLib, err)) slog.Warn(fmt.Sprintf("Failed to load dynamic library %s %s", dynLib, err))
err2 = err err = err
} }
return nil, err2 return nil, err
} }

View File

@ -109,6 +109,12 @@ func nativeInit() error {
if err != nil { if err != nil {
return err return err
} }
// delete the assetsDir
if err := os.RemoveAll(assetsDir); err != nil {
return err
}
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
err := extractPayloadFiles(assetsDir, "llama.cpp/ggml-metal.metal") err := extractPayloadFiles(assetsDir, "llama.cpp/ggml-metal.metal")
if err != nil { if err != nil {