使用.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
相关推荐
ai小陈9 小时前
PyTorch Profiler性能分析实战:定位GPU训练中的慢算子
人工智能·深度学习·机器学习·ai·性能优化·gpu算力
YCOSA20259 小时前
系统工具使用检测.exe (仅供娱乐)
python·microsoft
2601_962295339 小时前
如何python实现网页的自动化
python·selenium·beautifulsoup·requests·网页自动化
ofoxcoding9 小时前
GPT Image 2.5 API 实战:Python 调用实现图片生成与编辑
人工智能·python·gpt·ai
俊哥V10 小时前
AI 今日研究简报 · 2026-09-09
人工智能·ai
张小姐的猫10 小时前
【AI大模型接入SDK】 —— Gemini接入封装
android·数据结构·数据库·c++·人工智能·python
陈皮糖..10 小时前
从零搭建一个简易 AI 运维问答机器人(RAG + LangChain + Streamlit)
运维·人工智能·ai·langchain·机器人
Elastic 中国社区官方博客10 小时前
Elasticsearch Python DSL 客户端开发
大数据·数据库·python·elasticsearch·搜索引擎·全文检索
计算机编程-吉哥11 小时前
脑肿瘤MRI智能识别系统:基于深度学习的像素级脑肿瘤语义分割平台【计算机毕业设计选题推荐】
人工智能·python·深度学习·算法·毕业设计·课程设计·大数据毕业设计选题推荐
小木_.11 小时前
Python 离线识别滑块缺口距离,项目推荐
开发语言·python·滑块识别·人机验证·滑块缺口·缺口识别