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:
|
qk_norm |
The normalization to use for the query and key.
TYPE:
|
timestep_scale |
The scale to use for the timesteps.
TYPE:
|
Source code in mindone/diffusers/models/transformers/sana_transformer.py
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 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
|
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
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
|
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 |
|