Callbacks for 🧨 Diffusers pipelines for Kandinsly
Callbacks for logging experiment details, configs and generated images for the Kandinsly family of pipelines from Diffusers 🧨 pipelines to your Weights & Biases workspace.
Callback | Run-in-Colab | WandB Run |
---|---|---|
Kandinsky v2.1 |
KandinskyCallback
Bases: BaseDiffusersCallback
Callback for 🧨 Diffusers logging
the results of a
KandinskyCombinedPipeline
generation 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.
Example usage:
You can fine an example notebook here.
import torch
from diffusers import KandinskyCombinedPipeline
from wandb_addons.diffusers import KandinskyCallback
pipe = KandinskyCombinedPipeline.from_pretrained(
"kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16
)
pipe = pipe.to("cuda")
prompt = [
"a photograph of an astronaut riding a horse",
"a photograph of a dragon"
]
negative_prompt = ["ugly, deformed", "ugly, deformed"]
num_images_per_prompt = 2
configs = {
"guidance_scale": 4.0,
"height": 512,
"width": 512,
"prior_guidance_scale": 4.0,
"prior_num_inference_steps": 25,
}
# Create the WandB callback for StableDiffusionPipeline
callback = KandinskyCallback(
pipe,
prompt=prompt,
negative_prompt=negative_prompt,
wandb_project="diffusers",
num_images_per_prompt=num_images_per_prompt,
configs=configs,
)
# Add the callback to the pipeline
image = pipe(
prompt,
negative_prompt=negative_prompt,
callback=callback,
num_images_per_prompt=num_images_per_prompt,
**configs,
)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pipeline |
Union[DiffusionPipeline, KandinskyCombinedPipeline, KandinskyPipeline]
|
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
|
configs |
Optional[Dict]
|
Additional configs for the experiment you want to
sync, for example, for example, |
None
|
Source code in wandb_addons/diffusers/callbacks/kandinsky.py
9 10 11 12 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 |
|