上传、下载huggingface仓库文件(模型、数据等)

下载

例如,想要从huggingface hub下载llama-13b模型文件到本地:
在这里插入图片描述

可以用如下命令,local_dir就是你想要下载到的本地文件夹:

from huggingface_hub import snapshot_download
snapshot_download(repo_id="decapoda-research/llama-13b-hf",cache_dir="./cache", local_dir="./model_weights/llama-13b-hf")

上述命令等价于git clone,更多参数, 例如过滤、指定文件,建立符号链接等,详见官网教程:

上传

想要上传文件,例如模型权重的话,首先得找到自己huggingface hub的access code
在这里插入图片描述

然后将自己的access code设置到自己的机器上:

pip install huggingface_hub  ## 如果没有安装huggingface_hub库
python -c "from huggingface_hub.hf_api import HfFolder; HfFolder.save_token('MY_HUGGINGFACE_TOKEN_HERE')"

最后用如下命令,把相关文件(模型、tokenizer)上传就行(等价于git push)。

pt_model.push_to_hub("my-awesome-model")
tokenizer.push_to_hub("my-awesome-model")

猜你喜欢

转载自blog.csdn.net/weixin_43301333/article/details/130334346