gen3c ¶
GEN3C is a video-conditioned diffusion model that uses a 3D cache for camera control.
Key Features: - Extends Cosmos 2.5 architecture with video conditioning inputs - condition_video_input_mask: Binary mask indicating conditioning frames - condition_video_pose: VAE-encoded 3D cache buffers (rendered warped images/masks) - Augment sigma embedding for conditioning noise augmentation - 3D RoPE with learnable per-axis positional embeddings
Reference: https://arxiv.org/abs/2503.03751
Classes¶
fastvideo.models.dits.gen3c.Gen3CAdaLayerNormZero ¶
Gen3CAdaLayerNormZero(in_features: int)
Bases: Module
GEN3C Adaptive Layer Normalization with zero initialization and gate. This is a simplified version that expects pre-computed shift/scale/gate parameters.
Source code in fastvideo/models/dits/gen3c.py
Methods:¶
fastvideo.models.dits.gen3c.Gen3CAdaLayerNormZero.forward ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states | Tensor | Input tensor | required |
shift | Tensor | Shift parameter for modulation | required |
scale | Tensor | Scale parameter for modulation | required |
Returns:
| Name | Type | Description |
|---|---|---|
normalized_hidden_states | Tensor | Modulated normalized hidden states |
Source code in fastvideo/models/dits/gen3c.py
fastvideo.models.dits.gen3c.Gen3CCrossAttention ¶
Gen3CCrossAttention(dim: int, cross_attention_dim: int, num_heads: int, qk_norm: bool = True, eps: float = 1e-06, supported_attention_backends: tuple[AttentionBackendEnum, ...] | None = None)
Bases: Module
GEN3C cross-attention for text conditioning.
Source code in fastvideo/models/dits/gen3c.py
Methods:¶
fastvideo.models.dits.gen3c.Gen3CCrossAttention.forward ¶
forward(hidden_states: Tensor, encoder_hidden_states: Tensor, attention_mask: Tensor | None = None) -> Tensor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states | Tensor | (B, S, D) | required |
encoder_hidden_states | Tensor | (B, N, D_text) | required |
Source code in fastvideo/models/dits/gen3c.py
fastvideo.models.dits.gen3c.Gen3CEmbedding ¶
Gen3CEmbedding(embedding_dim: int, condition_dim: int, use_adaln_lora: bool = True, adaln_lora_dim: int = 256)
Bases: Module
GEN3C timestep conditioning embedding. Generates sinusoidal embeddings and processes them through MLP.
Source code in fastvideo/models/dits/gen3c.py
Methods:¶
fastvideo.models.dits.gen3c.Gen3CEmbedding.forward ¶
forward(timestep: Tensor, dtype: dtype) -> tuple[Tensor, Tensor | None]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestep | Tensor | (B,) tensor of timesteps | required |
dtype | dtype | Target dtype for embeddings | required |
Returns:
| Name | Type | Description |
|---|---|---|
embedded_timestep | Tensor | Timestep embedding (B, D) |
adaln_lora | Tensor | None | AdaLN-LoRA parameters (B, 3D) or None |
Source code in fastvideo/models/dits/gen3c.py
fastvideo.models.dits.gen3c.Gen3CFinalLayer ¶
Gen3CFinalLayer(hidden_size: int, out_channels: int, patch_size: tuple[int, int, int], adaln_lora_dim: int = 256, use_adaln_lora: bool = True)
Bases: Module
GEN3C final layer with AdaLN modulation and unpatchification.
Source code in fastvideo/models/dits/gen3c.py
Methods:¶
fastvideo.models.dits.gen3c.Gen3CFinalLayer.forward ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states | Tensor | (B, T, H, W, D) | required |
affine_emb | Tensor | (B, D) | required |
adaln_lora | Tensor | None | (B, 3D) or None | None |
Source code in fastvideo/models/dits/gen3c.py
fastvideo.models.dits.gen3c.Gen3CLearnablePositionalEmbed ¶
Gen3CLearnablePositionalEmbed(hidden_size: int, max_size: tuple[int, int, int], patch_size: tuple[int, int, int], eps: float = 1e-06)
Bases: Module
GEN3C learnable absolute positional embeddings.
Source code in fastvideo/models/dits/gen3c.py
Methods:¶
fastvideo.models.dits.gen3c.Gen3CLearnablePositionalEmbed.forward ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states | Tensor | (B, T, H, W, D) | required |
Returns: pos_emb: (B, T, H, W, D)
Source code in fastvideo/models/dits/gen3c.py
fastvideo.models.dits.gen3c.Gen3CPatchEmbed ¶
Bases: Module
GEN3C patch embedding - converts video (B, C, T, H, W) to patches (B, T', H', W', D). Uses linear projection after rearranging patches.
Input channels include: - VAE latent (16 channels) - condition_video_input_mask (1 channel) - condition_video_pose (frame_buffer_max * 32 channels) - padding_mask (1 channel, if concat_padding_mask=True)
Source code in fastvideo/models/dits/gen3c.py
Methods:¶
fastvideo.models.dits.gen3c.Gen3CPatchEmbed.forward ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states | Tensor | (B, C, T, H, W) | required |
Returns: (B, T', H', W', D) where T'=T//pt, H'=H//ph, W'=W//pw
Source code in fastvideo/models/dits/gen3c.py
fastvideo.models.dits.gen3c.Gen3CRotaryPosEmbed ¶
Gen3CRotaryPosEmbed(hidden_size: int, max_size: tuple[int, int, int] = (128, 240, 240), patch_size: tuple[int, int, int] = (1, 2, 2), base_fps: int = 24, rope_scale: tuple[float, float, float] = (1.0, 1.0, 1.0), enable_fps_modulation: bool = True)
Bases: Module
GEN3C 3D Rotary Position Embedding with NTK-aware extrapolation.
Source code in fastvideo/models/dits/gen3c.py
Methods:¶
fastvideo.models.dits.gen3c.Gen3CRotaryPosEmbed.forward ¶
Generate 3D RoPE embeddings.
Source code in fastvideo/models/dits/gen3c.py
fastvideo.models.dits.gen3c.Gen3CSelfAttention ¶
Gen3CSelfAttention(dim: int, num_heads: int, qk_norm: bool = True, eps: float = 1e-06, supported_attention_backends: tuple[AttentionBackendEnum, ...] | None = None)
Bases: Module
GEN3C self-attention with QK normalization and RoPE.
Source code in fastvideo/models/dits/gen3c.py
Methods:¶
fastvideo.models.dits.gen3c.Gen3CSelfAttention.forward ¶
forward(hidden_states: Tensor, rope_emb: tuple[Tensor, Tensor] | None = None, original_seq_len: int | None = None) -> Tensor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states | Tensor | (B, S, D) where S = THW | required |
rope_emb | tuple[Tensor, Tensor] | None | Tuple of (cos, sin) for RoPE | None |
original_seq_len | int | None | Original (unpadded) full sequence length | None |
Source code in fastvideo/models/dits/gen3c.py
fastvideo.models.dits.gen3c.Gen3CTimestepEmbedding ¶
Gen3CTimestepEmbedding(in_features: int, out_features: int, use_adaln_lora: bool = True, adaln_lora_dim: int = 256)
Bases: Module
GEN3C timestep embedding with AdaLN-LoRA support. Generates both standard embedding and AdaLN-LoRA parameters.
Source code in fastvideo/models/dits/gen3c.py
Methods:¶
fastvideo.models.dits.gen3c.Gen3CTimestepEmbedding.forward ¶
forward(sample: Tensor) -> tuple[Tensor, Tensor | None]
Returns:
| Name | Type | Description |
|---|---|---|
emb | Tensor | Standard embedding (B, D) - the original sinusoidal input |
adaln_lora | Tensor | None | AdaLN-LoRA parameters (B, 3D) or None |
Note: When use_adaln_lora=True, the standard embedding is the INPUT (sinusoidal timestep embedding), not the processed output. The processed output (linear_2) is used exclusively for AdaLN-LoRA parameters. This matches the official GEN3C implementation.
Source code in fastvideo/models/dits/gen3c.py
fastvideo.models.dits.gen3c.Gen3CTransformer3DModel ¶
Gen3CTransformer3DModel(config: Gen3CVideoConfig, hf_config: dict[str, Any])
Bases: BaseDiT
GEN3C DiT - Video-conditioned diffusion transformer with 3D cache support.
Key features: - AdaLN-LoRA conditioning - 3D RoPE with NTK-aware extrapolation - Learnable positional embeddings - QK normalization - Video conditioning with 3D cache buffers - Augment sigma embedding for conditioning noise augmentation
Source code in fastvideo/models/dits/gen3c.py
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |
Methods:¶
fastvideo.models.dits.gen3c.Gen3CTransformer3DModel.forward ¶
forward(hidden_states: Tensor, timestep: Tensor, encoder_hidden_states: Tensor | list[Tensor], attention_mask: Tensor | None = None, fps: int | None = None, condition_video_input_mask: Tensor | None = None, condition_video_pose: Tensor | None = None, condition_video_augment_sigma: Tensor | None = None, padding_mask: Tensor | None = None, **kwargs) -> Tensor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states | Tensor | (B, C, T, H, W) latent video (16 channels) | required |
timestep | Tensor | (B,) diffusion timesteps | required |
encoder_hidden_states | Tensor | list[Tensor] | (B, N, D_text) text embeddings | required |
attention_mask | Tensor | None | Optional attention mask | None |
fps | int | None | Frames per second | None |
condition_video_input_mask | Tensor | None | (B, 1, T, H, W) conditioning mask for video frames | None |
condition_video_pose | Tensor | None | (B, buffer_channels, T, H, W) VAE-encoded 3D cache buffers | None |
condition_video_augment_sigma | Tensor | None | (B,) sigma for conditioning noise augmentation | None |
padding_mask | Tensor | None | (B, 1, H, W) padding mask | None |
Source code in fastvideo/models/dits/gen3c.py
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 | |
fastvideo.models.dits.gen3c.Gen3CTransformerBlock ¶
Gen3CTransformerBlock(num_attention_heads: int, attention_head_dim: int, cross_attention_dim: int, mlp_ratio: float = 4.0, adaln_lora_dim: int = 256, use_adaln_lora: bool = True, qk_norm: bool = True, supported_attention_backends: tuple[AttentionBackendEnum, ...] | None = None)
Bases: Module
GEN3C transformer block with self-attention, cross-attention, and MLP. Uses AdaLN-LoRA for conditioning.
Source code in fastvideo/models/dits/gen3c.py
Methods:¶
fastvideo.models.dits.gen3c.Gen3CTransformerBlock.forward ¶
forward(hidden_states: Tensor, encoder_hidden_states: Tensor, affine_emb: Tensor, adaln_lora: Tensor | None = None, rope_emb: tuple[Tensor, Tensor] | None = None, extra_pos_emb: Tensor | None = None, original_seq_len: int | None = None) -> Tensor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_states | Tensor | (B, S, D) where S = THW (sequence may be sharded with SP) | required |
encoder_hidden_states | Tensor | (B, N, D_text) | required |
affine_emb | Tensor | (B, D) affine embedding | required |
adaln_lora | Tensor | None | (B, 3D) AdaLN-LoRA parameters | None |
rope_emb | tuple[Tensor, Tensor] | None | Tuple of (cos, sin) for RoPE | None |
extra_pos_emb | Tensor | None | Optional learnable positional embeddings (B, S, D) | None |
original_seq_len | int | None | Original (unpadded) full sequence length | None |
Source code in fastvideo/models/dits/gen3c.py
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 | |