参考:https://github.com/pytorch/vision/issues/4156
一、问题1:rate limit exceeded
问题的产生代码
model = torch.hub.load('huggingface/pytorch-transformers', 'model', 'bert-base-chinese')
环境
pytorch 1.9.0
torchvision 0.10.0
问题
urllib.error.HTTPError: HTTP Error 403: rate limit exceeded
解决办法:
以下方法是可以尝试的方法
1. 更改torch版本
更改torch版本从1.9.0+cpu转到1.7.0
2. 注释错误代码行
注释掉hub.py的162行的方法
_validate_not_a_forked_repo
3. 在加载错误代码之前添加代码:
torch.hub._validate_not_a_forked_repo=lambda a,b,c: True
4. 设置github的token来增加api访问次数
应该没用,因为【torch.hub.load】我们访问的是:https://github.com/...。而不是https://api.github.com/
如果需要改变可以参考:
https://blog.csdn.net/caroline_wendy/article/details/109337216
二、问题2:URLError
如果再次运行代码,报错:
我将torch的版本从1.9.0变成了1.8.1,但是报错:
Downloading: "https://github.com/huggingface/pytorch-transformers/archive/master.zip" to /root/.cache/torch/hub/master.zip
urllib.error.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:841)>
原因:请求github.com请求超时
解决:
windows或Ubuntu中请求github.com请求超时,或在下载GitHub文件出现:<urlopen error [Errno 110] Connection timed out>
三、问题3:Missing dependencies
新的错误:
RuntimeError: Missing dependencies: sentencepiece
这个时候已经下载下来了
原因:请求github.com请求超时
解决:
pip install --user transformers
pip install --user sentencepiece
如果安装出错,请参考:Python - 安装sentencepiece异常