-
可以通过以下代码下载并加载模型,以
facebook/opt-6.7b为例:pythonfrom 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) -
如果出现以下报错,则说明是网络连接问题:无法连接到 Hugging Face 的服务器
pythonOSError: 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的网络连接问题,在终端输入以下命令
pythonexport HF_ENDPOINT=https://hf-mirror.com成功开始下载:

-
如果仅需要下载模型,且安装了 Hugging Face CLI 工具,可以使用以下命令简单快捷地下载模型ckpt到本地:
pythonhuggingface-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
使用.py脚本下载并加载开源大模型LLMs
Jurio.2026-05-22 13:37
相关推荐
ofoxcoding6 小时前
2026年视频生成API选型指南:根据应用场景匹配最佳方案土星云SaturnCloud6 小时前
边缘侧大模型部署的新利器——国科环宇GK 300I大模型一体机深度评测与架构解析_Jimmy_6 小时前
Agent 溯源精度提升方案码字的特恩6 小时前
AI Agent Skill 工程化 09:让 Skill 自己变好——走向自进化流水线fuquxiaoguang7 小时前
当AI学会“会诊”:微软MAI-DxO与医疗推理的范式革命Muscleheng7 小时前
Spring Boot 3.x 集成 DeepSeek 实现 Function Calling(工具调用)SamChan908 小时前
在Web应用中集成PDF多语言翻译功能:PDFTranslator API实战指南天天进步20158 小时前
Python全栈项目--智能办公自动化系统颜酱8 小时前
09 | 重构项目结构kisloy9 小时前
【爬虫入门第8讲】Python爬虫反爬入门