下载方法1:git lfs下载
1、在hf-mirror.com中搜索模型,如搜索text2vec-large-chinese, 点击模型进入页面:https://hf-mirror.com/GanymedeNil/text2vec-large-chinese/tree/main
2、git lfs install
3、git clone https://hf-mirror.com/GanymedeNil/text2vec-large-chinese
简化:直接 git clone https://hf-mirror.com/模型名, 如GanymedeNil/text2vec-large-chinese
下载方法2:手动下载
1、在hf-mirror.com中搜索模型,如搜索text2vec-large-chinese, 点击模型进入页面:https://hf-mirror.com/GanymedeNil/text2vec-large-chinese/tree/main
2、手动点击链接下载
通过代码自动下载:
import requests
from bs4 import BeautifulSoup
import re
def get_url_file(url):
match = re.search(r'/([^ /]+)\?', url)
if match:
result = match.group(1)
return result
else:
print("No match found.")
return None
def download(model):
url = f"https://hf-mirror.com/{model}/tree/main"
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
download_links = soup.find_all('a', attrs={'title': 'Download file'})
for link in download_links:
url = 'http://hf-mirror.com' + link['href']
file_name = get_url_file(url)
if url and file_name:
print('wget ' + url + ' -O ' + file_name)
model = 'google-bert/bert-large-cased'
while model:
download(model)
model = input("Input your model to download: ")
下载方法3:使用transformers的接口下载
import os
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
from huggingface_hub import snapshot_download
snapshot_download(repo_id="Qwen/Qwen1.5-32B",
local_dir_use_symlinks = False,
local_dir = "Qwen/Qwen1.5-32B",
proxies={"https": "http://x.x.x.x:8080"}
)