r""" A basic Transformer block. Parameters: dim (`int`): The number of channels in the input and output. num_attention_heads (`int`): The number of heads to use for multi-head attention. attention_head_dim (`int`): The number of channels in each head. dropout
| 750 | |
| 751 | @maybe_allow_in_graph |
| 752 | class BasicTransformerBlock(nn.Module): |
| 753 | r""" |
| 754 | A basic Transformer block. |
| 755 | |
| 756 | Parameters: |
| 757 | dim (`int`): The number of channels in the input and output. |
| 758 | num_attention_heads (`int`): The number of heads to use for multi-head attention. |
| 759 | attention_head_dim (`int`): The number of channels in each head. |
| 760 | dropout (`float`, *optional*, defaults to 0.0): The dropout probability to use. |
| 761 | cross_attention_dim (`int`, *optional*): The size of the encoder_hidden_states vector for cross attention. |
| 762 | activation_fn (`str`, *optional*, defaults to `"geglu"`): Activation function to be used in feed-forward. |
| 763 | num_embeds_ada_norm (: |
| 764 | obj: `int`, *optional*): The number of diffusion steps used during training. See `Transformer2DModel`. |
| 765 | attention_bias (: |
| 766 | obj: `bool`, *optional*, defaults to `False`): Configure if the attentions should contain a bias parameter. |
| 767 | only_cross_attention (`bool`, *optional*): |
| 768 | Whether to use only cross-attention layers. In this case two cross attention layers are used. |
| 769 | double_self_attention (`bool`, *optional*): |
| 770 | Whether to use two self-attention layers. In this case no cross attention layers are used. |
| 771 | upcast_attention (`bool`, *optional*): |
| 772 | Whether to upcast the attention computation to float32. This is useful for mixed precision training. |
| 773 | norm_elementwise_affine (`bool`, *optional*, defaults to `True`): |
| 774 | Whether to use learnable elementwise affine parameters for normalization. |
| 775 | norm_type (`str`, *optional*, defaults to `"layer_norm"`): |
| 776 | The normalization layer to use. Can be `"layer_norm"`, `"ada_norm"` or `"ada_norm_zero"`. |
| 777 | final_dropout (`bool` *optional*, defaults to False): |
| 778 | Whether to apply a final dropout after the last feed-forward layer. |
| 779 | attention_type (`str`, *optional*, defaults to `"default"`): |
| 780 | The type of attention to use. Can be `"default"` or `"gated"` or `"gated-text-image"`. |
| 781 | positional_embeddings (`str`, *optional*, defaults to `None`): |
| 782 | The type of positional embeddings to apply to. |
| 783 | num_positional_embeddings (`int`, *optional*, defaults to `None`): |
| 784 | The maximum number of positional embeddings to apply. |
| 785 | """ |
| 786 | |
| 787 | def __init__( |
| 788 | self, |
| 789 | dim: int, |
| 790 | num_attention_heads: int, |
| 791 | attention_head_dim: int, |
| 792 | dropout=0.0, |
| 793 | cross_attention_dim: int | None = None, |
| 794 | activation_fn: str = "geglu", |
| 795 | num_embeds_ada_norm: int | None = None, |
| 796 | attention_bias: bool = False, |
| 797 | only_cross_attention: bool = False, |
| 798 | double_self_attention: bool = False, |
| 799 | upcast_attention: bool = False, |
| 800 | norm_elementwise_affine: bool = True, |
| 801 | norm_type: str = "layer_norm", # 'layer_norm', 'ada_norm', 'ada_norm_zero', 'ada_norm_single', 'ada_norm_continuous', 'layer_norm_i2vgen' |
| 802 | norm_eps: float = 1e-5, |
| 803 | final_dropout: bool = False, |
| 804 | attention_type: str = "default", |
| 805 | positional_embeddings: str | None = None, |
| 806 | num_positional_embeddings: int | None = None, |
| 807 | ada_norm_continous_conditioning_embedding_dim: int | None = None, |
| 808 | ada_norm_bias: int | None = None, |
| 809 | ff_inner_dim: int | None = None, |
no outgoing calls
no test coverage detected
searching dependent graphs…