Jeremy Howard, the founder of fastai, organized a series of live coding sessions covering the basics of git, bash, vim, tmux, and more, as a companion to the free fastai course on deep learning. Here is the playlist and the forum post.
Live coding 1
- intall WSL if on Windows (all commands below are typed in linux terminal in WSL)
alt + enterfor full screenpwdprint working directorywhichshows where a file ismkdirmakes a directorylslist stuffs-lahlong format all files human readabledf -hdisk freedu -sh *disk usage-ssummary of all subdirectories in.du -sh .disk usage of.
- conda-forge distribution as of september 2023, mambaforge/miniforge3 are the same.
-c conda-forgeis the default wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.shto download the distributionbash Miniforge3-Linux-x86_64.sh -bto install, where-bfor less intervention- install pytorch here
mamba install jupyter ipywidgetsalias jl="jupyter lab"add this command to the end of.bashrcto save alias for goodmamba install -c fastai fastai
Tip
Jeremy automated setup of conda in this file. To run it, one needs to add executable permission to user chmod u+x setup-conda.sh
Live coding 2
bash
cd -back to most recent directorypushd ~push current directory to a stack and change directory to~popdpop what’s in the stackctrl+dexit for most programctrl+uctrl+wctrl+actrl+emove cursor faster
tmux
tmuxctrl+bstart of a tmux command, then"split top-bottom%split left-rightzzoom in/outddetach, back to bashtmux aattach stuffs running in tmux from bash (everything remains until restart computer)
git (with ssh)
ssh-keygengenerates public/private rsa key pair (prompt where to save the file, by default it’s in~/.ssh)- login to github.com and upload public key
cat ~/.ssh/id_rsa.pub git clone git@github.com:fastai/fastbook.gitgit statusgit commit -am 'MESSAGE'git push
Live coding 3
bash
ln -s ONEsimlink ONE to here$PATHpaths that bash knows to run program
paperspace
pip install --user PACKAGEwill install PACKAGE to~/.local/lib/python3.*/site-packageswhich gets wiped after shutdownmv ~/.local /storage/.localthenln -s /storage/.local ~/to make it persistent (/storageis persistent across notebook instances)
jupyter lab
ctrl + shift + [change tabctrl + bhide side column%%debugexit withqshift + taborMETHOD?shows signatureMETHOD??shows source code
Live coding 4
Tip
Jeremy teaches how to write your first bash script. The job done via these scripts is to set up paperspace for persistent storage and configs across instances. The repo is here.
first script pre-run.sh
#!/usr/bin/env bash
pushd ~
mkdir -p /storage/cfg
if [ ! -e /storage/cfg/.conda ]; then
mamba create -yp /storage/cfg/.conda
fi
for p in .local .ssh .config .ipython .fastai .jupyter .conda .kaggle
do
if [ ! -e /storage/cfg/$p ]; then
mkdir /storage/cfg/$p
fi
rm -rf ~/$p
ln -s /storage/cfg/$p ~/
done
chmod 700 /storage/cfg/.ssh
for p in .git-credentials .gitconfig .bash_history
do
if [ ! -e /storage/cfg/$p ]; then
touch /storage/cfg/$p
fi
rm -rf ~/$p
ln -s /storage/cfg/$p ~/
done
popd
second script setup.sh
#!/usr/bin/env bash
mkdir /storage/cfg
cp pre-run.sh /storage/
cp .bash.local /storage/
echo install complete. please start a new instance
Live coding 5
bash
cat FILEdisplay filecat f1 f2 > combinedconcatcat f1 >> f2append
vim
iinsert modeescback to command mode- in command mode try
:qto quit:wqto write and quit - tutorial https://vim-adventures.com/
alternatively, type code . then edit/create file with VS code
Live coding 6
du -sh * | grep 'G'search ouput ofdu -sh *that containsGto identify directories larger than GBconda install universal-ctags- copy config files to Paperspace (they’ll be persistent if we’ve run the bash script before in live coding 4.)
- copy ssh keys to
~/.sshand change permissionschmod 644 ~/.ssh/id_rsa.pubchmod 600 ~/.ssh/id_rsa - first time git commit needs
~/.gitconfigto have name and email of the user, just follow the prompt.
- copy ssh keys to
Live coding 7
pip isntall --user kaggle
- pre-append
~/.bashrcwithexport PATH=~/.local/bin:$PATH source .bashrc- create
kaggle.jsonfile from kaggle website and copy it into~/.kaggle - navigate into
.kaggleandchmod 600 kaggle.json kaggle competitions donwnload -c NAME
Try time unzip -q BLA to see how long it takes to unzip.
nvidia-smi dmonif sm is low, this means i/o slow. Try- resize image
- move files to local (see
get_data.shbelow) - reduce augmentation
- change to CPU instance?
On paperspace, create get_data.sh in /notebooks (persistent)
#!/user/bin/env bash
cd
mkdir BLA
cd BLA
kaggle competitions donwnload -c NAME
unzip -q NAME