-
可以通过以下代码下载并加载模型,以
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
相关推荐
张哈大8 小时前
解密Function Calling:AI Agent工具调用的标准化核心搬砖的小码农_Sky8 小时前
特斯拉FSD Supervised(监督版)的技术原理子榆.8 小时前
CANN ATC编译器:模型从Python到达芬奇指令走了多远lookaroundd8 小时前
llm-compressor 普通量化调用链分析Loo国昌8 小时前
从 Agent 编排到 Skill Runtime:企业 AI 工程化的下一层抽象编码者卢布8 小时前
【Azure Service Bus】Azure Service Bus Java SDK 中 Token 刷新异常的排查思路liuyunshengsir8 小时前
PyTorch 最小模型转 ONNX 完整样例z202305088 小时前
RDMA之RoCEv2 无损网络PFC 、DCQCN 和ECN (7)m0_380167148 小时前
CoinGlass API vs Glassnode:全面对比分析