Minimal helpers to run standalone Stable Diffusion experiments
Project description
The min_diffusion
library
This library was put together for a series of experiments on Classifier-free Guidance.
Install
pip install min_diffusion
How to use min_diffusion
The library has a single main class
MinimalDiffusion
.
This class takes three arguments:
model_name
device
dtype
model_name
is the string model name on the HuggingFace hub.
device
sets the hardware to run on.
dtype
is the torch.dtype
precision for the torch modules.
# import the library
from min_diffusion.core import MinimalDiffusion
Loading a sample model
Below is an example to load the openjourney model from PromptHero.
The model will be loaded in torch.float16
precision and placed on the
GPU.
# set the model to load and its options
model_name = 'prompthero/openjourney'
device = 'cuda'
dtype = torch.float16
Creating a
MinimalDiffusion
with these arguments:
# create the minimal diffusion pipeline
pipeline = MinimalDiffusion(model_name, device, dtype)
Loading the pipeline:
# load the pipeline
pipeline.load();
Enabling default unet attention slicing.
Generating an image
Below is an example text prompt for image generation.
Note the keyword
"mdjrny-v4 style"
at the start of the prompt. This is how theopenjourney
model creates images in the style of Midjourney v4.
# text prompt for image generations
prompt = "mdjrny-v4 style a photograph of an astronaut riding a horse"
Calling MinimalDiffusion
on the input text prompt
# generate the image
img = pipeline.generate(prompt);
Using the default Classifier-free Guidance.
0%| | 0/50 [00:00<?, ?it/s]
Here is the generated image:
# view the output image
img
Notes:
The pipeline assumes you have logged in to the HuggingFace hub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for min_diffusion-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86fee9e1321b7d69fb0b94f74cdc08e03cc4623643d321eed5c2be767d8c97ce |
|
MD5 | c1f94ccca7f7673558a9567e742025d6 |
|
BLAKE2b-256 | 7ae590da22e3302b05fce340f484216915a8d31f5cf98ca985081644fdc9d6ee |