2023年 huggingface.co 国内可用 IP,修改/etc/hosts 可高速访问,附代码
原理分析
huggingface.co
使用的 CDN 与其它 GFW 清单重合,很多 IP 无法使用。
解决办法是找到与 google、fb 无重合的 IP 段。
几百上千 G 的模型文件怎么搞,走代理还是肉身背硬盘拷?
step 1. 查找全球可用 IP
https://17ce.com/site/dns/20230915_fc0261d053b311eeac17e316c626d952:1.html
挑选 IP 的时候注意避开敏感名称
step 2,配置 hosts 以后验证
13.33.174.80 huggingface.co www.huggingface.co cdn-lfs.huggingface.co
- git clone 模型
git lfs clone https://huggingface.co/baichuan-inc/Baichuan2-13B-Chat
- 手动下载模型
wget https://huggingface.co/baichuan-inc/Baichuan2-13B-Chat/resolve/main/pytorch_model-00001-of-00003.bin
通过程序自动测试可用 IP
import re
import requests
iplist = "https://17ce.com/site/dns/20230915_fc0261d053b311eeac17e316c626d952:1.html"
text = requests.get(iplist)
# 使用正则表达式匹配 IP 地址的模式
ip_pattern = r'>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})<'
# 使用 findall 函数找到所有匹配的 IP 地址
ip_addresses = re.findall(ip_pattern, str(text.content))
print("found {} ip".format(len(ip_addresses)))
for ip in ip_addresses:
url = f"http://{ip}/baichuan-inc/Baichuan2-13B-Chat/resolve/main/tokenizer_config.json"
header = {
"Host": "huggingface.co"
}
try:
response = requests.head(url, headers=header, timeout=5)
print(f"{ip} connect success")
except:
log = ""
发表评论