In-place fastai specific errors to ease debugging
/mnt/d/lib/python3.7/site-packages/torch/cuda/ UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from (Triggered internally at  /pytorch/c10/cuda/CUDAFunctions.cpp:100.)
  return torch._C._cuda_getDeviceCount() > 0

This notebook contains a series of various errors that can be used when running with fastai. It should be noted here that there is no other imports or magic you need to do to use this section of the library other then: from fastdebug import *. It will automatically load in what's needed.

As a style choice, we are choosing to do the .* notation as this loads in not only all of our errors, but also replaces sections of fastai's code to inject some error handling (as we'll see later)

Error Types


loss_func_error(e:Exception, learn)

Error that should be run when there is an issue when working with the loss function

Raises with a message stating the shapes of the inputs and targs, and the error


callback_error(e:Exception, cb:str, event_name:str)

Raises an error from when a Callback event failed, showing what event, the name of the Callback and the trace


catch_pred_errors(e:Exception, model)

Catches any errors relating to prediction that are either related to the device or model layers. Else raise e


catch_loss_errors(e:Exception, learn)

Catches any errors that occur with the loss function and its calculation

Modifications and Enhancements to the fastai Source Code and Learner:


Learner.__init__(dls, model, loss_func=None, opt_func=Adam, lr=0.001, splitter=trainable_params, cbs=None, metrics=None, path=None, model_dir='models', wd=None, wd_bn_bias=False, train_bn=True, moms=(0.95, 0.85, 0.95), sanity_check=False, show_table=False)

Group together a model, some dls and a loss_func to handle training, potentially run a sanity check



Performs a short epoch and uses all the callbacks in on the CPU to ensure nothing is broken

With sanity_check, you can make sure that you've set everything up properly and you won't get any issues before pushing to the GPU. This allows you to quickly ensure that you won't get any CUDA device-assist errors, and that the whole training regiment will go well.



Raises an error when trying to load in a previous Learner and custom functions were not available in the namespace


load_learner(fname, cpu=True, pickle_module=pickle)

Load a Learner object in fname, optionally putting it on the cpu

We have a custom load_learner function here that can check if everything exported is available when bringing the model in, if not then it'll raise an explicit error