1. 如何下载hg上的大模型

huggingface-cli 是 Hugging Face 官方提供的命令行工具,自带完善的下载功能

下载安装

# huggingface_hub 依赖于 Python>=3.8
pip install -U huggingface_hub

# 定位huggingface-cli.exe的位置
pip show huggingface-hub
cd D:\soft\anaconda3\lib\site-packages\huggingface_hub\

#使用示例
#下载模型
huggingface-cli.exe download  moka-ai/m3e-base --local-dir d:/llm/m3e-base

#下载数据
huggingface-cli.exe download --repo-type dataset  wikitext --local-dir wikitext

#查看帮助文档
huggingface-cli.exe download -h

huggingface-cli.exe download --local-dir-use-symlinks false google-bert/bert-base-chinese --local-dir d:/llm/bert-base-chinese

D:\python\jupyter\models

重要参数

  • --resume-download If True, resume a previously interrupted download
  • --quiet If True, progress bars are disabled and only the path to the download files is printed
  • --local-dir-use-symlinks {auto,True,False} 因为huggingface的工具链默认会使用符号链接来存储下载的文件,导致--local-dir指定的目录中都是一些“链接文件”,真实模型则存储在~/.cache/huggingface
  • --local-dir LOCAL_DIR
  • –exclude [EXCLUDE …] Glob patterns to exclude from files to download.

设置环境变量

  • huggingface 工具链会获取HF_ENDPOINT环境变量来确定下载文件所用的网址

    export HF_ENDPOINT=https://hf-mirror.com/
    
    #Windows Powershell
    $env:HF_ENDPOINT = "https://hf-mirror.com"
    
  • 改变缓存目录

    • XDG_CACHE_HOME=缓存目录 或 HF_HOME = 缓存目录
    • 默认的目录在:C:\Users\gitriver\.cache\huggingface

如何下载modelscope上的大模型

pip install modelscope
#下载完整模型repo
modelscope download --model qwen/Qwen2-Audio-7B-Instruct
#下载单个文件(以README.md为例)
modelscope download --model qwen/Qwen2-Audio-7B-Instruct README.md

### 指定下载某些文件
modelscope download --model 'AI-ModelScope/gpt2' --include 'onnx/*' '*.tflite'

# ### 过滤指定文件
modelscope download --model 'AI-ModelScope/gpt2' --exclude 'onnx/*' '*.tflite'

# 查看帮助
modelscope download --help

详见使用请参见:https://www.modelscope.cn/docs/模型的下载#使用命令行工具下载模型

Logo

欢迎加入 MCP 技术社区!与志同道合者携手前行,一同解锁 MCP 技术的无限可能!

更多推荐