SanaTransformer2DModel¶
A Diffusion Transformer model for 2D data from SANA: Efficient High-Resolution Image Synthesis with Linear Diffusion Transformers was introduced from NVIDIA and MIT HAN Lab, by Enze Xie, Junsong Chen, Junyu Chen, Han Cai, Haotian Tang, Yujun Lin, Zhekai Zhang, Muyang Li, Ligeng Zhu, Yao Lu, Song Han.
The abstract from the paper is:
We introduce Sana, a text-to-image framework that can efficiently generate images up to 4096×4096 resolution. Sana can synthesize high-resolution, high-quality images with strong text-image alignment at a remarkably fast speed, deployable on laptop GPU. Core designs include: (1) Deep compression autoencoder: unlike traditional AEs, which compress images only 8×, we trained an AE that can compress images 32×, effectively reducing the number of latent tokens. (2) Linear DiT: we replace all vanilla attention in DiT with linear attention, which is more efficient at high resolutions without sacrificing quality. (3) Decoder-only text encoder: we replaced T5 with modern decoder-only small LLM as the text encoder and designed complex human instruction with in-context learning to enhance the image-text alignment. (4) Efficient training and sampling: we propose Flow-DPM-Solver to reduce sampling steps, with efficient caption labeling and selection to accelerate convergence. As a result, Sana-0.6B is very competitive with modern giant diffusion model (e.g. Flux-12B), being 20 times smaller and 100+ times faster in measured throughput. Moreover, Sana-0.6B can be deployed on a 16GB laptop GPU, taking less than 1 second to generate a 1024×1024 resolution image. Sana enables content creation at low cost. Code and model will be publicly released.
The model can be loaded with the following code snippet.
from mindone.diffusers import SanaTransformer2DModel
transformer = SanaTransformer2DModel.from_pretrained("Efficient-Large-Model/Sana_1600M_1024px_BF16_diffusers", subfolder="transformer", mindspore_dtype=ms.bfloat16)
mindone.diffusers.SanaTransformer2DModel
¶
Bases: ModelMixin
, ConfigMixin
, PeftAdapterMixin
A 2D Transformer model introduced in Sana family of models.
PARAMETER | DESCRIPTION |
---|---|
in_channels |
The number of channels in the input.
TYPE:
|
out_channels |
The number of channels in the output.
TYPE:
|
num_attention_heads |
The number of heads to use for multi-head attention.
TYPE:
|
attention_head_dim |
The number of channels in each head.
TYPE:
|
num_layers |
The number of layers of Transformer blocks to use.
TYPE:
|
num_cross_attention_heads |
The number of heads to use for cross-attention.
TYPE:
|
cross_attention_head_dim |
The number of channels in each head for cross-attention.
TYPE:
|
cross_attention_dim |
The number of channels in the cross-attention output.
TYPE:
|
caption_channels |
The number of channels in the caption embeddings.
TYPE:
|
mlp_ratio |
The expansion ratio to use in the GLUMBConv layer.
TYPE:
|
dropout |
The dropout probability.
TYPE:
|
attention_bias |
Whether to use bias in the attention layer.
TYPE:
|
sample_size |
The base size of the input latent.
TYPE:
|
patch_size |
The size of the patches to use in the patch embedding layer.
TYPE:
|
norm_elementwise_affine |
Whether to use elementwise affinity in the normalization layer.
TYPE:
|
norm_eps |
The epsilon value for the normalization layer.
TYPE:
|
Source code in mindone/diffusers/models/transformers/sana_transformer.py
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 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
|
mindone.diffusers.SanaTransformer2DModel.attn_processors: Dict[str, AttentionProcessor]
property
¶
RETURNS | DESCRIPTION |
---|---|
Dict[str, AttentionProcessor]
|
|
Dict[str, AttentionProcessor]
|
indexed by its weight name. |
mindone.diffusers.SanaTransformer2DModel.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/transformers/sana_transformer.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
mindone.diffusers.models.modeling_outputs.Transformer2DModelOutput
dataclass
¶
Bases: BaseOutput
The output of [Transformer2DModel
].
PARAMETER | DESCRIPTION |
---|---|
`(batch |
The hidden states output conditioned on the
TYPE:
|
Source code in mindone/diffusers/models/modeling_outputs.py
22 23 24 25 26 27 28 29 30 31 32 33 34 |
|