Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

download_model.py 1.0 KB

You have to be logged in to leave a comment. Sign In
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
  1. import os
  2. import sys
  3. import requests
  4. from tqdm import tqdm
  5. if len(sys.argv) != 2:
  6. print('You must enter the model name as a parameter, e.g.: download_model.py 124M')
  7. sys.exit(1)
  8. model = sys.argv[1]
  9. subdir = os.path.join('models', model)
  10. if not os.path.exists(subdir):
  11. os.makedirs(subdir)
  12. subdir = subdir.replace('\\','/') # needed for Windows
  13. for filename in ['checkpoint','encoder.json','hparams.json','model.ckpt.data-00000-of-00001', 'model.ckpt.index', 'model.ckpt.meta', 'vocab.bpe']:
  14. r = requests.get("https://storage.googleapis.com/gpt-2/" + subdir + "/" + filename, stream=True)
  15. with open(os.path.join(subdir, filename), 'wb') as f:
  16. file_size = int(r.headers["content-length"])
  17. chunk_size = 1000
  18. with tqdm(ncols=100, desc="Fetching " + filename, total=file_size, unit_scale=True) as pbar:
  19. # 1k for chunk_size, since Ethernet packet size is around 1500 bytes
  20. for chunk in r.iter_content(chunk_size=chunk_size):
  21. f.write(chunk)
  22. pbar.update(chunk_size)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...