Open In Colab

Notes about fastai_xla_extensions development setup

The fastai_xla_extensions project uses nbdev to build the package from Jupyter notebooks.

In order to contribute or update the package, the development environment must be setup to run on Colab, which provides access to TPUs.

The following steps are based on instructions from nbdev documentation on running nbdev on Colab.

Google Drive setup

Connect your Colab instance to your google drive

from google.colab import drive
drive.mount('/content/drive')
%cd /content/drive

Git setup

  1. Fork the main fastai_xla_extensions github repo on Github

  2. Clone the forked fastai_xla_extensions github repo

    • in the clone command below, replace the butchland user id with your own github user id
%cd /content/drive/MyDrive
!git clone https://github.com/butchland/fastai_xla_extensions.git
%cd /content
!ln -s /content/drive/MyDrive/fastai_xla_extensions fastai_xla_extensions

Install Pytorch XLA

!pip install -Uqq cloud-tpu-client==0.10 https://storage.googleapis.com/tpu-pytorch/wheels/torch_xla-1.7-cp36-cp36m-linux_x86_64.whl
     |████████████████████████████████| 133.6MB 77kB/s 
     |████████████████████████████████| 61kB 3.1MB/s 

Install fastai and other dependencies

!pip install -Uqq fastai==2.3.0 
!pip install -qqq nbdev

Import fastai_xla_extensions modules

%cd /content/fastai_xla_extensions
from fastai_xla_extensions.all import *
%cd /content

Run nbdev commands

%cd /content/fastai_xla_extensions
!nbdev_clean_nbs && nbdev_build_lib && nbdev_build_docs

Run git commands

Specify Github Credentials

Your github_id and github_repo should contain the information you previously used as your Github ID and repo when you forked the fastai_xla_extensions repo.

#@title Enter your github info {display-mode: "form"}
github_id = "" #@param {type: "string"}
user_email = ""  #@param {type: "string"}
real_name = "" #@param {type: "string"}

Check that the github ID, repo, email and name have been filled out

github_repo = 'fastai_xla_extensions'
if github_id == "" or github_repo == "" or user_email == "" or real_name == "":
    print("Rerun your notebook by pressing Cmd/Ctrl-F9 or menu Runtime/Run all")
    raise RuntimeError("Please enter your Github ID and Repo as well as your user email and name")
!git config --global user.name "{real_name}"
!git config --global user.email "{user_email}"
from pathlib import Path
if not (Path('/content')/github_repo).is_dir():
    print('You might have entered the wrong github credentials')
    raise RuntimeError(f'Could not download your github repo  https://github.com/{github_id}/{github_repo}.git')
%cd /content/{github_repo}

Run git commands to add your changes to your local repo.

# !git status
# !git add -all
# !git commit -m ""

Enter Github Password

Please enter your github password as requested

#@title {display-mode: "form"}
print('Please enter your password.')
import getpass
github_password = getpass.getpass()

Push changes to repo

#@title {display-mode: "form"}
!git config credential.helper store
!echo "https://{github_id}:{github_password}@github.com" > /root/.git-credentials
!git push
!rm -f /root/.git-credentials