mirror of
https://github.com/mudler/LocalAI.git
synced 2025-02-14 22:51:57 +00:00
Some checks are pending
Explorer deployment / build-linux (push) Waiting to run
GPU tests / ubuntu-latest (1.21.x) (push) Waiting to run
generate and publish GRPC docker caches / generate_caches (ubuntu:22.04, linux/amd64,linux/arm64, ubuntu-latest) (push) Waiting to run
generate and publish intel docker caches / generate_caches (intel/oneapi-basekit:2025.0.0-0-devel-ubuntu22.04, linux/amd64, ubuntu-latest) (push) Waiting to run
build container images / hipblas-jobs (-aio-gpu-hipblas, rocm/dev-ubuntu-22.04:6.1, hipblas, true, ubuntu:22.04, extras, latest-gpu-hipblas, latest-aio-gpu-hipblas, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, -hipblas-ffmpeg) (push) Waiting to run
build container images / hipblas-jobs (rocm/dev-ubuntu-22.04:6.1, hipblas, false, ubuntu:22.04, core, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -hipblas-core) (push) Waiting to run
build container images / hipblas-jobs (rocm/dev-ubuntu-22.04:6.1, hipblas, false, ubuntu:22.04, extras, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -hipblas) (push) Waiting to run
build container images / hipblas-jobs (rocm/dev-ubuntu-22.04:6.1, hipblas, true, ubuntu:22.04, core, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -hipblas-ffmpeg-core) (push) Waiting to run
build container images / self-hosted-jobs (-aio-gpu-intel-f16, quay.io/go-skynet/intel-oneapi-base:latest, sycl_f16, true, ubuntu:22.04, extras, latest-gpu-intel-f16, latest-aio-gpu-intel-f16, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, -sycl-f16-ffmpeg) (push) Waiting to run
build container images / self-hosted-jobs (-aio-gpu-intel-f32, quay.io/go-skynet/intel-oneapi-base:latest, sycl_f32, true, ubuntu:22.04, extras, latest-gpu-intel-f32, latest-aio-gpu-intel-f32, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, -sycl-f32-ffmpeg) (push) Waiting to run
build container images / self-hosted-jobs (-aio-gpu-nvidia-cuda-11, ubuntu:22.04, cublas, 11, 7, true, extras, latest-gpu-nvidia-cuda-11, latest-aio-gpu-nvidia-cuda-11, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, -cublas-cuda11-ffmpeg) (push) Waiting to run
build container images / self-hosted-jobs (-aio-gpu-nvidia-cuda-12, ubuntu:22.04, cublas, 12, 0, true, extras, latest-gpu-nvidia-cuda-12, latest-aio-gpu-nvidia-cuda-12, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, -cublas-cuda12-ffmpeg) (push) Waiting to run
build container images / self-hosted-jobs (quay.io/go-skynet/intel-oneapi-base:latest, sycl_f16, false, ubuntu:22.04, core, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -sycl-f16-core) (push) Waiting to run
build container images / self-hosted-jobs (quay.io/go-skynet/intel-oneapi-base:latest, sycl_f16, true, ubuntu:22.04, core, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -sycl-f16-ffmpeg-core) (push) Waiting to run
build container images / self-hosted-jobs (quay.io/go-skynet/intel-oneapi-base:latest, sycl_f32, false, ubuntu:22.04, core, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -sycl-f32-core) (push) Waiting to run
build container images / self-hosted-jobs (quay.io/go-skynet/intel-oneapi-base:latest, sycl_f32, true, ubuntu:22.04, core, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -sycl-f32-ffmpeg-core) (push) Waiting to run
build container images / self-hosted-jobs (ubuntu:22.04, , , extras, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, ) (push) Waiting to run
build container images / self-hosted-jobs (ubuntu:22.04, , true, extras, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, -ffmpeg) (push) Waiting to run
build container images / self-hosted-jobs (ubuntu:22.04, cublas, 11, 7, , extras, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -cublas-cuda11) (push) Waiting to run
build container images / self-hosted-jobs (ubuntu:22.04, cublas, 12, 0, , extras, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -cublas-cuda12) (push) Waiting to run
build container images / core-image-build (-aio-cpu, ubuntu:22.04, , true, core, latest-cpu, latest-aio-cpu, --jobs=4 --output-sync=target, linux/amd64,linux/arm64, arc-runner-set, false, auto, -ffmpeg-core) (push) Waiting to run
build container images / core-image-build (ubuntu:22.04, cublas, 11, 7, , core, --jobs=4 --output-sync=target, linux/amd64, arc-runner-set, false, false, -cublas-cuda11-core) (push) Waiting to run
build container images / core-image-build (ubuntu:22.04, cublas, 11, 7, true, core, --jobs=4 --output-sync=target, linux/amd64, arc-runner-set, false, false, -cublas-cuda11-ffmpeg-core) (push) Waiting to run
build container images / core-image-build (ubuntu:22.04, cublas, 12, 0, , core, --jobs=4 --output-sync=target, linux/amd64, arc-runner-set, false, false, -cublas-cuda12-core) (push) Waiting to run
build container images / core-image-build (ubuntu:22.04, cublas, 12, 0, true, core, --jobs=4 --output-sync=target, linux/amd64, arc-runner-set, false, false, -cublas-cuda12-ffmpeg-core) (push) Waiting to run
build container images / core-image-build (ubuntu:22.04, vulkan, true, core, latest-vulkan-ffmpeg-core, --jobs=4 --output-sync=target, linux/amd64, arc-runner-set, false, false, -vulkan-ffmpeg-core) (push) Waiting to run
build container images / gh-runner (nvcr.io/nvidia/l4t-jetpack:r36.4.0, cublas, 12, 0, true, core, latest-nvidia-l4t-arm64-core, --jobs=4 --output-sync=target, linux/arm64, ubuntu-24.04-arm, true, false, -nvidia-l4t-arm64-core) (push) Waiting to run
Security Scan / tests (push) Waiting to run
Tests extras backends / tests-transformers (push) Waiting to run
Tests extras backends / tests-rerankers (push) Waiting to run
Tests extras backends / tests-diffusers (push) Waiting to run
Tests extras backends / tests-coqui (push) Waiting to run
tests / tests-linux (1.21.x) (push) Waiting to run
tests / tests-aio-container (push) Waiting to run
tests / tests-apple (1.21.x) (push) Waiting to run
Since the remote gallery was introduced this is now completely superseded by it. In order to keep the code clean and remove redudant parts let's simplify the usage. Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
139 lines
4.7 KiB
Go
139 lines
4.7 KiB
Go
package startup
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/mudler/LocalAI/core/config"
|
|
"github.com/mudler/LocalAI/core/gallery"
|
|
"github.com/mudler/LocalAI/pkg/downloader"
|
|
"github.com/mudler/LocalAI/pkg/utils"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// InstallModels will preload models from the given list of URLs and galleries
|
|
// It will download the model if it is not already present in the model path
|
|
// It will also try to resolve if the model is an embedded model YAML configuration
|
|
func InstallModels(galleries []config.Gallery, modelPath string, enforceScan bool, downloadStatus func(string, string, string, float64), models ...string) error {
|
|
// create an error that groups all errors
|
|
var err error
|
|
|
|
for _, url := range models {
|
|
// As a best effort, try to resolve the model from the remote library
|
|
// if it's not resolved we try with the other method below
|
|
|
|
uri := downloader.URI(url)
|
|
|
|
switch {
|
|
case uri.LooksLikeOCI():
|
|
log.Debug().Msgf("[startup] resolved OCI model to download: %s", url)
|
|
|
|
// convert OCI image name to a file name.
|
|
ociName := strings.TrimPrefix(url, downloader.OCIPrefix)
|
|
ociName = strings.TrimPrefix(ociName, downloader.OllamaPrefix)
|
|
ociName = strings.ReplaceAll(ociName, "/", "__")
|
|
ociName = strings.ReplaceAll(ociName, ":", "__")
|
|
|
|
// check if file exists
|
|
if _, e := os.Stat(filepath.Join(modelPath, ociName)); errors.Is(e, os.ErrNotExist) {
|
|
modelDefinitionFilePath := filepath.Join(modelPath, ociName)
|
|
e := uri.DownloadFile(modelDefinitionFilePath, "", 0, 0, func(fileName, current, total string, percent float64) {
|
|
utils.DisplayDownloadFunction(fileName, current, total, percent)
|
|
})
|
|
if e != nil {
|
|
log.Error().Err(e).Str("url", url).Str("filepath", modelDefinitionFilePath).Msg("error downloading model")
|
|
err = errors.Join(err, e)
|
|
}
|
|
}
|
|
|
|
log.Info().Msgf("[startup] installed model from OCI repository: %s", ociName)
|
|
case uri.LooksLikeURL():
|
|
log.Debug().Msgf("[startup] downloading %s", url)
|
|
|
|
// Extract filename from URL
|
|
fileName, e := uri.FilenameFromUrl()
|
|
if e != nil {
|
|
log.Warn().Err(e).Str("url", url).Msg("error extracting filename from URL")
|
|
err = errors.Join(err, e)
|
|
continue
|
|
}
|
|
|
|
modelPath := filepath.Join(modelPath, fileName)
|
|
|
|
if e := utils.VerifyPath(fileName, modelPath); e != nil {
|
|
log.Error().Err(e).Str("filepath", modelPath).Msg("error verifying path")
|
|
err = errors.Join(err, e)
|
|
continue
|
|
}
|
|
|
|
// check if file exists
|
|
if _, e := os.Stat(modelPath); errors.Is(e, os.ErrNotExist) {
|
|
e := uri.DownloadFile(modelPath, "", 0, 0, func(fileName, current, total string, percent float64) {
|
|
utils.DisplayDownloadFunction(fileName, current, total, percent)
|
|
})
|
|
if e != nil {
|
|
log.Error().Err(e).Str("url", url).Str("filepath", modelPath).Msg("error downloading model")
|
|
err = errors.Join(err, e)
|
|
}
|
|
}
|
|
default:
|
|
if _, e := os.Stat(url); e == nil {
|
|
log.Debug().Msgf("[startup] resolved local model: %s", url)
|
|
// copy to modelPath
|
|
md5Name := utils.MD5(url)
|
|
|
|
modelYAML, e := os.ReadFile(url)
|
|
if e != nil {
|
|
log.Error().Err(e).Str("filepath", url).Msg("error reading model definition")
|
|
err = errors.Join(err, e)
|
|
continue
|
|
}
|
|
|
|
modelDefinitionFilePath := filepath.Join(modelPath, md5Name) + ".yaml"
|
|
if e := os.WriteFile(modelDefinitionFilePath, modelYAML, 0600); e != nil {
|
|
log.Error().Err(err).Str("filepath", modelDefinitionFilePath).Msg("error loading model: %s")
|
|
err = errors.Join(err, e)
|
|
}
|
|
} else {
|
|
// Check if it's a model gallery, or print a warning
|
|
e, found := installModel(galleries, url, modelPath, downloadStatus, enforceScan)
|
|
if e != nil && found {
|
|
log.Error().Err(err).Msgf("[startup] failed installing model '%s'", url)
|
|
err = errors.Join(err, e)
|
|
} else if !found {
|
|
log.Warn().Msgf("[startup] failed resolving model '%s'", url)
|
|
err = errors.Join(err, fmt.Errorf("failed resolving model '%s'", url))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
func installModel(galleries []config.Gallery, modelName, modelPath string, downloadStatus func(string, string, string, float64), enforceScan bool) (error, bool) {
|
|
models, err := gallery.AvailableGalleryModels(galleries, modelPath)
|
|
if err != nil {
|
|
return err, false
|
|
}
|
|
|
|
model := gallery.FindModel(models, modelName, modelPath)
|
|
if model == nil {
|
|
return err, false
|
|
}
|
|
|
|
if downloadStatus == nil {
|
|
downloadStatus = utils.DisplayDownloadFunction
|
|
}
|
|
|
|
log.Info().Str("model", modelName).Str("license", model.License).Msg("installing model")
|
|
err = gallery.InstallModelFromGallery(galleries, modelName, modelPath, gallery.GalleryModel{}, downloadStatus, enforceScan)
|
|
if err != nil {
|
|
return err, true
|
|
}
|
|
|
|
return nil, true
|
|
}
|