Created
March 26, 2020 04:18
-
-
Save mikewcasale/65c680eb50a815b68d40f8cf054317a4 to your computer and use it in GitHub Desktop.
t5 colab pt 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TODO(adarob): Add support for 2.x. | |
# %tensorflow_version 1.x | |
import datetime | |
import functools | |
import json | |
import os | |
import pprint | |
import random | |
import string | |
import sys | |
import tensorflow as tf | |
BASE_DIR = "gs://icol" #your Google Cloud Storage Bucket | |
if not BASE_DIR or BASE_DIR == "gs://": | |
raise ValueError("You must enter a BASE_DIR.") | |
DATA_DIR = os.path.join(BASE_DIR, "data") | |
MODELS_DIR = os.path.join(BASE_DIR, "models") | |
ON_CLOUD = True | |
if ON_CLOUD: | |
assert "COLAB_TPU_ADDR" in os.environ, "ERROR: Not connected to a TPU runtime; please see the first cell in this notebook for instructions!" | |
TPU_ADDRESS = "grpc://" + os.environ["COLAB_TPU_ADDR"] | |
TPU_TOPOLOGY = "2x2" | |
print("TPU address is", TPU_ADDRESS) | |
from google.colab import auth | |
auth.authenticate_user() | |
with tf.Session(TPU_ADDRESS) as session: | |
print('TPU devices:') | |
pprint.pprint(session.list_devices()) | |
# Upload credentials to TPU. | |
with open('/content/adc.json', 'r') as f: | |
auth_info = json.load(f) | |
tf.contrib.cloud.configure_gcs(session, credentials=auth_info) | |
# Now credentials are set for all future sessions on this TPU. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment