File size: 1,357 Bytes
15c46ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Use an anonymous mirror transport; hashes come from the official HF API."""
import fnmatch
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
from settings import MODELS, WEIGHTS
from huggingface_hub import HfApi
from range_download import download
from download_core import download_imagebind

if __name__ == "__main__":
    api = HfApi()
    for key, destination, patterns in [
        ("nextgpt", WEIGHTS / "nextgpt", ["*.json", "*.model", "pytorch_model.pt"]),
        ("llama", WEIGHTS / "sources" / "llama", ["*.json", "*.model", "*.safetensors"]),
        ("vicuna_delta", WEIGHTS / "sources" / "vicuna_delta", ["*.json", "*.model", "pytorch_model*.bin"]),
    ]:
        repo, revision = MODELS[key]
        info = api.model_info(repo, revision=revision, files_metadata=True)
        for file in info.siblings:
            if not any(fnmatch.fnmatch(file.rfilename, pattern) for pattern in patterns):
                continue
            lfs = file.lfs
            download(f"https://hf-mirror.com/{repo}/resolve/{revision}/{file.rfilename}",
                     destination / file.rfilename, file.size,
                     sha256=lfs.sha256 if lfs else None, git_sha1=file.blob_id if not lfs else None)
    download_imagebind()
    print("Core model downloads verified.", flush=True)