r""" Wan diffusion backbone supporting both text-to-video and image-to-video.
| 370 | |
| 371 | |
| 372 | class WanModel(ModelMixin, ConfigMixin): |
| 373 | r""" |
| 374 | Wan diffusion backbone supporting both text-to-video and image-to-video. |
| 375 | """ |
| 376 | |
| 377 | ignore_for_config = [ |
| 378 | 'patch_size', 'cross_attn_norm', 'qk_norm', 'text_dim', 'window_size' |
| 379 | ] |
| 380 | _no_split_modules = ['WanAttentionBlock'] |
| 381 | |
| 382 | @register_to_config |
| 383 | def __init__(self, |
| 384 | model_type='t2v', |
| 385 | patch_size=(1, 2, 2), |
| 386 | text_len=512, |
| 387 | in_dim=16, |
| 388 | dim=2048, |
| 389 | ffn_dim=8192, |
| 390 | freq_dim=256, |
| 391 | text_dim=4096, |
| 392 | out_dim=16, |
| 393 | num_heads=16, |
| 394 | num_layers=32, |
| 395 | window_size=(-1, -1), |
| 396 | qk_norm=True, |
| 397 | cross_attn_norm=True, |
| 398 | eps=1e-6): |
| 399 | r""" |
| 400 | Initialize the diffusion model backbone. |
| 401 | |
| 402 | Args: |
| 403 | model_type (`str`, *optional*, defaults to 't2v'): |
| 404 | Model variant - 't2v' (text-to-video) or 'i2v' (image-to-video) or 'flf2v' (first-last-frame-to-video) or 'vace' |
| 405 | patch_size (`tuple`, *optional*, defaults to (1, 2, 2)): |
| 406 | 3D patch dimensions for video embedding (t_patch, h_patch, w_patch) |
| 407 | text_len (`int`, *optional*, defaults to 512): |
| 408 | Fixed length for text embeddings |
| 409 | in_dim (`int`, *optional*, defaults to 16): |
| 410 | Input video channels (C_in) |
| 411 | dim (`int`, *optional*, defaults to 2048): |
| 412 | Hidden dimension of the transformer |
| 413 | ffn_dim (`int`, *optional*, defaults to 8192): |
| 414 | Intermediate dimension in feed-forward network |
| 415 | freq_dim (`int`, *optional*, defaults to 256): |
| 416 | Dimension for sinusoidal time embeddings |
| 417 | text_dim (`int`, *optional*, defaults to 4096): |
| 418 | Input dimension for text embeddings |
| 419 | out_dim (`int`, *optional*, defaults to 16): |
| 420 | Output video channels (C_out) |
| 421 | num_heads (`int`, *optional*, defaults to 16): |
| 422 | Number of attention heads |
| 423 | num_layers (`int`, *optional*, defaults to 32): |
| 424 | Number of transformer blocks |
| 425 | window_size (`tuple`, *optional*, defaults to (-1, -1)): |
| 426 | Window size for local attention (-1 indicates global attention) |
| 427 | qk_norm (`bool`, *optional*, defaults to True): |
| 428 | Enable query/key normalization |
| 429 | cross_attn_norm (`bool`, *optional*, defaults to False): |