使用.py脚本下载并加载开源大模型LLMs

  1. 可以通过以下代码下载并加载模型,以facebook/opt-6.7b为例:

    python 复制代码
    from transformers import AutoModelForCausalLM, AutoTokenizer
    
    tokenizer = AutoTokenizer.from_pretrained('facebook/opt-6.7b', cache_dir='your_loaded_path')
    model = AutoModelForCausalLM.from_pretrained('facebook/opt-6.7b', cache_dir='your_loaded_path',
                                                 device_map='your_device', load_in_8bit=True)
  2. 如果出现以下报错,则说明是网络连接问题:无法连接到 Hugging Face 的服务器

    python 复制代码
    OSError: We couldn't connect to 'https://huggingface.co' to load this file, couldn't find it in the cached files and it looks like facebook/opt-6.7b is not the path to a directory containing a file named config.json.
    Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.

    解决方法:只需要设置 HF mirror 就可以修复HF的网络连接问题,在终端输入以下命令

    python 复制代码
    export HF_ENDPOINT=https://hf-mirror.com

    成功开始下载:

  3. 如果仅需要下载模型,且安装了 Hugging Face CLI 工具,可以使用以下命令简单快捷地下载模型ckpt到本地:

    python 复制代码
    huggingface-cli download facebook/opt-6.7b --cache-dir [/本地路径]
    
    # Shell
    huggingface-cli download --repo-type dataset --token [你的token] --resume-download [数据集名称] --cache-dir [/本地路径] --local-dir-use-symlinks False
相关推荐
ofoxcoding6 小时前
2026年视频生成API选型指南:根据应用场景匹配最佳方案
ai·音视频
土星云SaturnCloud6 小时前
边缘侧大模型部署的新利器——国科环宇GK 300I大模型一体机深度评测与架构解析
服务器·人工智能·ai·边缘计算
_Jimmy_6 小时前
Agent 溯源精度提升方案
人工智能·python·langchain
码字的特恩6 小时前
AI Agent Skill 工程化 09:让 Skill 自己变好——走向自进化流水线
人工智能·计算机·ai·程序员·大模型·互联网·编程
fuquxiaoguang7 小时前
当AI学会“会诊”:微软MAI-DxO与医疗推理的范式革命
ai·微软·医疗
Muscleheng7 小时前
Spring Boot 3.x 集成 DeepSeek 实现 Function Calling(工具调用)
人工智能·spring boot·后端·ai·spring ai·deepseek
SamChan908 小时前
在Web应用中集成PDF多语言翻译功能:PDFTranslator API实战指南
前端·python·ai·pdf·yapi·机器翻译
天天进步20158 小时前
Python全栈项目--智能办公自动化系统
开发语言·python
颜酱8 小时前
09 | 重构项目结构
人工智能·python·langchain
kisloy9 小时前
【爬虫入门第8讲】Python爬虫反爬入门
开发语言·爬虫·python