【转载】Huggingface上传自己的预训练模型,Windows配置代理

一些预训练的权重可以传到Huggingface上

1. Huggingface 上传自己的模型

下面是具体操作教程,转载自Huggingface上传自己的预训练模型(大小权重都可以)

1. 安装git-lfs

$ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
$ sudo apt-get install git-lfs
$ git lfs install
$ pip install huggingface_hub

上述是Linux安装git-lfs, windows用户可以直接下载并安装。地址:Git Large File Storage

2. 登录huggingface

使用huggingface-cli login命令进行登录,登录过程中需要输入用户的Access Tokens 。这里需要先到网站页面上进行设置然后复制过来进行登录。

$ huggingface-cli login

        _|    _|  _|    _|    _|_|_|    _|_|_|  _|_|_|  _|      _|    _|_|_|      _|_|_|_|    _|_|      _|_|_|  _|_|_|_|
        _|    _|  _|    _|  _|        _|          _|    _|_|    _|  _|            _|        _|    _|  _|        _|
        _|_|_|_|  _|    _|  _|  _|_|  _|  _|_|    _|    _|  _|  _|  _|  _|_|      _|_|_|    _|_|_|_|  _|        _|_|_|
        _|    _|  _|    _|  _|    _|  _|    _|    _|    _|    _|_|  _|    _|      _|        _|    _|  _|        _|
        _|    _|    _|_|      _|_|_|    _|_|_|  _|_|_|  _|      _|    _|_|_|      _|        _|    _|    _|_|_|  _|_|_|_|

        To login, `huggingface_hub` now requires a token generated from https://huggingface.co/settings/token.
        (Deprecated, will be removed in v0.3.0) To login with username and password instead, interrupt with Ctrl+C.
        
Token: 
Login successful

3. 创建项目

$ huggingface-cli repo create model_name

如果你想要手动创建,则可以直接在Huggingface上new一个Model就可以跳过这一步了。

4. 克隆仓库并准备上传

$ git lfs install
$ git clone https://huggingface.co/username/model_name

克隆来以后就可以把需要上传的文件放入到这个下载的model_name文件夹中。

这个时候如果你发现你上传的文件的大小大于5GB,你就应该运行以下命令,否则可以不运行:

$ huggingface-cli lfs-enable-largefiles ./path/to/your/repo

5. 上传模型

$ git add .
$ git commit -m "commit from $USER"
$ git push

第一次上传可能出现让你输入账号密码,只需要按照要求输入即可。

参考

  1. https://juejin.cn/post/7081452948550746148
  2. https://blog.csdn.net/javastart/article/details/122648199

2. Huggingface 上传自己的模型

最近Huggingface被墙了,所以可以需要代理.

在Windows命令提示符(cmd)中设置代理的方法:

set http_proxy=http://127.0.0.1:2802
set https_proxy=http://127.0.0.1:2802
# 127.0.0.1 一般不变, :后面是端口号, 需要自己查看并设置。
# 代理端口,可以在 设置 → 网络和Internet → 代理 中查看。

若以上设置还不能,下面是在 Windows 系统上为 Git 添加代理设置:
有两种方式, 选一种进行即可

1. 通过命令行使用 git config 命令

git config --global http.proxy http://用户名:密码@代理服务器:端口
git config --global https.proxy https://用户名:密码@代理服务器:端口

如果你想查看你的配置,可以使用:

git config --global --get http.proxy
git config --global --get https.proxy

如果你需要删除这些代理设置,可以使用:

git config --global --unset http.proxy
git config --global --unset https.proxy

2. 手动编辑全局 .gitconfig 文件

编辑C:\Users\yours\.gitconfig文件中的内容即可.

其内容示意:

[user]
	email = 你的邮箱
	name = 名字
[filter "lfs"]
	clean = git-lfs clean -- %f
	smudge = git-lfs smudge -- %f
	process = git-lfs filter-process
	required = true
[credential "https://gitee.com"]
	provider = generic
[credential]
	helper = store
[credential "https://huggingface.co"]
	provider = generic
[http]
	proxy = http://127.0.0.1:7890
[https]
	proxy = https://127.0.0.1:7890

你可能感兴趣的:(windows)