Fixed a typo
Browse files
adria.py
CHANGED
|
@@ -142,7 +142,7 @@ class MultiHeadAttention(nn.Module):
|
|
| 142 |
self.c_attention = nn.Linear(dim_model, 3 * dim_model)
|
| 143 |
self.c_projection = nn.Linear(dim_model, dim_model)
|
| 144 |
|
| 145 |
-
#
|
| 146 |
self.register_buffer("mask", torch.tril(torch.ones((max_len, max_len))).view(1, 1, max_len, max_len))
|
| 147 |
|
| 148 |
def dot_product_attention(self, q, k, v, mask = None):
|
|
@@ -207,7 +207,7 @@ class MultiHeadAttention(nn.Module):
|
|
| 207 |
|
| 208 |
current_kv = (k, v)
|
| 209 |
|
| 210 |
-
#
|
| 211 |
attention = (torch.matmul(q, k.transpose(-2, -1))) * (1.0 / math.sqrt(self.dim_k))
|
| 212 |
|
| 213 |
if kv_cache is None:
|
|
|
|
| 142 |
self.c_attention = nn.Linear(dim_model, 3 * dim_model)
|
| 143 |
self.c_projection = nn.Linear(dim_model, dim_model)
|
| 144 |
|
| 145 |
+
# Causal mask registered for attention
|
| 146 |
self.register_buffer("mask", torch.tril(torch.ones((max_len, max_len))).view(1, 1, max_len, max_len))
|
| 147 |
|
| 148 |
def dot_product_attention(self, q, k, v, mask = None):
|
|
|
|
| 207 |
|
| 208 |
current_kv = (k, v)
|
| 209 |
|
| 210 |
+
# Causal masking is now skipped when using cache since we only attend to valid past positions
|
| 211 |
attention = (torch.matmul(q, k.transpose(-2, -1))) * (1.0 / math.sqrt(self.dim_k))
|
| 212 |
|
| 213 |
if kv_cache is None:
|