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
cb6aadaa
Commit
cb6aadaa
authored
Dec 30, 2020
by
Rick Ho
Browse files
performance test in python
parent
57191b14
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
pytorch/cuda/moe_test.py
pytorch/cuda/moe_test.py
+33
-0
No files found.
pytorch/cuda/moe_test.py
0 → 100644
View file @
cb6aadaa
from
moe
import
MOELayer
import
torch
import
time
def
perf
():
batch_size
=
128
in_feat
=
1024
out_feat
=
4096
num_expert
=
4
inp
=
torch
.
rand
(
batch_size
,
in_feat
).
cuda
()
gate
=
torch
.
randint
(
low
=
0
,
high
=
num_expert
,
size
=
(
batch_size
,
),
requires_grad
=
False
).
int
().
cuda
()
moe
=
MOELayer
(
num_expert
,
in_feat
,
out_feat
).
cuda
()
o
=
moe
(
inp
,
gate
)
n_runs
=
16
tott
=
0.
for
i
in
range
(
n_runs
):
gate
=
torch
.
randint
(
low
=
0
,
high
=
num_expert
,
size
=
(
batch_size
,
),
requires_grad
=
False
).
int
().
cuda
()
ts
=
time
.
time
()
o
=
moe
(
inp
,
gate
)
te
=
time
.
time
()
tott
+=
te
-
ts
gflops
=
2e-9
*
n_runs
*
in_feat
*
out_feat
*
batch_size
print
(
'Mean time {:.3f} ms, {:.3f} GFLOPs'
.
format
(
tott
*
1e3
/
n_runs
,
gflops
))
if
__name__
==
'__main__'
:
perf
()
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