Callbacks for 🧨 Diffusers pipelines for DeepFloyd IF
Callbacks for logging experiment details, configs and generated images for the DeepFloyd IF pipelines from Diffusers 🧨 pipelines to your Weights & Biases workspace.
Callback | Run-in-Colab | WandB Run |
---|---|---|
DeepFloyd IF |
IFCallback
Bases: BaseMultiPipelineCallback
Callback for logging the resulst of a text-to-image workflow with DeepFloyd IF to Weights & Biases.
Features:
- The callback automatically logs basic configs like prompt, negative prompt,
etc. along with the generated image in a
wandb.Table
. - The callback also logs configs for both the experiment as well as pipelines with the wandb run.
- No need to initialize a run, the callback automatically initialized and ends runs gracefully.
- Supports logging multiple stages of a workflow using a single callback.
Example usage:
You can fine an example notebook here.
import gc
from functools import partial
import torch
from diffusers import IFPipeline, IFSuperResolutionPipeline, StableDiffusionUpscalePipeline
from wandb_addons.diffusers import IFCallback
# Stage 1
pipeline_1 = IFPipeline.from_pretrained(
"DeepFloyd/IF-I-XL-v1.0", variant="fp16", torch_dtype=torch.float16
)
pipeline_1.enable_model_cpu_offload()
prompt = 'a photo of a smiling bee wearing a yellow hoodie and blue sunglasses standing in front of the eiffel tower holding a sign that says "Weights and Biases"'
prompt_embeds, negative_embeds = pipeline_1.encode_prompt(prompt)
num_images_per_prompt = 2
num_inference_steps = 100
configs = {"guidance_scale": 7.0}
callback = IFCallback(
pipeline=pipeline_1,
prompt=prompt,
wandb_project="diffusers-2",
wandb_entity="geekyrakshit",
weave_mode=False,
num_inference_steps=num_inference_steps,
num_images_per_prompt=num_images_per_prompt,
configs=configs
)
image = pipeline_1(
prompt_embeds=prompt_embeds,
negative_prompt_embeds=negative_embeds,
output_type="pt",
# Do not end the experiment after the first stage
callback=partial(callback, end_experiment=False),
**configs,
).images
# Stage 2
pipeline_2 = IFSuperResolutionPipeline.from_pretrained(
"DeepFloyd/IF-II-L-v1.0",
text_encoder=None,
variant="fp16",
torch_dtype=torch.float16
)
pipeline_2.enable_model_cpu_offload()
num_inference_steps = 50
callback.add_stage(pipeline_2, num_inference_steps=num_inference_steps)
image = pipeline_2(
image=image,
prompt_embeds=prompt_embeds,
negative_prompt_embeds=negative_embeds,
num_inference_steps=num_inference_steps,
output_type="pt",
callback=partial(callback, end_experiment=False),
).images
# Upscale stage
safety_modules = {
"feature_extractor": pipeline_1.feature_extractor,
"safety_checker": pipeline_1.safety_checker,
"watermarker": pipeline_1.watermarker,
}
pipeline_3 = StableDiffusionUpscalePipeline.from_pretrained(
"stabilityai/stable-diffusion-x4-upscaler",
**safety_modules,
torch_dtype=torch.float16
)
pipeline_3.enable_model_cpu_offload()
num_inference_steps = 75
callback.add_stage(
pipeline_3, num_inference_steps=num_inference_steps, stage_name="Upscale"
)
image = pipeline_3(
prompt=prompt,
image=image,
noise_level=100,
num_inference_steps=num_inference_steps,
callback=callback,
).images
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pipeline |
DiffusionPipeline
|
The |
required |
prompt |
Union[str, List[str]]
|
The prompt or prompts to guide the image generation. |
required |
wandb_project |
Optional[str]
|
The name of the project where you're sending the new run. The project is not necessary to be specified unless the run has automatically been initiatlized before the callback is defined. |
required |
wandb_entity |
Optional[str]
|
An entity is a username or team name where you're sending runs. This entity must exist before you can send runs there, so make sure to create your account or team in the UI before starting to log runs. If you don't specify an entity, the run will be sent to your default entity, which is usually your username. Change your default entity in your settings under "default location to create new projects". |
None
|
weave_mode |
bool
|
Whether to use log to a
weave board instead of W&B dashboard
or not. The weave mode logs the configs, generated images and timestamp in a
|
False
|
num_inference_steps |
int
|
The number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference. |
100
|
num_images_per_prompt |
Optional[int]
|
The number of images to generate per prompt. |
1
|
negative_prompt |
Optional[Union[str, List[str]]]
|
The prompt or prompts not
to guide the image generation. Ignored when not using guidance
(i.e., ignored if |
None
|
initial_stage_name |
Optional[str]
|
The name of the initial stage. If not
specified, it would be set to |
None
|
configs |
Optional[Dict]
|
Additional configs for the experiment you want to
sync, for example, for example, |
None
|
Source code in wandb_addons/diffusers/callbacks/deepfloyd_if.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
add_stage(pipeline, num_inference_steps=None, stage_name=None, configs=None)
Add a new stage to the callback to log the results of a new pipeline in a multi-pipeline workflow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pipeline |
DiffusionPipeline
|
The |
required |
num_inference_steps |
Optional[int]
|
The number of denoising steps for the new stage. More denoising steps usually lead to a higher quality image at the expense of slower inference. |
None
|
stage_name |
Optional[str]
|
The name of the new stage. If not specified,
it would be set to |
None
|
configs |
Optional[Dict]
|
Additional configs for the new stage you want to
sync, for example, for example, |
None
|