Skip to content

Commit ed0dedc

Browse files
committed
update download stuff
1 parent 8eb6793 commit ed0dedc

File tree

5 files changed

+29
-51
lines changed

5 files changed

+29
-51
lines changed

Dockerfile.cpu

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
FROM tensorflow/tensorflow:1.12.0-py3
22

33
ENV LANG=C.UTF-8
4-
RUN mkdir /gpt-2
4+
RUN mkdir /gpt-2
55
WORKDIR /gpt-2
6-
COPY requirements.txt download_model.sh /gpt-2/
7-
RUN apt-get update && \
8-
apt-get install -y curl && \
9-
sh download_model.sh 117M
10-
RUN pip3 install -r requirements.txt
11-
126
ADD . /gpt-2
7+
RUN pip3 install -r requirements.txt
8+
RUN python3 download_model.py 117M

Dockerfile.gpu

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ ENV NVIDIA_VISIBLE_DEVICES=all \
1212

1313
RUN mkdir /gpt-2
1414
WORKDIR /gpt-2
15-
COPY requirements.txt download_model.sh /gpt-2/
16-
RUN apt-get update && \
17-
apt-get install -y curl && \
18-
sh download_model.sh 117M
19-
RUN pip3 install -r requirements.txt
20-
2115
ADD . /gpt-2
16+
RUN pip3 install -r requirements.txt
17+
RUN python3 download_model.py 117M

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ Then, follow instructions for either native or Docker installation.
1717

1818
### Native Installation
1919

20-
Download the model data
21-
```
22-
sh download_model.sh 117M
23-
```
24-
25-
The remaining steps can optionally be done in a virtual environment using tools such as `virtualenv` or `conda`.
20+
All steps can optionally be done in a virtual environment using tools such as `virtualenv` or `conda`.
2621

2722
Install tensorflow 1.12 (with GPU support, if you have a GPU and want everything to run faster)
2823
```
@@ -38,6 +33,11 @@ Install other python packages:
3833
pip3 install -r requirements.txt
3934
```
4035

36+
Download the model data
37+
```
38+
python3 download_model.py 117M
39+
```
40+
4141
### Docker Installation
4242

4343
Build the Dockerfile and tag the created image as `gpt-2`:

download_model.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
#!/usr/bin/env python
21
import os
32
import sys
43
import requests
54
from tqdm import tqdm
65

7-
if len(sys.argv)!=2:
6+
if len(sys.argv) != 2:
87
print('You must enter the model name as a parameter, e.g.: download_model.py 117M')
98
sys.exit(1)
9+
1010
model = sys.argv[1]
11-
#Create directory if it does not exist already, then do nothing
12-
if not os.path.exists('models/'+model):
13-
os.makedirs('models/'+model)
14-
#download all the files
11+
12+
subdir = os.path.join('models', model)
13+
if not os.path.exists(subdir):
14+
os.makedirs(subdir)
15+
1516
for filename in ['checkpoint','encoder.json','hparams.json','model.ckpt.data-00000-of-00001', 'model.ckpt.index', 'model.ckpt.meta', 'vocab.bpe']:
16-
r = requests.get("https://storage.googleapis.com/gpt-2/models/"+model+"/"+filename,stream=True)
17-
#wb flag required for windows
18-
with open('models/'+model+'/'+filename,'wb') as currentFile:
19-
fileSize = int(r.headers["content-length"])
20-
with tqdm(ncols=100,desc="Fetching "+filename,total=fileSize,unit_scale=True) as pbar:
21-
#went for 1k for chunk_size. Motivation -> Ethernet packet size is around 1500 bytes.
22-
for chunk in r.iter_content(chunk_size=1000):
23-
currentFile.write(chunk)
24-
pbar.update(1000)
17+
18+
r = requests.get("https://storage.googleapis.com/gpt-2/" + subdir + "/" + filename, stream=True)
19+
20+
with open(os.path.join(subdir, filename), 'wb') as f:
21+
file_size = int(r.headers["content-length"])
22+
chunk_size = 1000
23+
with tqdm(ncols=100, desc="Fetching " + filename, total=file_size, unit_scale=True) as pbar:
24+
# 1k for chunk_size, since Ethernet packet size is around 1500 bytes
25+
for chunk in r.iter_content(chunk_size=chunk_size):
26+
f.write(chunk)
27+
pbar.update(chunk_size)

download_model.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)