Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TransformerLayer, TransformerBlock, C3TR modules #2333

Merged
merged 18 commits into from
Apr 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove bias in Transformer
  • Loading branch information
dingyiwei committed Feb 27, 2021
commit 9a1dee87f0f1b8215aa29d0b36f9f6f2493c819d
13 changes: 6 additions & 7 deletions models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,19 @@ def __init__(self, c, num_heads):
super().__init__()

self.ln1 = nn.LayerNorm(c)
self.q = nn.Linear(c, c)
self.k = nn.Linear(c, c)
self.v = nn.Linear(c, c)
self.q = nn.Linear(c, c, bias=False)
self.k = nn.Linear(c, c, bias=False)
self.v = nn.Linear(c, c, bias=False)
self.ma = nn.MultiheadAttention(embed_dim=c, num_heads=num_heads)
self.ln2 = nn.LayerNorm(c)
self.fc1 = nn.Linear(c, c)
self.fc2 = nn.Linear(c, c)
self.act = nn.SiLU()
self.fc1 = nn.Linear(c, c, bias=False)
self.fc2 = nn.Linear(c, c, bias=False)

def forward(self, x):
x_ = self.ln1(x)
x = self.ma(self.q(x_), self.k(x_), self.v(x_))[0] + x
x = self.ln2(x)
x = self.fc2(self.act(self.fc1(x))) + x
x = self.fc2(self.fc1(x)) + x
return x


Expand Down