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
| 211 | |
| 212 | @maybe_allow_in_graph |
| 213 | class BasicTransformerBlock(nn.Module): |
| 214 | r""" |
| 215 | A basic Transformer block. |
| 216 | |
| 217 | Parameters: |
| 218 | dim (`int`): The number of channels in the input and output. |
| 219 | num_attention_heads (`int`): The number of heads to use for multi-head attention. |
| 220 | attention_head_dim (`int`): The number of channels in each head. |
| 221 | dropout (`float`, *optional*, defaults to 0.0): The dropout probability to use. |
| 222 | cross_attention_dim (`int`, *optional*): The size of the encoder_hidden_states vector for cross attention. |
| 223 | activation_fn (`str`, *optional*, defaults to `"geglu"`): Activation function to be used in feed-forward. |
| 224 | num_embeds_ada_norm (: |
| 225 | obj: `int`, *optional*): The number of diffusion steps used during training. See `Transformer2DModel`. |
| 226 | attention_bias (: |
| 227 | obj: `bool`, *optional*, defaults to `False`): Configure if the attentions should contain a bias parameter. |
| 228 | only_cross_attention (`bool`, *optional*): |
| 229 | Whether to use only cross-attention layers. In this case two cross attention layers are used. |
| 230 | double_self_attention (`bool`, *optional*): |
| 231 | Whether to use two self-attention layers. In this case no cross attention layers are used. |
| 232 | upcast_attention (`bool`, *optional*): |
| 233 | Whether to upcast the attention computation to float32. This is useful for mixed precision training. |
| 234 | norm_elementwise_affine (`bool`, *optional*, defaults to `True`): |
| 235 | Whether to use learnable elementwise affine parameters for normalization. |
| 236 | norm_type (`str`, *optional*, defaults to `"layer_norm"`): |
| 237 | The normalization layer to use. Can be `"layer_norm"`, `"ada_norm"` or `"ada_norm_zero"`. |
| 238 | final_dropout (`bool` *optional*, defaults to False): |
| 239 | Whether to apply a final dropout after the last feed-forward layer. |
| 240 | attention_type (`str`, *optional*, defaults to `"default"`): |
| 241 | The type of attention to use. Can be `"default"` or `"gated"` or `"gated-text-image"`. |
| 242 | positional_embeddings (`str`, *optional*, defaults to `None`): |
| 243 | The type of positional embeddings to apply to. |
| 244 | num_positional_embeddings (`int`, *optional*, defaults to `None`): |
| 245 | The maximum number of positional embeddings to apply. |
| 246 | """ |
| 247 | |
| 248 | def __init__( |
| 249 | self, |
| 250 | dim: int, |
| 251 | num_attention_heads: int, |
| 252 | attention_head_dim: int, |
| 253 | dropout=0.0, |
| 254 | cross_attention_dim: Optional[int] = None, |
| 255 | activation_fn: str = "geglu", |
| 256 | num_embeds_ada_norm: Optional[int] = None, |
| 257 | attention_bias: bool = False, |
| 258 | only_cross_attention: bool = False, |
| 259 | double_self_attention: bool = False, |
| 260 | upcast_attention: bool = False, |
| 261 | norm_elementwise_affine: bool = True, |
| 262 | norm_type: str = "layer_norm", # 'layer_norm', 'ada_norm', 'ada_norm_zero', 'ada_norm_single', 'ada_norm_continuous', 'layer_norm_i2vgen' |
| 263 | norm_eps: float = 1e-5, |
| 264 | final_dropout: bool = False, |
| 265 | attention_type: str = "default", |
| 266 | positional_embeddings: Optional[str] = None, |
| 267 | num_positional_embeddings: Optional[int] = None, |
| 268 | ada_norm_continous_conditioning_embedding_dim: Optional[int] = None, |
| 269 | ada_norm_bias: Optional[int] = None, |
| 270 | ff_inner_dim: Optional[int] = None, |
no outgoing calls
no test coverage detected