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
1dc7e73e
Commit
1dc7e73e
authored
Feb 26, 2021
by
Jiezhong Qiu
Browse files
seems that solution 1 is still the fatest
i.e., expand bias using torch.repeat_interleave directly
parent
c65039da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
fmoe/layers.py
fmoe/layers.py
+5
-5
No files found.
fmoe/layers.py
View file @
1dc7e73e
...
@@ -70,13 +70,13 @@ class FMoELinear(nn.Module):
...
@@ -70,13 +70,13 @@ class FMoELinear(nn.Module):
# like MOELinear.apply(x, weight, bias, count)
# like MOELinear.apply(x, weight, bias, count)
# Solution 1
# Solution 1
#
bias = torch.repeat_interleave(self.bias,
bias
=
torch
.
repeat_interleave
(
self
.
bias
,
#
fwd_expert_count.to(self.bias.device), dim=0)
fwd_expert_count
.
to
(
self
.
bias
.
device
),
dim
=
0
)
# Solution 2
# Solution 2
bias_idx
=
torch
.
arange
(
self
.
num_expert
)
\
#
bias_idx = torch.arange(self.num_expert)\
.
repeat_interleave
(
fwd_expert_count
)
#
.repeat_interleave(fwd_expert_count)
bias
=
self
.
bias
[
bias_idx
]
#
bias = self.bias[bias_idx]
# Solution 3
# Solution 3
# bias = []
# bias = []
...
...
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