fast.ai offers a couple of excellent, free courses online, complete with Jupyter notebooks, video lectures by Jeremy Howard, and an online forum. There are 2 versions of deep learning part 1: an older course (coupled with video lectures, running on the old version of fast.ai library) and a newer course (no accompanying video lectures yet, running on the new version of fast.ai library).
Which version are you running on?
If we find cats and dogs in the first lesson, we know we are on the older course. If the first lesson is lesson1-pets.ipynb, we know we are on the newer course.
On paperspace, clicking CREATE NOTEBOOK would lead us to Public Containers where we have the choice of the old and the new:
- Paperspace + Fast.AI 0.7.x
- Fast.ai 1.0 / PyTorch 1.0 BETA
The older version
The older library-course version has a directory structure in the form of courses/dl1/*.ipynb, where dl stands for for deep learning. These notebooks run on the older fast.ai library (version 0.7.x or something like that, depending on where, when and how it was downloaded). These notebooks by default run on the older fast.ai library, even as the newer library is also present in the bundle, because there is a symbolic link from the directory where the notebooks sit:
~/fastai-master/courses/dl1$ ls -l | grep fastai
lrwxrwxrwx 1 kid kid 16 Nov 20 19:25 fastai -> ../../old/fastai
fastai-master/old/fastai is the directory for the older fast.ai library. It contains the python files we will be importing from:
~/fastai-master/courses/dl1$ ls fastai
adaptive_softmax.py imports.py metrics.py sgdr.py column_data.py initializers.py model.py structured.py conv_learner.py init.py models swa.py
core.py io.py nlp.py text.py dataloader.py layer_optimizer.py plots.py torch_imports.py dataset.py layers.py pycache torchqrnn
executors.py learner.py rnn_reg.py transforms_pil.py fp16.py lm_rnn.py rnn_train.py transforms.py images lsuv_initializer.py set_spawn.py
The newer version
The newer course-library version has a directory structure in the form of course-v3/nbs/dl1/*.ipynb. These notebooks run on a newer version of fast.ai library (version 1.0). The fastai-master/fastai directory contains the library. Note that even the filenames differ from the earlier version:
~/fastai-master/fastai$ ls
basic_data.py collab.py gen_doc metrics.py torch_core.py vision basic_train.py core.py imports pycache train.py widgets
callback.py data_block.py init.py tabular
utils callbacks datasets.py layers.py
text version.py
Curiosity / confusion / frustration
Learners who attempted both versions, at some point, can start feeling quite frustrated and/or confused, with Jupyter Notebooks crashing on them eg:
- Confusion about cycle_len
- Learn.summary() equivalent in v3?
- Sched -> recorder?
- FastAi installation problem
- Fastai v1 install issues thread
- Really frustrating experience with fastai
- Lesson 4 IMDB: can’t run
- Lesson 4 IMDB Test Part Fails
where we get errors such as:
RuntimeError: shape ‘[1000000, 1]’ is invalid for input of size 2000
NameError: name 'LanguageModelData' is not defined
AttributeError: Can't get attribute '_rebuild_tensor_v2' on <module 'torch._utils' from
ModuleNotFoundError: No module named 'dataclasses'
Solution 1
The simplest solution is to keep two separate instances (on Paperspace, Google Cloud Platform, Amazon AWS or whatever): one for fast.ai 0.7 and another for fast.ai 1.0. The inconvenience is that we would need to switch between the two separate instances.
Solution 2
Here is a solution to be able to run both library versions and both course versions within the same instance. Create two Conda environments, one for each. We may then be able to switch between the two anytime, just by clicking on our Jupyter Notebooks (as selections under the New pull-down menu; also as selections under the Change kernel pull-down menu). Here are the steps:
- Take a snapshot of the original Jupyter kernels, Conda environments and installed packages; save the snapshot in a file named before.txt (or any name you like):
jupyter kernelspec list > before.txt
conda info --envs >> before.txt
conda list --explicit >> before.txt
- Create a new Conda environment named fastai0 (or any name you like). We need Python 3.6 (neither 3.5 nor 3.7 would work). Go into the new Conda environment and get Jupyter to register the new kernel:
conda create -n fastai0 python=3.6 ipykernel
conda activate fastai0
TISPATH=`which python`
sudo $TISPATH -m ipykernel install --name fastai0
- Make a copy of the old course and place it in your working directory, then change into the working directory. If your directory structure differs, just replace the path with yours. The following is given according to the default set up on Google Cloud Platform.
cp -rp /opt/anaconda3/src/fastai/courses /home/jupyter/tutorials/fastai/
cd /home/jupyter/tutorials/fastai/courses/dl1/
- The symbolic link for fastai is relative, so after making the copy and moving elsewher it will be pointing to nowhere. So we need to put it right:
rm fastai
ln -s /opt/anaconda3/src/fastai/old/fastai
- Install pytorch, torchvision and cuda92 (for GPU) from pytorch channel. Install fastai from fastai channel. Then downgrade torch to version 0.4.1 (otherwise the old fastai version won’t run).
conda install -c pytorch pytorch torchvision cuda92
conda install -c fastai fastai
pip install torch==0.4.1
- Install the remaining Python packages to be imported in the Jupyter notebooks during various lessons. We use conda where available; otherwise pip:
conda install bcolz opencv seaborn python-graphviz ipywidgets keras feedparser
pip install sklearn_pandas isoweek pandas_summary torchtext scikit-image
We are good to go!
thank you, for your help, we got stuck on this.
That’s great – have fun!