ollama 在Linux上使模型位置更容易和更清晰

ogsagwnx  于 6个月前  发布在  Linux
关注(0)|答案(2)|浏览(145)

它始于在重新安装Linux之前备份下载的模型(我想升级我的CUDA版本并进行干净的安装),然后我不知道模型保存在哪里,也不知道哪个blob对应哪个!
操作系统:Ubuntu 22.04 LTS

(base) user@user-TRX50-AERO-D:~$ ollama list
NAME                      	ID          	SIZE  	MODIFIED    
llama3.1:70b-instruct-q8_0	a706db81604c	74 GB 	5 days ago 	
phi3:medium               	1e67dff39209	7.9 GB	12 days ago	
llava:34b                 	3d2d24f46674	20 GB 	2 weeks ago	
gemma2:27b                	371038893ee3	15 GB 	3 weeks ago	
(base) user@user-TRX50-AERO-D:~$ 

(base) user@user-TRX50-AERO-D:~$ sudo ls /usr/share/ollama/.ollama/models
[sudo] password for user: 
blobs  manifests
(base) user@user-TRX50-AERO-D:~$ sudo ls /usr/share/ollama/.ollama/models/blobs
sha256-00c39c2649c078d5ba6f74e6806c2e4ab1bce903e16105409786ef638caf24a1  sha256-854e958d53c3833a2604aa8f557efdaf5e23ffc7a6fe0280f0387f92fc6bd733
sha256-097a36493f718248845233af1d3fefe7a303f864fae13bc31a3a9704229378ca  sha256-8dde1baf1db03d318a2ab076ae363318357dff487bdd8c1703a29886611e581f
sha256-109037bec39c0becc8221222ae23557559bc594290945a2c4221ab4f303b8871  sha256-a35298562e36265ed3f0bff11a4c9bea8513fbabfca59006c9597648a738a13a
sha256-43070e2d4e532684de521b885f385d0841030efa2b1a20bafb76133a5e1379c1  sha256-a47b02e00552cd7022ea700b1abf8c572bb26c9bc8c1a37e01b566f2344df5dc
sha256-518589767ccdbbe44c13aa2d35e0ae86e0c48969f2094750abb183ee8f2370f4  sha256-c266f81b82cdcde845d98e37aa625fc6e6c0e04818edf7b4bf27528a17e67b1c
sha256-542b217f179c7825eeb5bca3c77d2b75ed05bafbd3451d9188891a60a85337c6  sha256-cdbcae7e69d520e3d5a17b4979c31331dfba959f36641a81576349875d682127
sha256-56bb8bd477a519ffa694fc449c2413c6f0e1d3b1c88fa7e3c9d88d3ae49d4dcb  sha256-f02dd72bb2423204352eabc5637b44d79d17f109fdb510a7c51455892aa2d216
sha256-60677c6bf48ba630e7ffe55cb46e6d8c198b5b88b81cd7da510c2b0b3240cf7c  sha256-f1cd752815fcf68c3c2e73b2b00b5396c5dffb9eebe49567573f275f9ec85fcd
sha256-6f1156408d0ad0a5f62682fb808d7b56440691703824c0f4a450c4883326ab43  sha256-fa8235e5b48faca34e3ca98cf4f694ef08bd216d28b58071a1f85b1d50cb814d
sha256-7a3cc4804c645959a6734971b87607bc7eb2a2ed3e3adf3ad221f12b79dadff8  sha256-fbbdec5e5fa1f0f6621e10d74f1651e4806adb892f2681995a8ed99bb261df84
sha256-83720bd8438ccdc910deba5efbdc3340820b29258d94a7a60d1addc9a1b5f095
(base) user@user-TRX50-AERO-D:~$ sudo ls /usr/share/ollama/.ollama/models/manifests
registry.ollama.ai

我不知道哪个blob对应哪个模型!

为什么维护这些文件如此困难,因为它们并不小!肯定有更容易的方法,我可以复制并将它们保存到另一个位置,然后之后再恢复到ollama文件夹中!

我实在不想花半天时间去下载它们。
开发者们,请考虑这个请求好吗?

tez616oj

tez616oj1#

我明白,为了提高效率需要对模型文件进行哈希处理,但这样做使得在没有CLI的情况下更难管理模型。

vecaoik1

vecaoik12#

#!/bin/bash

OLLAMA_MODELS=${OLLAMA_MODELS-/usr/share/ollama/.ollama/models}

library=manifests/registry.ollama.ai/library
blobs=blobs

usage() {
    echo "Usage: ${0##*/} model-name ollama-directory"
    echo "       ${0##*/} model-archive ollama-directory"
    echo "       ${0##*/} model-name model-archive"
    exit 1
}

die() {
  echo "$1" >&2
  exit 2
}

get_files() {
  manifest=$library/$1
  echo "$(echo $manifest ; for blob in $(jq -r '.config.digest,.layers[].digest' "$OLLAMA_MODELS/$manifest") ; do
            echo $blobs/${blob/:/-}
          done)"
}

copy_model_to_directory() {
  files=$(get_files "$1")
  cpio -dump -D "$OLLAMA_MODELS" "$2" <<< "$files" || exit $?
}

copy_archive_to_directory() {
  cpio -D "$2" -dumi < "$1" || exit $?
}

copy_model_to_archive() {
  files=$(get_files "$1")
  cpio -o -D "$OLLAMA_MODELS" --file="$2" <<< "$files" || exit $?
}

model_to_path() {
  namespace=${1%:*}
  tag=latest
  _=$(expr match "$1" ".*:") && tag="${1#*:}"
  [ ! -f "$OLLAMA_MODELS/$library/$namespace/$tag" ] && die "Couldn't find manifest for $1"
  echo "$namespace/$tag"
}

[ "${#@}" -ne 2 ] && usage

[ -f "$1" -a -d "$2" ] && { copy_archive_to_directory "$1" "$2" ; exit 0 ; }

model_path=$(model_to_path $1) || exit $?
dst=$(realpath "$2")

[ -d "$dst" ] && { copy_model_to_directory "$model_path" "$dst" ; exit 0 ; }

[ ! -e "$dst" ] && { copy_model_to_archive "$model_path" "$dst" ; exit 0 ; }

usage

相关问题