Base Classes for Diffusers Integration
The base callback classes for integration with Diffusers.
BaseDiffusersCallback
Bases: ABC
Base callback for 🧨 Diffusers
logging the results of a
DiffusionPipeline
generation to Weights & Biases.
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. |
50
|
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/base/base_callback.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 |
|
__call__(step, timestep, latents, end_experiment=True)
A function that will be called every callback_steps
steps during
inference with the diffusers.DiffusionPipeline
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step |
int
|
The current step of the inference. |
required |
timestep |
int
|
The current timestep of the inference. |
required |
latents |
FloatTensor
|
The latent tensor used to generate the image. |
required |
end_experiment |
bool
|
Whether to end the experiment automatically or not after the pipeline is executed. |
True
|
Source code in wandb_addons/diffusers/callbacks/base/base_callback.py
at_initial_step()
A function that will be called at the initial step of the denoising loop during inference.
build_wandb_table()
Specifies the columns of the wandb table if not in weave mode. This function is called automatically when the callback is initialized.
Source code in wandb_addons/diffusers/callbacks/base/base_callback.py
end_experiment()
Ends the experiment. This function is called automatically at the end of
__call__
the parameter end_experiment
is set to True
.
Source code in wandb_addons/diffusers/callbacks/base/base_callback.py
generate(latents)
abstractmethod
Generate images from latents. This method must be implemented in the child class.
initialize_wandb(wandb_project, wandb_entity)
Initializes the wandb run if not already initialized. If weave_mode
is
True
, then a StreamTable is
initialized instead of a wandb run. This function is called automatically when
the callback is initialized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wandb_project |
str
|
The name of the W&B project. |
required |
wandb_entity |
str
|
The name of the W&B entity. |
required |
Source code in wandb_addons/diffusers/callbacks/base/base_callback.py
populate_table_row(prompt, negative_prompt, image)
Populates the table row with the prompt, negative prompt, the generated image, and the configs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt |
str
|
The prompt to guide the image generation. |
required |
negative_prompt |
str
|
The prompt not to guide the image generation. |
required |
image |
Image
|
The generated image. |
required |
Source code in wandb_addons/diffusers/callbacks/base/base_callback.py
update_configs()
Update the configs as a state of the callback. This function is called inside
initialize_wandb()
.
Source code in wandb_addons/diffusers/callbacks/base/base_callback.py
BaseImage2ImageCallback
Bases: BaseDiffusersCallback
Base callback for 🧨 Diffusers
logging the results of a
DiffusionPipeline
for image2image translation task to Weights & Biases.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pipeline |
DiffusionPipeline
|
The |
required |
prompt |
Union[str, List[str]]
|
The prompt or prompts to guide the image generation. |
required |
input_images |
PipelineImageInput
|
The input image, numpy array or tensor
representing an image batch to be used as the starting point. For both numpy
array and pytorch tensor, the expected value range is between [0, 1] If it's
a tensor or a list or tensors, the expected shape should be |
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. |
50
|
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/base/base_image_to_image_callback.py
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 |
|
__call__(step, timestep, latents, end_experiment=True)
A function that will be called every callback_steps
steps during
inference with the diffusers.DiffusionPipeline
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step |
int
|
The current step of the inference. |
required |
timestep |
int
|
The current timestep of the inference. |
required |
latents |
FloatTensor
|
The latent tensor used to generate the image. |
required |
end_experiment |
bool
|
Whether to end the experiment automatically or not after the pipeline is executed. |
True
|
Source code in wandb_addons/diffusers/callbacks/base/base_image_to_image_callback.py
build_wandb_table()
Specifies the columns of the wandb table if not in weave mode. This function is called automatically when the callback is initialized.
Source code in wandb_addons/diffusers/callbacks/base/base_image_to_image_callback.py
initialize_wandb(wandb_project, wandb_entity)
Initializes the wandb run if not already initialized. If weave_mode
is
True
, then a StreamTable is
initialized instead of a wandb run. This function is called automatically when
the callback is initialized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wandb_project |
str
|
The name of the W&B project. |
required |
wandb_entity |
str
|
The name of the W&B entity. |
required |
Source code in wandb_addons/diffusers/callbacks/base/base_image_to_image_callback.py
populate_table_row(input_image, prompt, negative_prompt, image)
Populates the table row with the input image, prompt, negative prompt, the generated image, and the configs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_image |
Image
|
The input image.s |
required |
prompt |
str
|
The prompt to guide the image generation. |
required |
negative_prompt |
str
|
The prompt not to guide the image generation. |
required |
image |
Image
|
The generated image. |
required |
Source code in wandb_addons/diffusers/callbacks/base/base_image_to_image_callback.py
postprocess_input_images(input_images)
Postprocess input images to be logged to the W&B Table/StreamTable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_images |
Union[Tensor, Image, array]
|
The input images to be postprocessed. |
required |
Source code in wandb_addons/diffusers/callbacks/base/base_image_to_image_callback.py
BaseMultiPipelineCallback
Bases: BaseDiffusersCallback
Base callback for 🧨 Diffusers
logging the results of multiple
DiffusionPipeline
s
to Weights & Biases.
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. |
50
|
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/base/base_multi_pipeline_callback.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 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 |
|
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
|
Source code in wandb_addons/diffusers/callbacks/base/base_multi_pipeline_callback.py
at_initial_step()
A function that will be called at the initial step of the denoising loop during inference.
build_wandb_table()
Specifies the columns of the wandb table if not in weave mode. This function is called automatically when the callback is initialized.
Source code in wandb_addons/diffusers/callbacks/base/base_multi_pipeline_callback.py
end_experiment()
Ends the experiment. This function is called automatically at the end of
__call__
the parameter end_experiment
is set to True
.
Source code in wandb_addons/diffusers/callbacks/base/base_multi_pipeline_callback.py
populate_table_row(prompt, negative_prompt, image)
Populates the table row with the prompt, negative prompt, the generated image, and the configs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt |
str
|
The prompt to guide the image generation. |
required |
negative_prompt |
str
|
The prompt not to guide the image generation. |
required |
image |
Image
|
The generated image. |
required |
Source code in wandb_addons/diffusers/callbacks/base/base_multi_pipeline_callback.py
update_configs()
Update the configs as a state of the callback. This function is called inside
initialize_wandb()
. In this function, the configs regarding the base pipeline
are updated as well.