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
89de2153
Commit
89de2153
authored
Feb 26, 2021
by
Rick Ho
Browse files
zero gate update
parent
94eca783
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
+6
-3
fmoe/gates.py
fmoe/gates.py
+6
-3
No files found.
fmoe/gates.py
View file @
89de2153
...
...
@@ -10,15 +10,18 @@ import torch.nn.functional as F
class
ZeroGate
(
nn
.
Module
):
def
__init__
(
self
,
d_model
,
num_expert
,
world_size
,
top_k
=
2
):
super
().
__init__
()
self
.
top_k
=
top_k
def
forward
(
self
,
inp
):
r
'''
The naive implementation simply calculates the top-k of a linear layer's
output.
'''
idx
=
torch
.
zeros
(
inp
.
shape
[
0
],
dtype
=
torch
.
int64
,
device
=
inp
.
device
)
score
=
torch
.
ones
(
inp
.
shape
[
0
],
device
=
inp
.
device
)
return
idx
,
score
.
reshape
(
-
1
,
1
,
1
)
idx
=
torch
.
zeros
(
inp
.
shape
[
0
]
*
self
.
top_k
,
dtype
=
torch
.
int64
,
device
=
inp
.
device
)
score
=
torch
.
ones
(
inp
.
shape
[
0
]
*
self
.
top_k
,
device
=
inp
.
device
)
/
self
.
top_k
return
idx
,
score
.
reshape
(
-
1
,
1
,
self
.
top_k
)
class
NaiveGate
(
nn
.
Module
):
...
...
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