青蛙小白
博客 / 2025/03

使用modelscope下载模型

2025/03/08 · — 字 · 阅读约 — 分钟 ·
目录

see also “使用huggingface-cli下载模型”

安装ModelScope SDK

安装环境信息如下:

  • 操作系统: Ubuntu 24.04
  • 安装用户: 系统普通用户(非root, 非特权用户)
  • Python版本: 3.11 (注Ubuntu 24.04内置安装了Python 3.12, Python 3.11需额外安装)

安装过程如下:

  1. 切换到执行安装操作的普通系统用户上
su - <theuser>
  1. 确保Python 3.11的pip已经安装:
python3.11 -m ensurepip --upgrade --user
python3.11 -m pip install --user --upgrade pip --index-url=https://mirrors.aliyun.com/pypi/simple
  1. 确保pipx已经安装:
python3.11 -m pip install --user pipx --index-url=https://mirrors.aliyun.com/pypi/simple

前面两步安装的pip和pipx位于~/.local目录中,具体为~/.local/bin, ~/.local/lib/python3.11/site-packages

  1. 使用pipx安装modelscope
pipx install modelscope --index-url=https://mirrors.aliyun.com/pypi/simple

使用pipx安装的好处是, modelscope被pipx安装到了~/.local/share/pipx/venvs/modelscope下,具有独立的虚拟环境

  1. 验证安装

安装完成后,会自动创建~/.local/bin/modelscope~/.local/share/pipx/venvs/modelscope/bin/modelscope的软链接。

modelscope --help
usage: modelscope <command> [<args>]

positional arguments:
  {download,upload,clear-cache,plugin,pipeline,modelcard,model,server,login,llamafile}
                        modelscope commands helpers

options:
  -h, --help            show this help message and exit
  --token TOKEN         Specify ModelScope SDK token.

下载模型

modelscope支持断点续传和模型高速下载。无论是使用命令行还是ModelScope SDK,默认模型会下载到~/.cache/modelscope/hub目录下。如果需要修改cache目录,可以手动指定环境变量:MODELSCOPE_CACHE,指定后,模型将下载到该环境变量指定的目录中。

另外还可以使用--local_dir ./model-dir来指定模型下载目录。

BAAI/bge-large-zh-v1.5

modelscope download --model BAAI/bge-large-zh-v1.5

下载单个或多个文件

指定下载单个文件:

modelscope download --model 'Qwen/Qwen2.5-7B-Instruct' tokenizer.json

指定下载多个个文件:

modelscope download --model 'Qwen/Qwen2.5-7B-Instruct' tokenizer.json config.json

过滤指定文件:

modelscope download --model 'Qwen/Qwen2.5-7B-Instruct' --exclude '*.safetensors'

参考

TAGS # aigc
评论