Tiny AutoEncoder¶
Tiny AutoEncoder for Stable Diffusion (TAESD) was introduced in madebyollin/taesd by Ollin Boer Bohan. It is a tiny distilled version of Stable Diffusion's VAE that can quickly decode the latents in a StableDiffusionPipeline
or StableDiffusionXLPipeline
almost instantly.
To use with Stable Diffusion v-2.1:
import mindspore as ms
from mindone.diffusers import DiffusionPipeline, AutoencoderTiny
pipe = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-2-1-base", mindspore_dtype=ms.float16
)
pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesd", mindspore_dtype=ms.float16)
prompt = "slice of delicious New York-style berry cheesecake"
image = pipe(prompt, num_inference_steps=25)[0][0]
image
To use with Stable Diffusion XL 1.0
import mindspore as ms
from mindone.diffusers import DiffusionPipeline, AutoencoderTiny
pipe = DiffusionPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0", mindspore_dtype=ms.float16
)
pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taesdxl", mindspore_dtype=ms.float16)
prompt = "slice of delicious New York-style berry cheesecake"
image = pipe(prompt, num_inference_steps=25)[0][0]
image
mindone.diffusers.AutoencoderTiny
¶
Bases: ModelMixin
, ConfigMixin
A tiny distilled VAE model for encoding images into latents and decoding latent representations into images.
[AutoencoderTiny
] is a wrapper around the original implementation of TAESD
.
This model inherits from [ModelMixin
]. Check the superclass documentation for its generic methods implemented for
all models (such as downloading or saving).
PARAMETER | DESCRIPTION |
---|---|
in_channels |
Number of channels in the input image.
TYPE:
|
out_channels |
Number of channels in the output.
TYPE:
|
encoder_block_out_channels |
Tuple of integers representing the number of output channels for each encoder block. The length of the tuple should be equal to the number of encoder blocks.
TYPE:
|
decoder_block_out_channels |
Tuple of integers representing the number of output channels for each decoder block. The length of the tuple should be equal to the number of decoder blocks.
TYPE:
|
act_fn |
Activation function to be used throughout the model.
TYPE:
|
latent_channels |
Number of channels in the latent representation. The latent space acts as a compressed representation of the input image.
TYPE:
|
upsampling_scaling_factor |
Scaling factor for upsampling in the decoder. It determines the size of the output image during the upsampling process.
TYPE:
|
num_encoder_blocks |
Tuple of integers representing the number of encoder blocks at each stage of the encoding process. The length of the tuple should be equal to the number of stages in the encoder. Each stage has a different number of encoder blocks.
TYPE:
|
num_decoder_blocks |
Tuple of integers representing the number of decoder blocks at each stage of the decoding process. The length of the tuple should be equal to the number of stages in the decoder. Each stage has a different number of decoder blocks.
TYPE:
|
latent_magnitude |
Magnitude of the latent representation. This parameter scales the latent representation values to control the extent of information preservation.
TYPE:
|
latent_shift |
Shift applied to the latent representation. This parameter controls the center of the latent space.
TYPE:
|
scaling_factor |
The component-wise standard deviation of the trained latent space computed using the first batch of the
training set. This is used to scale the latent space to have unit variance when training the diffusion
model. The latents are scaled with the formula
TYPE:
|
force_upcast |
If enabled it will force the VAE to run in float32 for high image resolution pipelines, such as SD-XL. VAE
can be fine-tuned / trained to a lower range without losing too much precision, in which case
TYPE:
|
Source code in mindone/diffusers/models/autoencoders/autoencoder_tiny.py
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 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
mindone.diffusers.AutoencoderTiny.construct(sample, return_dict=False)
¶
PARAMETER | DESCRIPTION |
---|---|
sample |
Input sample.
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
Source code in mindone/diffusers/models/autoencoders/autoencoder_tiny.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
mindone.diffusers.AutoencoderTiny.disable_slicing()
¶
Disable sliced VAE decoding. If enable_slicing
was previously enabled, this method will go back to computing
decoding in one step.
Source code in mindone/diffusers/models/autoencoders/autoencoder_tiny.py
178 179 180 181 182 183 |
|
mindone.diffusers.AutoencoderTiny.disable_tiling()
¶
Disable tiled VAE decoding. If enable_tiling
was previously enabled, this method will go back to computing
decoding in one step.
Source code in mindone/diffusers/models/autoencoders/autoencoder_tiny.py
193 194 195 196 197 198 |
|
mindone.diffusers.AutoencoderTiny.enable_slicing()
¶
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
Source code in mindone/diffusers/models/autoencoders/autoencoder_tiny.py
171 172 173 174 175 176 |
|
mindone.diffusers.AutoencoderTiny.enable_tiling(use_tiling=True)
¶
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow processing larger images.
Source code in mindone/diffusers/models/autoencoders/autoencoder_tiny.py
185 186 187 188 189 190 191 |
|
mindone.diffusers.AutoencoderTiny.scale_latents(x)
¶
raw latents -> [0, 1]
Source code in mindone/diffusers/models/autoencoders/autoencoder_tiny.py
163 164 165 |
|
mindone.diffusers.AutoencoderTiny.unscale_latents(x)
¶
[0, 1] -> raw latents
Source code in mindone/diffusers/models/autoencoders/autoencoder_tiny.py
167 168 169 |
|
mindone.diffusers.models.autoencoders.autoencoder_tiny.AutoencoderTinyOutput
dataclass
¶
Bases: BaseOutput
Output of AutoencoderTiny encoding method.
PARAMETER | DESCRIPTION |
---|---|
latents |
Encoded outputs of the
TYPE:
|
Source code in mindone/diffusers/models/autoencoders/autoencoder_tiny.py
30 31 32 33 34 35 36 37 38 39 40 |
|