Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download script improvements #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions download_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from tqdm import tqdm

subdir = 'data'
if not os.path.exists(subdir):
os.makedirs(subdir)
subdir = subdir.replace('\\','/') # needed for Windows
os.makedirs(subdir, exist_ok=True)

for ds in [
'webtext',
Expand All @@ -18,12 +16,19 @@
for split in ['train', 'valid', 'test']:
filename = ds + "." + split + '.jsonl'
r = requests.get("https://openaipublic.azureedge.net/gpt-2/output-dataset/v1/" + filename, stream=True)
r.raise_for_status()
file_size = int(r.headers["content-length"])
filepath = os.path.join(subdir, filename)
try:
if os.stat(filepath).st_size == file_size:
print('%s already exists and is the expected %d bytes, not redownloading' % (filepath, file_size))
r.close()
continue
except OSError: # likely "file not found" or similar
pass

with open(os.path.join(subdir, filename), 'wb') as f:
file_size = int(r.headers["content-length"])
chunk_size = 1000
with open(filepath, 'wb') as f:
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):
for chunk in r.iter_content(chunk_size=4194304):
f.write(chunk)
pbar.update(chunk_size)
pbar.update(len(chunk))