tensorflow 等模型离线到本地及加载
因为不同的网络情况可能导致加载失败,此处以在 huggingface 上的模型为例,说明如何将模型离线并从本地加载
- 在需要备份模型的环境中,使用 conda 离线
conda create -n huggingface huggingface_hub conda activate huggingface # bash 环境 huggingface-cli download --repo-type model --resume-download '${模型名}' --local-dir ${模型保存路径}
- 本地加载模型
from transformers import AutoModelForCausalLM, AutoTokenizer tokenizer = AutoTokenizer.from_pretrained('${模型保存路径}', trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained('${模型保存路径}',trust_remote_code = True)
完工!