(
self,
num_attention_heads: int = 48,
attention_head_dim: int = 128,
in_channels: int = 64,
out_channels: Optional[int] = 64,
num_layers: int = 48,
dropout: float = 0.0,
patch_size: int = 1,
norm_type: str = "ada_norm_single",
norm_elementwise_affine: bool = False,
norm_eps: float = 1e-6,
use_additional_conditions: Optional[bool] = False,
caption_channels: Optional[Union[int, List, Tuple]] = [6144, 1024],
attention_type: Optional[str] = "torch",
)
| 745 | |
| 746 | class StepVideoModel(torch.nn.Module): |
| 747 | def __init__( |
| 748 | self, |
| 749 | num_attention_heads: int = 48, |
| 750 | attention_head_dim: int = 128, |
| 751 | in_channels: int = 64, |
| 752 | out_channels: Optional[int] = 64, |
| 753 | num_layers: int = 48, |
| 754 | dropout: float = 0.0, |
| 755 | patch_size: int = 1, |
| 756 | norm_type: str = "ada_norm_single", |
| 757 | norm_elementwise_affine: bool = False, |
| 758 | norm_eps: float = 1e-6, |
| 759 | use_additional_conditions: Optional[bool] = False, |
| 760 | caption_channels: Optional[Union[int, List, Tuple]] = [6144, 1024], |
| 761 | attention_type: Optional[str] = "torch", |
| 762 | ): |
| 763 | super().__init__() |
| 764 | |
| 765 | # Set some common variables used across the board. |
| 766 | self.inner_dim = num_attention_heads * attention_head_dim |
| 767 | self.out_channels = in_channels if out_channels is None else out_channels |
| 768 | |
| 769 | self.use_additional_conditions = use_additional_conditions |
| 770 | |
| 771 | self.pos_embed = PatchEmbed( |
| 772 | patch_size=patch_size, |
| 773 | in_channels=in_channels, |
| 774 | embed_dim=self.inner_dim, |
| 775 | ) |
| 776 | |
| 777 | self.transformer_blocks = nn.ModuleList( |
| 778 | [ |
| 779 | StepVideoTransformerBlock( |
| 780 | dim=self.inner_dim, |
| 781 | attention_head_dim=attention_head_dim, |
| 782 | attention_type=attention_type |
| 783 | ) |
| 784 | for _ in range(num_layers) |
| 785 | ] |
| 786 | ) |
| 787 | |
| 788 | # 3. Output blocks. |
| 789 | self.norm_out = nn.LayerNorm(self.inner_dim, eps=norm_eps, elementwise_affine=norm_elementwise_affine) |
| 790 | self.scale_shift_table = nn.Parameter(torch.randn(2, self.inner_dim) / self.inner_dim**0.5) |
| 791 | self.proj_out = nn.Linear(self.inner_dim, patch_size * patch_size * self.out_channels) |
| 792 | self.patch_size = patch_size |
| 793 | |
| 794 | self.adaln_single = AdaLayerNormSingle( |
| 795 | self.inner_dim, use_additional_conditions=self.use_additional_conditions |
| 796 | ) |
| 797 | |
| 798 | if isinstance(caption_channels, int): |
| 799 | caption_channel = caption_channels |
| 800 | else: |
| 801 | caption_channel, clip_channel = caption_channels |
| 802 | self.clip_projection = nn.Linear(clip_channel, self.inner_dim) |
| 803 | |
| 804 | self.caption_norm = nn.LayerNorm(caption_channel, eps=norm_eps, elementwise_affine=norm_elementwise_affine) |
nothing calls this directly
no test coverage detected