-
Notifications
You must be signed in to change notification settings - Fork 335
/
Copy pathdownload_model.py
52 lines (39 loc) · 1.87 KB
/
download_model.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
50
51
52
import os
import sys
import requests
from tqdm import tqdm
if len(sys.argv) != 2:
print('You must enter the model name as a parameter, e.g.: download_model.py 117M')
sys.exit(1)
model = sys.argv[1]
if model not in ["117M", "PrettyBig", "encoder", "1.5B"]:
print("Unknown model! Currently available models: 117M, SortaBig, 1.5B")
sys.exit(1)
if not os.path.exists(model):
os.makedirs(model)
if not os.path.exists("encoder"):
os.makedirs("encoder")
for filename in ['encoder.json', 'vocab.bpe']:
r = requests.get("https://storage.googleapis.com/connors-models/public/encoder/" + filename, stream=True)
with open(os.path.join("encoder", filename), 'wb') as f:
file_size = int(r.headers["content-length"])
chunk_size = 1000
with tqdm(ncols=100, desc="Fetching " + filename, total=file_size, unit_scale=True) as pbar:
# 1k for chunk_size, since Ethernet packet size is around 1500 bytes
for chunk in r.iter_content(chunk_size=chunk_size):
f.write(chunk)
pbar.update(chunk_size)
if model == "encoder":
sys.exit()
with open(os.path.join(model, "checkpoint"), "w") as f:
f.write("model_checkpoint_path: \"model.ckpt\"\n")
for filename in ['model.ckpt.data-00000-of-00001', 'model.ckpt.index', 'model.ckpt.meta']:
r = requests.get("https://storage.googleapis.com/connors-models/public/" + model + "/" + filename, stream=True)
with open(os.path.join(model, filename), 'wb') as f:
file_size = int(r.headers["content-length"])
chunk_size = 1000
with tqdm(ncols=100, desc="Fetching " + filename, total=file_size, unit_scale=True) as pbar:
# 1k for chunk_size, since Ethernet packet size is around 1500 bytes
for chunk in r.iter_content(chunk_size=chunk_size):
f.write(chunk)
pbar.update(chunk_size)