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
Uni-Core
Commits
1e8b6e33
Commit
1e8b6e33
authored
Jul 27, 2022
by
Guolin Ke
Browse files
fix softmax cpu
parent
21cb6b39
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
12 deletions
+10
-12
unicore/modules/softmax_dropout.py
unicore/modules/softmax_dropout.py
+10
-12
No files found.
unicore/modules/softmax_dropout.py
View file @
1e8b6e33
...
...
@@ -94,23 +94,21 @@ def softmax_dropout(input, dropout_prob, is_training=True, mask=None, bias=None)
torch.Tensor: the result after softmax
"""
input
=
input
.
contiguous
()
input_size
=
input
.
size
()
if
mask
is
not
None
:
_check_mask
(
mask
,
input
)
mask
=
mask
.
contiguous
().
view
(
-
1
,
mask
.
shape
[
-
2
],
mask
.
shape
[
-
1
])
if
bias
is
not
None
:
_check_bias
(
bias
,
input
)
bias
=
bias
.
contiguous
().
view
(
-
1
,
input_size
[
-
2
],
input_size
[
-
1
])
input
=
input
.
view
(
-
1
,
input_size
[
-
2
],
input_size
[
-
1
])
if
input
.
is_cuda
and
input
.
shape
[
-
1
]
<=
2048
:
input_size
=
input
.
size
()
if
mask
is
not
None
:
_check_mask
(
mask
,
input
)
mask
=
mask
.
contiguous
().
view
(
-
1
,
mask
.
shape
[
-
2
],
mask
.
shape
[
-
1
])
if
bias
is
not
None
:
_check_bias
(
bias
,
input
)
bias
=
bias
.
contiguous
().
view
(
-
1
,
input_size
[
-
2
],
input_size
[
-
1
])
input
=
input
.
view
(
-
1
,
input_size
[
-
2
],
input_size
[
-
1
])
return
SoftmaxDropoutFast
.
apply
(
is_training
,
input
,
mask
,
bias
,
dropout_prob
).
view
(
*
input_size
)
else
:
if
mask
is
None
:
if
mask
is
not
None
:
input
+=
mask
if
bias
is
not
None
:
input
+=
bias
return
F
.
dropout
(
F
.
softmax
(
input
,
dim
=-
1
),
p
=
dropout_prob
,
training
=
is_training
).
view
(
*
input_size
)
return
F
.
dropout
(
F
.
softmax
(
input
,
dim
=-
1
),
p
=
dropout_prob
,
training
=
is_training
)
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