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
fairscale
Commits
29c01fb1
"vscode:/vscode.git/clone" did not exist on "4cc1a6143387f41e2466536abcd6a2620b63a35b"
Unverified
Commit
29c01fb1
authored
May 08, 2021
by
Sam Shleifer
Committed by
GitHub
May 08, 2021
Browse files
[test] Force overflow in top2gating test (#664)
parent
5739930f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
tests/nn/moe/test_top2gating.py
tests/nn/moe/test_top2gating.py
+10
-10
No files found.
tests/nn/moe/test_top2gating.py
View file @
29c01fb1
...
...
@@ -50,18 +50,18 @@ def test_forward_cuda():
# Verify that top gate is allocated capacity as per Algorithm 1 in GShard paper.
def
test_
top1s
():
def
test_
expert1_overflow
():
num_tokens
=
8
num_experts
=
4
logits
=
torch
.
randn
(
num_tokens
,
num_experts
)
l
_aux
,
_
,
dispatch_mask
=
top2gating
(
logits
)
l
ogits
[:,
0
]
=
torch
.
max
(
logits
,
dim
=
1
).
values
+
1
# Force overflow
top1s
=
torch
.
argmax
(
logits
,
dim
=
1
)
assert
top1s
.
eq
(
0
).
all
(),
top1s
_
,
__
,
dispatch_mask
=
top2gating
(
logits
)
capacity
=
2
*
num_tokens
//
num_experts
ce
=
[
0
]
*
num_experts
locations
=
[
0
]
*
num_tokens
for
i
,
s
in
enumerate
(
top1s
):
e
=
s
.
item
()
loc
=
ce
[
e
]
ce
[
e
]
=
loc
+
1
if
ce
[
e
]
<
capacity
:
assert
dispatch_mask
[
i
][
e
][
loc
]
for
i
in
range
(
num_tokens
):
if
i
<
capacity
:
assert
dispatch_mask
[
i
][
0
][
i
]
else
:
assert
not
dispatch_mask
[
i
][
0
].
any
()
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