{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#export\n", "from local.test import *\n", "from local.data.all import *\n", "from local.optimizer import *\n", "from local.learner import *\n", "from torch.utils.data import TensorDataset" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# default_exp test_utils" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Synthetic Learner\n", "\n", "> For quick testing of the training loop and Callbacks" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#export\n", "from torch.utils.data import TensorDataset\n", "\n", "def synth_dbunch(a=2, b=3, bs=16, n_train=10, n_valid=2, cuda=False):\n", " def get_data(n):\n", " x = torch.randn(bs*n, 1)\n", " return TensorDataset(x, a*x + b + 0.1*torch.randn(bs*n, 1))\n", " train_ds = get_data(n_train)\n", " valid_ds = get_data(n_valid)\n", " tfms = Cuda() if cuda else None\n", " train_dl = TfmdDL(train_ds, bs=bs, shuffle=True, after_batch=tfms, num_workers=0)\n", " valid_dl = TfmdDL(valid_ds, bs=bs, after_batch=tfms, num_workers=0)\n", " return DataBunch(train_dl, valid_dl)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#export\n", "class RegModel(Module):\n", " def __init__(self): self.a,self.b = nn.Parameter(torch.randn(1)),nn.Parameter(torch.randn(1))\n", " def forward(self, x): return x*self.a + self.b" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# export\n", "@delegates(Learner.__init__)\n", "def synth_learner(n_trn=10, n_val=2, cuda=False, lr=1e-3, data=None, **kwargs):\n", " if data is None: data = synth_dbunch(n_train=n_trn,n_valid=n_val, cuda=cuda)\n", " return Learner(data, RegModel(), lr=lr, loss_func=MSELossFlat(),\n", " opt_func=partial(SGD, mom=0.9), **kwargs)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## - Export" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Converted 00_test.ipynb.\n", "Converted 01_core.ipynb.\n", "Converted 01a_torch_core.ipynb.\n", "Converted 02_script.ipynb.\n", "Converted 03_dataloader.ipynb.\n", "Converted 04_transform.ipynb.\n", "Converted 05_data_core.ipynb.\n", "Converted 06_data_transforms.ipynb.\n", "Converted 07_vision_core.ipynb.\n", "Converted 08_pets_tutorial.ipynb.\n", "Converted 09_vision_augment.ipynb.\n", "Converted 11_layers.ipynb.\n", "Converted 11a_vision_models_xresnet.ipynb.\n", "Converted 12_optimizer.ipynb.\n", "Converted 13_learner.ipynb.\n", "Converted 14_callback_schedule.ipynb.\n", "Converted 14a_callback_data.ipynb.\n", "Converted 15_callback_hook.ipynb.\n", "Converted 16_callback_progress.ipynb.\n", "Converted 17_callback_tracker.ipynb.\n", "Converted 18_callback_fp16.ipynb.\n", "Converted 19_callback_mixup.ipynb.\n", "Converted 20_metrics.ipynb.\n", "Converted 21_tutorial_imagenette.ipynb.\n", "Converted 22_vision_learner.ipynb.\n", "Converted 23_tutorial_transfer_learning.ipynb.\n", "Converted 30_text_core.ipynb.\n", "Converted 31_text_data.ipynb.\n", "Converted 32_text_models_awdlstm.ipynb.\n", "Converted 33_text_models_core.ipynb.\n", "Converted 34_callback_rnn.ipynb.\n", "Converted 35_tutorial_wikitext.ipynb.\n", "Converted 36_text_models_qrnn.ipynb.\n", "Converted 37_text_learner.ipynb.\n", "Converted 38_tutorial_ulmfit.ipynb.\n", "Converted 40_tabular_core.ipynb.\n", "Converted 41_tabular_model.ipynb.\n", "Converted 42_tabular_rapids.ipynb.\n", "Converted 50_data_block.ipynb.\n", "Converted 90_notebook_core.ipynb.\n", "Converted 91_notebook_export.ipynb.\n", "Converted 92_notebook_showdoc.ipynb.\n", "Converted 93_notebook_export2html.ipynb.\n", "Converted 94_notebook_test.ipynb.\n", "Converted 95_index.ipynb.\n", "Converted 96_data_external.ipynb.\n", "Converted 97_utils_test.ipynb.\n", "Converted notebook2jekyll.ipynb.\n", "Converted tmp.ipynb.\n" ] } ], "source": [ "#hide\n", "from local.notebook.export import *\n", "notebook2script(all_fs=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 2 }