<meta charset="utf-8" /><meta http-equiv="content-security-policy" content=""><meta name="hf:doc:metadata" content="{&quot;local&quot;:&quot;diffusers-training-examples&quot;,&quot;sections&quot;:[{&quot;local&quot;:&quot;community&quot;,&quot;title&quot;:&quot;Community&quot;},{&quot;local&quot;:&quot;important-note&quot;,&quot;title&quot;:&quot;Important note&quot;}],&quot;title&quot;:&quot;🧨 Diffusers Training Examples&quot;}" data-svelte="svelte-1phssyn">
	<link rel="modulepreload" href="/docs/diffusers/pr_1170/en/_app/assets/pages/__layout.svelte-hf-doc-builder.css">
	<link rel="modulepreload" href="/docs/diffusers/pr_1170/en/_app/start-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/diffusers/pr_1170/en/_app/chunks/vendor-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/diffusers/pr_1170/en/_app/chunks/paths-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/diffusers/pr_1170/en/_app/pages/__layout.svelte-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/diffusers/pr_1170/en/_app/pages/training/overview.mdx-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/diffusers/pr_1170/en/_app/chunks/IconCopyLink-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/diffusers/pr_1170/en/_app/chunks/CodeBlock-hf-doc-builder.js"> 






<h1 class="relative group"><a id="diffusers-training-examples" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#diffusers-training-examples"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a>
	<span>🧨 Diffusers Training Examples
	</span></h1>

<p>Diffusers training examples are a collection of scripts to demonstrate how to effectively use the <code>diffusers</code> library
for a variety of use cases.</p>
<p><strong>Note</strong>: If you are looking for <strong>official</strong> examples on how to use <code>diffusers</code> for inference,
please have a look at <a href="https://github.com/huggingface/diffusers/tree/main/src/diffusers/pipelines" rel="nofollow">src/diffusers/pipelines</a></p>
<p>Our examples aspire to be <strong>self-contained</strong>, <strong>easy-to-tweak</strong>, <strong>beginner-friendly</strong> and for <strong>one-purpose-only</strong>.
More specifically, this means:</p>
<ul><li><strong>Self-contained</strong>: An example script shall only depend on “pip-install-able” Python packages that can be found in a <code>requirements.txt</code> file. Example scripts shall <strong>not</strong> depend on any local files. This means that one can simply download an example script, <em>e.g.</em> <a href="https://github.com/huggingface/diffusers/blob/main/examples/unconditional_image_generation/train_unconditional.py" rel="nofollow">train_unconditional.py</a>, install the required dependencies, <em>e.g.</em> <a href="https://github.com/huggingface/diffusers/blob/main/examples/unconditional_image_generation/requirements.txt" rel="nofollow">requirements.txt</a> and execute the example script.</li>
<li><strong>Easy-to-tweak</strong>: While we strive to present as many use cases as possible, the example scripts are just that - examples. It is expected that they won’t work out-of-the box on your specific problem and that you will be required to change a few lines of code to adapt them to your needs. To help you with that, most of the examples fully expose the preprocessing of the data and the training loop to allow you to tweak and edit them as required.</li>
<li><strong>Beginner-friendly</strong>: We do not aim for providing state-of-the-art training scripts for the newest models, but rather examples that can be used as a way to better understand diffusion models and how to use them with the <code>diffusers</code> library. We often purposefully leave out certain state-of-the-art methods if we consider them too complex for beginners.</li>
<li><strong>One-purpose-only</strong>: Examples should show one task and one task only. Even if a task is from a modeling
point of view very similar, <em>e.g.</em> image super-resolution and image modification tend to use the same model and training method, we want examples to showcase only one task to keep them as readable and easy-to-understand as possible.</li></ul>
<p>We provide <strong>official</strong> examples that cover the most popular tasks of diffusion models.
<em>Official</em> examples are <strong>actively</strong> maintained by the <code>diffusers</code> maintainers and we try to rigorously follow our example philosophy as defined above.
If you feel like another important example should exist, we are more than happy to welcome a <a href="https://github.com/huggingface/diffusers/issues/new?assignees=&labels=&template=feature_request.md&title=" rel="nofollow">Feature Request</a> or directly a <a href="https://github.com/huggingface/diffusers/compare" rel="nofollow">Pull Request</a> from you!</p>
<p>Training examples show how to pretrain or fine-tune diffusion models for a variety of tasks. Currently we support:</p>
<ul><li><a href="./unconditional_training">Unconditional Training</a></li>
<li><a href="./text2image">Text-to-Image Training</a></li>
<li><a href="./text_inversion">Text Inversion</a></li>
<li><a href="./dreambooth">Dreambooth</a></li></ul>
<table><thead><tr><th>Task</th>
<th>🤗 Accelerate</th>
<th align="center">🤗 Datasets</th>
<th align="center">Colab</th></tr></thead>
<tbody><tr><td><a href="./unconditional_training"><strong>Unconditional Image Generation</strong></a></td>
<td>✅</td>
<td align="center">✅</td>
<td align="center"><a href="https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/training_example.ipynb" rel="nofollow"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a></td></tr>
<tr><td><a href="./text2image"><strong>Text-to-Image fine-tuning</strong></a></td>
<td>✅</td>
<td align="center">✅</td>
<td align="center"></td></tr>
<tr><td><a href="./text_inversion"><strong>Textual Inversion</strong></a></td>
<td>✅</td>
<td align="center">-</td>
<td align="center"><a href="https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/sd_textual_inversion_training.ipynb" rel="nofollow"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a></td></tr>
<tr><td><a href="./dreambooth"><strong>Dreambooth</strong></a></td>
<td>✅</td>
<td align="center">-</td>
<td align="center"><a href="https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/sd_dreambooth_training.ipynb" rel="nofollow"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"></a></td></tr></tbody></table>
<h2 class="relative group"><a id="community" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#community"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a>
	<span>Community
	</span></h2>

<p>In addition, we provide <strong>community</strong> examples, which are examples added and maintained by our community.
Community examples can consist of both <em>training</em> examples or <em>inference</em> pipelines.
For such examples, we are more lenient regarding the philosophy defined above and also cannot guarantee to provide maintenance for every issue.
Examples that are useful for the community, but are either not yet deemed popular or not yet following our above philosophy should go into the <a href="https://github.com/huggingface/diffusers/tree/main/examples/community" rel="nofollow">community examples</a> folder. The community folder therefore includes training examples and inference pipelines.
<strong>Note</strong>: Community examples can be a <a href="https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22" rel="nofollow">great first contribution</a> to show to the community how you like to use <code>diffusers</code> 🪄.</p>
<h2 class="relative group"><a id="important-note" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#important-note"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a>
	<span>Important note
	</span></h2>

<p>To make sure you can successfully run the latest versions of the example scripts, you have to <strong>install the library from source</strong> and install some example-specific requirements. To do this, execute the following steps in a new virtual environment:</p>

	<div class="code-block relative"><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5   text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg>
	<div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div>
	Copied</div></button></div>
	<pre><!-- HTML_TAG_START -->git <span class="hljs-built_in">clone</span> https://github.com/huggingface/diffusers
<span class="hljs-built_in">cd</span> diffusers
pip install .<!-- HTML_TAG_END --></pre></div>
<p>Then cd in the example folder of your choice and run</p>

	<div class="code-block relative"><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5   text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg>
	<div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div>
	Copied</div></button></div>
	<pre><!-- HTML_TAG_START -->pip install -r requirements.txt<!-- HTML_TAG_END --></pre></div>


		<script type="module" data-hydrate="1r7mwt1">
		import { start } from "/docs/diffusers/pr_1170/en/_app/start-hf-doc-builder.js";
		start({
			target: document.querySelector('[data-hydrate="1r7mwt1"]').parentNode,
			paths: {"base":"/docs/diffusers/pr_1170/en","assets":"/docs/diffusers/pr_1170/en"},
			session: {},
			route: false,
			spa: false,
			trailing_slash: "never",
			hydrate: {
				status: 200,
				error: null,
				nodes: [
					import("/docs/diffusers/pr_1170/en/_app/pages/__layout.svelte-hf-doc-builder.js"),
						import("/docs/diffusers/pr_1170/en/_app/pages/training/overview.mdx-hf-doc-builder.js")
				],
				params: {}
			}
		});
	</script>
