danhtran2mind commited on
Commit
d2c6be8
·
verified ·
1 Parent(s): ef7a282

Delete scripts/old-download_ckpts.py

Browse files
Files changed (1) hide show
  1. scripts/old-download_ckpts.py +0 -82
scripts/old-download_ckpts.py DELETED
@@ -1,82 +0,0 @@
1
- import os
2
- import argparse
3
- import yaml
4
- from huggingface_hub import snapshot_download
5
-
6
- def download_repository(repo_id, local_dir, token=None):
7
- """
8
- Download a Hugging Face repository to a local directory using snapshot_download.
9
-
10
- Args:
11
- repo_id (str): Hugging Face repository ID.
12
- local_dir (str): Local directory to save the downloaded files.
13
- token (str, optional): Hugging Face API token for private/gated repositories.
14
- """
15
- os.makedirs(local_dir, exist_ok=True)
16
-
17
- try:
18
- snapshot_download(
19
- repo_id=repo_id,
20
- local_dir=local_dir,
21
- local_dir_use_symlinks=False,
22
- repo_type="model",
23
- token=token if token else None,
24
- allow_patterns=["*.safetensors", "*.ckpt", "*.json", "*.txt"]
25
- )
26
- print(f"Successfully downloaded all files from {repo_id} to {local_dir}")
27
- except Exception as e:
28
- print(f"Error downloading repository {repo_id}: {str(e)}")
29
-
30
- if __name__ == "__main__":
31
- parser = argparse.ArgumentParser(description="Download Hugging Face repositories to local directories.")
32
- parser.add_argument(
33
- "--config",
34
- type=str,
35
- default="configs/model_ckpts.yaml",
36
- help="Path to the YAML configuration file containing model IDs and local directories"
37
- )
38
- parser.add_argument(
39
- "--token",
40
- type=str,
41
- default=None,
42
- help="Hugging Face API token for private or gated repositories (optional)"
43
- )
44
-
45
- args = parser.parse_args()
46
-
47
- # Load the YAML configuration file
48
- try:
49
- with open(args.config, "r") as f:
50
- config_data = yaml.safe_load(f)
51
-
52
- if not config_data:
53
- raise ValueError("The YAML file is empty or invalid")
54
-
55
- # Extract repo_ids and local_dirs for HuggingFace platform only
56
- repo_ids = []
57
- local_dirs = []
58
- for item in config_data:
59
- if item.get("platform") == "HuggingFace":
60
- repo_ids.append(item["model_id"])
61
- local_dirs.append(item["local_dir"])
62
-
63
- # Validate that at least one valid entry was found
64
- if not repo_ids or not local_dirs:
65
- raise ValueError("No valid HuggingFace platform entries found in the YAML file")
66
-
67
- # Validate that the number of repo_ids matches the number of local_dirs
68
- if len(repo_ids) != len(local_dirs):
69
- raise ValueError("The number of model_ids must match the number of local_dirs for HuggingFace platform")
70
-
71
- # Download each repository
72
- for repo_id, local_dir in zip(repo_ids, local_dirs):
73
- download_repository(repo_id, local_dir, args.token)
74
-
75
- except FileNotFoundError:
76
- print(f"Error: The configuration file '{args.config}' was not found.")
77
- except yaml.YAMLError as e:
78
- print(f"Error: Failed to parse YAML file. Details: {e}")
79
- except KeyError as e:
80
- print(f"Error: Missing expected key in YAML data. Details: {e}")
81
- except ValueError as e:
82
- print(f"Error: {e}")