{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "s7iq_p9RCron" }, "source": [ "# Introduction to 🤗 Diffusers\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this notebook, you'll train your first diffusion model to **generate images of cute butterflies 🦋.** Along the way, you'll learn about the core components of the 🤗 Diffusers library, which will provide a good foundation for the more advanced applications that we'll cover later in the course.\n", "\n", "Let's dive in!" ] }, { "cell_type": "markdown", "metadata": { "id": "s7iq_p9RCron" }, "source": [ "## What You Will Learn\n", "\n", "In this notebook you will:\n", "\n", "- See a powerful custom diffusion model pipeline in action (with information on how to make your own version)\n", "- Create your own mini pipeline by:\n", " - Recapping the core ideas behind diffusion models\n", " - Loading in data from the Hub for training\n", " - Exploring how we add noise to this data with a scheduler\n", " - Creating and training the UNet model\n", " - Putting the pieces together into a working pipeline\n", "- Edit and run a script for initializing longer training runs, that will handle\n", " - Multi-GPU training via 🤗 Accelerate\n", " - Experiment logging to track critical stats\n", " - Uploading the final model to the Hugging Face Hub\n", "\n", "❓If you have any questions, please post them on the `#diffusion-models-class` channel on the Hugging Face Discord server. If you haven't signed up yet, you can do so here: https://huggingface.co/join/discord" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Prerequisites\n", "\n", "Before diving into the notebook, you should:\n", "\n", "* 📖 Read the Unit 1 materials\n", "* 🤗 Create an account on the Hugging Face Hub. If you haven't done so yet, you can do so here: https://huggingface.co/join" ] }, { "cell_type": "markdown", "metadata": { "id": "zfA87mA93LLP" }, "source": [ "## Step 1: Setup" ] }, { "cell_type": "markdown", "metadata": { "id": "pCoVNJtLI9KT" }, "source": [ "Run the following cell to install the diffusers library as well as a few other requirements:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "id": "Jw6-w4TB_7wg" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Note: you may need to restart the kernel to use updated packages.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1108: The handshake operation timed out'))': /simple/diffusers/\n", "WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1108: The handshake operation timed out'))': /simple/diffusers/\n", "WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1108: The handshake operation timed out'))': /simple/diffusers/\n", "WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1108: The handshake operation timed out'))': /simple/diffusers/\n", "WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1108: The handshake operation timed out'))': /simple/diffusers/\n", "ERROR: Could not find a version that satisfies the requirement diffusers (from versions: none)\n", "ERROR: No matching distribution found for diffusers\n" ] } ], "source": [ "%pip install -qq -U diffusers datasets transformers accelerate ftfy pyarrow==9.0.0" ] }, { "cell_type": "markdown", "metadata": { "id": "QJfU9oqZDscp" }, "source": [ "Next, head over to https://huggingface.co/settings/tokens and create an access token with write permission if you don't already have one:" ] }, { "cell_type": "markdown", "metadata": { "id": "oa0RbEt5D9sz" }, "source": [ "" ] }, { "cell_type": "markdown", "metadata": { "id": "9CDekhLrETH2" }, "source": [ "You can login with this token using the command line (`huggingface-cli login`) or by running the following cell:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 327 }, "id": "FlX4eeECD9HO", "outputId": "6e8d9cb7-d62b-43fb-cc09-35b8abc44b64" }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2c892369bb1d421d8bdfd5186e555f11", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HTML(value='