可能遇到的问题:
不知道大家有没有碰到这样的问题,想从hugging face 加载模型,使用其提供的接口做一个简单的demo,但是由于网络的原因没办法正常访问:
'(MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/resolve/main/tokenizer_config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x0000022D20237BB0>, 'Connection to huggingface.co timed out. (connect timeout=10)'))"), '(Request ID: e1fbe047-2f58-4b56-93e0-b565ca3d6097)')' thrown while requesting HEAD https://huggingface.co/bert-base-uncased/resolve/main/tokenizer_config.json
有同学可能会考虑用科学上网尝试解决,但是会遇到新的问题:
requests.exceptions.ProxyError: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/resolve/main/tokenizer_config.json (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1131)'))))"), '(Request ID: 2a88705e-f8fc-4072-bf1a-632ae8ede2aa)')
解决方法:
下载hugging face上的某个目录下的所有文件到本地,在hugging face中搜索加载预训练模型的的函数
模型搜索下载地址:https://huggingface.co/models
如BLIP的调用,将相关的参数换为本地地址即可使用
processor = BlipProcessor.from_pretrained(r"E:\xpj\models\blip-image-captioning-base")
model = BlipForConditionalGeneration.from_pretrained(r"E:\xpj\models\blip-image-captioning-base").to("cuda")
具体的使用方法请参照模型页面的readme介绍