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
chenpangpang
transformers
Commits
3ec7d4cf
Unverified
Commit
3ec7d4cf
authored
Jun 27, 2022
by
Younes Belkada
Committed by
GitHub
Jun 27, 2022
Browse files
fix mask (#17837)
parent
ee0d001d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
src/transformers/models/bloom/modeling_bloom.py
src/transformers/models/bloom/modeling_bloom.py
+11
-11
No files found.
src/transformers/models/bloom/modeling_bloom.py
View file @
3ec7d4cf
...
@@ -292,17 +292,17 @@ class BloomScaledSoftmax(nn.Module):
...
@@ -292,17 +292,17 @@ class BloomScaledSoftmax(nn.Module):
if
self
.
scale
is
not
None
:
if
self
.
scale
is
not
None
:
input
=
input
*
self
.
scale
input
=
input
*
self
.
scale
if
mask
is
not
None
:
if
mask
is
None
:
mask
=
mask
.
to
(
input
.
device
)
mask
=
torch
.
ones
(
input
.
shape
[
0
],
max_positions
,
dtype
=
torch
.
bool
,
device
=
input
.
device
)
causal_mask
=
(
torch
.
tril
(
torch
.
ones
((
max_positions
,
max_positions
),
dtype
=
torch
.
bool
)
)
mask
=
mask
.
to
(
input
.
device
)
.
view
(
1
,
1
,
max_positions
,
max_positions
)
causal_mask
=
(
.
to
(
input
.
device
)
torch
.
tril
(
torch
.
ones
((
max_positions
,
max_positions
),
dtype
=
torch
.
bool
)
)
)
.
view
(
1
,
1
,
max_positions
,
max_positions
)
mask_output
,
padded_causal_mask
=
self
.
mask_func
(
input
,
mask
,
causal_mask
)
.
to
(
input
.
device
)
probs
=
nn
.
functional
.
softmax
(
mask_output
,
dim
=-
1
,
dtype
=
softmax_dtype
)
*
(
~
padded_causal_mask
)
)
else
:
mask_output
,
padded_causal_mask
=
self
.
mask_func
(
input
,
mask
,
causal_mask
)
probs
=
nn
.
functional
.
softmax
(
in
put
,
dim
=-
1
,
dtype
=
softmax_dtype
)
probs
=
nn
.
functional
.
softmax
(
mask_out
put
,
dim
=-
1
,
dtype
=
softmax_dtype
)
*
(
~
padded_causal_mask
)
if
input_in_16bit
and
self
.
softmax_in_fp32
:
if
input_in_16bit
and
self
.
softmax_in_fp32
:
probs
=
probs
.
to
(
dtype
=
input_dtype
)
probs
=
probs
.
to
(
dtype
=
input_dtype
)
...
...
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