Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
5d29f8e9
Commit
5d29f8e9
authored
Aug 28, 2019
by
VictorSanh
Browse files
fix bugs
parent
a8ad8304
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
1 deletion
+5
-1
pytorch_transformers/modeling_dilbert.py
pytorch_transformers/modeling_dilbert.py
+5
-1
No files found.
pytorch_transformers/modeling_dilbert.py
View file @
5d29f8e9
...
@@ -274,7 +274,8 @@ class TransformerBlock(nn.Module):
...
@@ -274,7 +274,8 @@ class TransformerBlock(nn.Module):
sa_output
=
self
.
attention
(
query
=
x
,
key
=
x
,
value
=
x
,
mask
=
attn_mask
)
sa_output
=
self
.
attention
(
query
=
x
,
key
=
x
,
value
=
x
,
mask
=
attn_mask
)
if
self
.
output_attentions
:
if
self
.
output_attentions
:
sa_output
,
sa_weights
=
sa_output
# (bs, seq_length, dim), (bs, n_heads, seq_length, seq_length)
sa_output
,
sa_weights
=
sa_output
# (bs, seq_length, dim), (bs, n_heads, seq_length, seq_length)
else
:
else
:
# To handle these `output_attention` or `output_hidden_states` cases returning tuples
assert
type
(
sa_output
)
==
tuple
sa_output
=
sa_output
[
0
]
sa_output
=
sa_output
[
0
]
sa_output
=
self
.
sa_layer_norm
(
sa_output
+
x
)
# (bs, seq_length, dim)
sa_output
=
self
.
sa_layer_norm
(
sa_output
+
x
)
# (bs, seq_length, dim)
...
@@ -329,6 +330,9 @@ class Transformer(nn.Module):
...
@@ -329,6 +330,9 @@ class Transformer(nn.Module):
if
self
.
output_attentions
:
if
self
.
output_attentions
:
attentions
,
hidden_state
=
hidden_state
attentions
,
hidden_state
=
hidden_state
all_attentions
=
all_attentions
+
(
attentions
,)
all_attentions
=
all_attentions
+
(
attentions
,)
else
:
# To handle these `output_attention` or `output_hidden_states` cases returning tuples
assert
type
(
hidden_state
)
==
tuple
hidden_state
=
hidden_state
[
0
]
all_hidden_states
=
all_hidden_states
+
(
hidden_state
,)
all_hidden_states
=
all_hidden_states
+
(
hidden_state
,)
outputs
=
(
hidden_state
,)
outputs
=
(
hidden_state
,)
...
...
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