Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
FastMoE
Commits
0f3e63eb
"src/vscode:/vscode.git/clone" did not exist on "ea6938aea589b034c2320964bf066ba6dd33b12c"
Commit
0f3e63eb
authored
Nov 23, 2020
by
Jiezhong Qiu
Browse files
add gate
parent
a43caff7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
0 deletions
+2
-0
pytorch/mem_transformer.py
pytorch/mem_transformer.py
+2
-0
No files found.
pytorch/mem_transformer.py
View file @
0f3e63eb
...
@@ -131,12 +131,14 @@ class HierarchicalMoEPositionwiseFF(nn.Module):
...
@@ -131,12 +131,14 @@ class HierarchicalMoEPositionwiseFF(nn.Module):
block
=
self
.
block_net
(
inp
)
block
=
self
.
block_net
(
inp
)
block_val
,
block_idx
=
torch
.
topk
(
block
,
k
=
self
.
top_block
,
dim
=-
1
,
largest
=
True
,
sorted
=
False
)
# [.. x top_k]
block_val
,
block_idx
=
torch
.
topk
(
block
,
k
=
self
.
top_block
,
dim
=-
1
,
largest
=
True
,
sorted
=
False
)
# [.. x top_k]
gate
=
F
.
softmax
(
block_val
,
dim
=-
1
)
W1_block
=
self
.
W1
[
block_idx
]
# [.. x top_k x d_block x d_model]
W1_block
=
self
.
W1
[
block_idx
]
# [.. x top_k x d_block x d_model]
b1_block
=
self
.
b1
[
block_idx
]
# [.. x top_k x d_block]
b1_block
=
self
.
b1
[
block_idx
]
# [.. x top_k x d_block]
x
=
torch
.
einsum
(
'ibd,ibnhd->ibnh'
,
(
inp
,
W1_block
))
+
b1_block
x
=
torch
.
einsum
(
'ibd,ibnhd->ibnh'
,
(
inp
,
W1_block
))
+
b1_block
x
=
x
*
gate
.
unsqueeze
(
-
1
)
relu_out
=
F
.
relu
(
x
)
relu_out
=
F
.
relu
(
x
)
relu_out
=
self
.
dropout_middle
(
relu_out
)
relu_out
=
self
.
dropout_middle
(
relu_out
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment