-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathdownload.py
49 lines (39 loc) · 1.44 KB
/
download.py
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
44
45
46
47
48
49
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
# copied from https://github.com/pytorch-labs/gpt-fast/blob/main/scripts/download.py
import os
from typing import Optional
from requests.exceptions import HTTPError
def hf_download(repo_id: Optional[str] = None, hf_token: Optional[str] = None) -> None:
from huggingface_hub import snapshot_download
os.makedirs(f"checkpoints/{repo_id}", exist_ok=True)
try:
snapshot_download(
repo_id,
local_dir=f"checkpoints/{repo_id}",
local_dir_use_symlinks=False,
token=hf_token,
)
except HTTPError as e:
if e.response.status_code == 401:
print(
"You need to pass a valid `--hf_token=...` to download private checkpoints."
)
else:
raise e
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Download data from HuggingFace Hub.")
parser.add_argument(
"--repo_id",
type=str,
default="checkpoints/meta-llama/llama-2-7b-chat-hf",
help="Repository ID to download from.",
)
parser.add_argument(
"--hf_token", type=str, default=None, help="HuggingFace API token."
)
args = parser.parse_args()
hf_download(args.repo_id, args.hf_token)