(self, dim, num_heads, mlp_ratio=4., qkv_bias=False, qk_scale=None, drop=0., attn_drop=0.,
drop_path=0., act_layer=nn.GELU, norm_layer=nn.LayerNorm)
| 86 | class DecoderBlock(nn.Module): |
| 87 | |
| 88 | def __init__(self, dim, num_heads, mlp_ratio=4., qkv_bias=False, qk_scale=None, drop=0., attn_drop=0., |
| 89 | drop_path=0., act_layer=nn.GELU, norm_layer=nn.LayerNorm): |
| 90 | super().__init__() |
| 91 | self. attn2 = CrossAttention( |
| 92 | dim, num_heads=num_heads, qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop) |
| 93 | self.norm2_1 = norm_layer(dim) |
| 94 | self.norm2_2 = norm_layer(dim) |
| 95 | # NOTE: drop path for stochastic depth, we shall see if this is better than dropout here |
| 96 | self.drop_path = DropPath(drop_path) if drop_path > 0. else nn.Identity() |
| 97 | self.norm2 = norm_layer(dim) |
| 98 | mlp_hidden_dim = int(dim * mlp_ratio) |
| 99 | self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop) |
| 100 | |
| 101 | def forward(self, q, kv, mask): |
| 102 | q = q + self.attn2(self.norm2_1(q), self.norm2_2(kv), mask) |
nothing calls this directly
no test coverage detected