| 4 | |
| 5 | class CLIPEncoderLayer(torch.nn.Module): |
| 6 | def __init__(self, embed_dim, intermediate_size, num_heads=12, head_dim=64, use_quick_gelu=True): |
| 7 | super().__init__() |
| 8 | self.attn = Attention(q_dim=embed_dim, num_heads=num_heads, head_dim=head_dim, bias_q=True, bias_kv=True, bias_out=True) |
| 9 | self.layer_norm1 = torch.nn.LayerNorm(embed_dim) |
| 10 | self.layer_norm2 = torch.nn.LayerNorm(embed_dim) |
| 11 | self.fc1 = torch.nn.Linear(embed_dim, intermediate_size) |
| 12 | self.fc2 = torch.nn.Linear(intermediate_size, embed_dim) |
| 13 | |
| 14 | self.use_quick_gelu = use_quick_gelu |
| 15 | |
| 16 | def quickGELU(self, x): |
| 17 | return x * torch.sigmoid(1.702 * x) |