{ "cells": [ { "cell_type": "raw", "metadata": {}, "source": [ "---\n", "skip_exec: true\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Lightning with fastai\n", "\n", "> Incrementally adding fastai goodness to your Lightning training" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We're going to use the MNIST training code from Lightning's 'Quick Start' (as at August 2020), converted to a module.\n", "\n", ":::{.callout-note}\n", "\n", "The source script for `migrating_lightning` is in the `examples` subdirectory of this folder if you checked out the `fastai` repo from git, or can be downloaded from [here](https://github.com/fastai/fastai/blob/master/nbs/examples/migrating_lightning.py) if you're using an online viewer such as Colab.\n", "\n", ":::" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from migrating_lightning import *\n", "\n", "from fastai.vision.all import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using fastai's training loop" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can use the Lightning module directly:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model = LitModel()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To use it in fastai, we first pull the DataLoaders from the module into a `DataLoaders` object:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = DataLoaders(model.train_dataloader(), model.val_dataloader()).cuda()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can now create a `Learner` and fit:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
epoch | \n", "train_loss | \n", "valid_loss | \n", "accuracy | \n", "time | \n", "
---|---|---|---|---|
0 | \n", "0.367197 | \n", "0.333293 | \n", "0.910800 | \n", "00:11 | \n", "