SD3ControlNetModel¶
SD3ControlNetModel is an implementation of ControlNet for Stable Diffusion 3.
The ControlNet model was introduced in Adding Conditional Control to Text-to-Image Diffusion Models by Lvmin Zhang, Anyi Rao, Maneesh Agrawala. It provides a greater degree of control over text-to-image generation by conditioning the model on additional inputs such as edge maps, depth maps, segmentation maps, and keypoints for pose detection.
The abstract from the paper is:
We present ControlNet, a neural network architecture to add spatial conditioning controls to large, pretrained text-to-image diffusion models. ControlNet locks the production-ready large diffusion models, and reuses their deep and robust encoding layers pretrained with billions of images as a strong backbone to learn a diverse set of conditional controls. The neural architecture is connected with "zero convolutions" (zero-initialized convolution layers) that progressively grow the parameters from zero and ensure that no harmful noise could affect the finetuning. We test various conditioning controls, eg, edges, depth, segmentation, human pose, etc, with Stable Diffusion, using single or multiple conditions, with or without prompts. We show that the training of ControlNets is robust with small (<50k) and large (>1m) datasets. Extensive results show that ControlNet may facilitate wider applications to control image diffusion models.
Loading from the original format¶
By default the SD3ControlNetModel
should be loaded with ModelMixin.from_pretrained
.
from mindone.diffusers import StableDiffusion3ControlNetPipeline
from mindone.diffusers.models import SD3ControlNetModel, SD3MultiControlNetModel
controlnet = SD3ControlNetModel.from_pretrained("InstantX/SD3-Controlnet-Canny")
pipe = StableDiffusion3ControlNetPipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", controlnet=controlnet)
mindone.diffusers.SD3ControlNetModel
¶
Bases: ModelMixin
, ConfigMixin
, PeftAdapterMixin
Source code in mindone/diffusers/models/controlnet_sd3.py
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 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
mindone.diffusers.SD3ControlNetModel.attn_processors: Dict[str, AttentionProcessor]
property
¶
RETURNS | DESCRIPTION |
---|---|
Dict[str, AttentionProcessor]
|
|
Dict[str, AttentionProcessor]
|
indexed by its weight name. |
mindone.diffusers.SD3ControlNetModel.construct(hidden_states, controlnet_cond, conditioning_scale=1.0, encoder_hidden_states=None, pooled_projections=None, timestep=None, joint_attention_kwargs=None, return_dict=False)
¶
The [SD3Transformer2DModel
] forward method.
PARAMETER | DESCRIPTION |
---|---|
hidden_states |
Input
TYPE:
|
controlnet_cond |
The conditional input tensor of shape
TYPE:
|
conditioning_scale |
The scale factor for ControlNet outputs.
TYPE:
|
encoder_hidden_states |
Conditional embeddings (embeddings computed from the input conditions such as prompts) to use.
TYPE:
|
pooled_projections |
Embeddings projected from the embeddings of input conditions.
TYPE:
|
timestep |
Used to indicate denoising step.
TYPE:
|
joint_attention_kwargs |
A kwargs dictionary that if specified is passed along to the
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tensor, Transformer2DModelOutput]
|
If |
Union[Tensor, Transformer2DModelOutput]
|
|
Source code in mindone/diffusers/models/controlnet_sd3.py
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 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
mindone.diffusers.SD3ControlNetModel.enable_forward_chunking(chunk_size=None, dim=0)
¶
Sets the attention processor to use feed forward chunking.
PARAMETER | DESCRIPTION |
---|---|
chunk_size |
The chunk size of the feed-forward layers. If not specified, will run feed-forward layer individually
over each tensor of dim=
TYPE:
|
dim |
The dimension over which the feed-forward computation should be chunked. Choose between dim=0 (batch) or dim=1 (sequence length).
TYPE:
|
Source code in mindone/diffusers/models/controlnet_sd3.py
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 |
|
mindone.diffusers.SD3ControlNetModel.set_attn_processor(processor)
¶
Sets the attention processor to use to compute attention.
PARAMETER | DESCRIPTION |
---|---|
processor |
The instantiated processor class or a dictionary of processor classes that will be set as the processor
for all If
TYPE:
|
Source code in mindone/diffusers/models/controlnet_sd3.py
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 |
|
mindone.diffusers.models.controlnet_sd3.SD3ControlNetOutput
dataclass
¶
Bases: BaseOutput
Source code in mindone/diffusers/models/controlnet_sd3.py
35 36 37 |
|