File size: 1,465 Bytes
79f9224
 
 
 
42742c6
 
79f9224
42742c6
79f9224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
from pathlib import Path
from huggingface_hub import snapshot_download

# HF_ENDPOINT=https://hf-mirror.com python download_llm_copy.py
local_dir = "/Users/jeqin/work/code"
# local_dir = "~/Downloads"
repos = {
    "Qwen/Qwen2.5-0.5B-Instruct": [],
    #"Qwen/Qwen3-235B-A22B-GGUF": ["Q8_0/Qwen3-235B-A22B-Q8_0-00002-of-00009.gguf","Q8_0/Qwen3-235B-A22B-Q8_0-00004-of-00009.gguf"]
}

def download(repo, files):
    folder = repo.split('/')[-1]
    print(f"start download {repo}")
    for retry in range(5):
        try:
            if not files:
                # 下载整个 repo
                snapshot_download(repo_id=repo, local_dir=f"{local_dir}/{folder}",
                                  #ignore_patterns=["original"],
                                #   allow_patterns=None,
                                  local_dir_use_symlinks=False)
                print(f"download {repo} finished")
                break
            else:
                # 下载列表中指定的文件
                snapshot_download(repo_id=repo, local_dir=f"{local_dir}/{folder}", allow_patterns=files,
                                  local_dir_use_symlinks=False)
                print(f"download {repo} finished")
                break
        except Exception as e:
            print(e)
            print(f"download failed, retry: {retry + 1}")


def main():
    for repo, files in repos.items():
        download(repo, files)


if __name__ == '__main__':
    main()