How to contribute a community pipeline
Last updated
Last updated
💡 Take a look at GitHub Issue for more context about why we’re adding community pipelines to help everyone easily share their work without being slowed down.
Community pipelines allow you to add any additional features you’d like on top of the . The main benefit of building on top of the DiffusionPipeline
is anyone can load and use your pipeline by only adding one more argument, making it super easy for the community to access.
This guide will show you how to create a community pipeline and explain how they work. To keep things simple, you’ll create a “one-step” pipeline where the UNet
does a single forward pass and calls the scheduler once.
You should start by creating a one_step_unet.py
file for your community pipeline. In this file, create a pipeline class that inherits from the to be able to load model weights and the scheduler configuration from the Hub. The one-step pipeline needs a UNet
and a scheduler, so you’ll need to add these as arguments to the __init__
function:
Copied
To ensure your pipeline and its components (unet
and scheduler
) can be saved with , add them to the register_modules
function:
Copied
Cool, the __init__
step is done and you can move to the forward pass now! 🔥
In the forward pass, which we recommend defining as __call__
, you have complete creative freedom to add whatever feature you’d like. For our amazing one-step pipeline, create a random image and only call the unet
and scheduler
once by setting timestep=1
:
Copied
That’s it! 🚀 You can now run this pipeline by passing a unet
and scheduler
to it:
Copied
Copied
Once it is merged, anyone with diffusers >= 0.4.0
installed can use this pipeline magically 🪄 by specifying it in the custom_pipeline
argument:
Copied
Copied
Take a look at the following table to compare the two sharing workflows to help you decide the best option for you:
usage
same
same
review process
open a Pull Request on GitHub and undergo a review process from the Diffusers team before merging; may be slower
upload directly to a Hub repository without any review; this is the fastest workflow
visibility
included in the official Diffusers repository and documentation
included on your HF Hub profile and relies on your own usage/promotion to gain visibility
💡 You can use whatever package you want in your community pipeline file - as long as the user has it installed, everything will work fine. Make sure you have one and only one pipeline class that inherits from DiffusionPipeline
because this is automatically detected.
It can be loaded with the custom_pipeline
argument.
The model weights and scheduler configuration are loaded from pretrained_model_name_or_path
.
The code that implements a feature in the community pipeline is defined in a pipeline.py
file.
Sometimes you can’t load all the pipeline components weights from an official repository. In this case, the other components should be passed directly to the pipeline:
Copied
The magic behind community pipelines is contained in the following code. It allows the community pipeline to be loaded from GitHub or the Hub, and it’ll be available to all 🧨 Diffusers packages.
Copied
But what’s even better is you can load pre-existing weights into the pipeline if the pipeline structure is identical. For example, you can load the weights into the one-step pipeline:
Open a Pull Request on the 🧨 Diffusers to add your awesome pipeline in one_step_unet.py
to the subfolder.
Another way to share your community pipeline is to upload the one_step_unet.py
file directly to your preferred on the Hub. Instead of specifying the one_step_unet.py
file, pass the model repository id to the custom_pipeline
argument:
A community pipeline is a class that inherits from which means: