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

Create a .tar archive before copying a checkpoint folder to Google Drive #37

Merged
merged 2 commits into from
May 17, 2019
Merged
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: 21 additions & 2 deletions gpt_2_simple/gpt_2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import tarfile
import os
import json
import requests
Expand Down Expand Up @@ -448,18 +449,36 @@ def is_mounted():
assert os.path.isdir('/content/drive'), "You must mount first using mount_gdrive()"


def get_tarfile_name(checkpoint_folder):
"""Converts a folder path into a filename for a .tar archive"""
tarfile_name = checkpoint_folder.replace(os.path.sep, '_') + '.tar'

return tarfile_name


def copy_checkpoint_to_gdrive(checkpoint_folder=os.path.join('checkpoint', 'run1')):
"""Copies the checkpoint folder to a mounted Google Drive."""
is_mounted()

shutil.copytree(checkpoint_folder, "/content/drive/My Drive/" + checkpoint_folder)
file_path = get_tarfile_name(checkpoint_folder)

# Reference: https://stackoverflow.com/a/17081026
with tarfile.open(file_path, 'w') as tar:
tar.add(checkpoint_folder)

shutil.copyfile(file_path, "/content/drive/My Drive/" + file_path)


def copy_checkpoint_from_gdrive(checkpoint_folder=os.path.join('checkpoint', 'run1')):
"""Copies the checkpoint folder from a mounted Google Drive."""
is_mounted()

shutil.copytree("/content/drive/My Drive/" + checkpoint_folder, checkpoint_folder)
file_path = get_tarfile_name(checkpoint_folder)

shutil.copyfile("/content/drive/My Drive/" + file_path, file_path)

with tarfile.open(file_path, 'r') as tar:
tar.extractall()


def copy_file_to_gdrive(file_path):
Expand Down