Update archctr.py
Browse files- archctr.py +5 -2
archctr.py
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
class GPTDecoder(nn.Module):
|
| 2 |
def __init__(self, nclass=16135, d_model=1024, max_pos=512, nhead=16, dim_feedforward=2048, vocab_size=16135, nhead_emb=8):
|
| 3 |
super().__init__()
|
|
@@ -16,7 +19,7 @@ class GPTDecoder(nn.Module):
|
|
| 16 |
self.Linear = nn.Linear(d_model, nclass)
|
| 17 |
def forward(self, x):
|
| 18 |
x = self.embedding(x)
|
| 19 |
-
x_n = torch.arange(x.size(1)).unsqueeze(0)
|
| 20 |
x_n = self.pos_embedding(x_n)
|
| 21 |
x = x + x_n
|
| 22 |
x_origin = x
|
|
@@ -28,7 +31,7 @@ class GPTDecoder(nn.Module):
|
|
| 28 |
x = x + x_origin
|
| 29 |
x_origin = x
|
| 30 |
x = self.LayerNorm_heads(x)
|
| 31 |
-
mask = nn.Transformer.generate_square_subsequent_mask(x.size(1))
|
| 32 |
x, _ = self.GPT_MHA(x,x,x, attn_mask=mask)
|
| 33 |
x = x+x_origin
|
| 34 |
x_origin = x
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
|
| 4 |
class GPTDecoder(nn.Module):
|
| 5 |
def __init__(self, nclass=16135, d_model=1024, max_pos=512, nhead=16, dim_feedforward=2048, vocab_size=16135, nhead_emb=8):
|
| 6 |
super().__init__()
|
|
|
|
| 19 |
self.Linear = nn.Linear(d_model, nclass)
|
| 20 |
def forward(self, x):
|
| 21 |
x = self.embedding(x)
|
| 22 |
+
x_n = torch.arange(x.size(1)).unsqueeze(0)
|
| 23 |
x_n = self.pos_embedding(x_n)
|
| 24 |
x = x + x_n
|
| 25 |
x_origin = x
|
|
|
|
| 31 |
x = x + x_origin
|
| 32 |
x_origin = x
|
| 33 |
x = self.LayerNorm_heads(x)
|
| 34 |
+
mask = nn.Transformer.generate_square_subsequent_mask(x.size(1))
|
| 35 |
x, _ = self.GPT_MHA(x,x,x, attn_mask=mask)
|
| 36 |
x = x+x_origin
|
| 37 |
x_origin = x
|