{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "AYV_dMVDxyc2", "pycharm": { "name": "#%% md\n" } }, "source": [ "[![Github](https://img.shields.io/github/stars/labmlai/annotated_deep_learning_paper_implementations?style=social)](https://github.com/labmlai/annotated_deep_learning_paper_implementations)\n", "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/labmlai/annotated_deep_learning_paper_implementations/blob/master/labml_nn/diffusion/ddpm/experiment.ipynb)\n", "\n", "## [Denoising Diffusion Probabilistic Models (DDPM)](https://nn.labml.ai/diffusion/ddpm/index.html)\n", "\n", "This notebook trains a DDPM based model on MNIST digits dataset." ] }, { "cell_type": "markdown", "metadata": { "id": "AahG_i2y5tY9", "pycharm": { "name": "#%% md\n" } }, "source": [ "### Install the packages" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "ZCzmCrAIVg0L", "outputId": "cf107fb2-4d50-4c67-af34-367624553421", "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "!pip install labml-nn --quiet" ] }, { "cell_type": "markdown", "metadata": { "id": "SE2VUQ6L5zxI", "pycharm": { "name": "#%% md\n" } }, "source": [ "### Imports" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "import torch\n", "import torch.nn as nn\n", "\n", "from labml import experiment\n", "from labml.configs import option\n", "from labml_nn.diffusion.ddpm.experiment import Configs" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "### Create an experiment" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "experiment.create(name=\"diffuse\", writers={'screen'})" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "### Configurations" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "configs = Configs()" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "Set experiment configurations and assign a configurations dictionary to override configurations" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "experiment.configs(configs, {\n", " 'dataset': 'MNIST',\n", " 'image_channels': 1,\n", " 'epochs': 5,\n", "})" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "Initializ" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "configs.init()" ] }, { "cell_type": "markdown", "metadata": { "id": "EvI7MtgJ61w5", "pycharm": { "name": "#%% md\n" } }, "source": [ "Set PyTorch models for loading and saving" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 255 }, "id": "GDlt7dp-5ALt", "outputId": "e7548e8f-c541-4618-dc5a-1597cae42003", "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "experiment.add_pytorch_models({'eps_model': configs.eps_model})" ] }, { "cell_type": "markdown", "metadata": { "id": "KJZRf8527GxL", "pycharm": { "name": "#%% md\n" } }, "source": [ "### Start the experiment and run the training loop." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "id": "aIAWo7Fw5DR8", "outputId": "db979785-bfe3-4eda-d3eb-8ccbe61053e5", "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "# Start the experiment\n", "with experiment.start():\n", " configs.run()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [] } ], "metadata": { "accelerator": "GPU", "colab": { "collapsed_sections": [], "name": "Denoising Diffusion Probabilistic Models (DDPM)", "provenance": [] }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.12" } }, "nbformat": 4, "nbformat_minor": 4 }