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
16263f96
"...git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "c8f7bb990c072c77d8cfc8a6c883ba0c352a5671"
Commit
16263f96
authored
Nov 07, 2019
by
Lysandre
Committed by
Lysandre Debut
Nov 26, 2019
Browse files
Headmasking
parent
abb23a78
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
6 deletions
+6
-6
transformers/modeling_albert.py
transformers/modeling_albert.py
+6
-5
transformers/tests/modeling_albert_test.py
transformers/tests/modeling_albert_test.py
+0
-1
No files found.
transformers/modeling_albert.py
View file @
16263f96
...
...
@@ -224,7 +224,7 @@ class AlbertLayer(nn.Module):
self
.
activation
=
ACT2FN
[
config
.
hidden_act
]
def
forward
(
self
,
hidden_states
,
attention_mask
=
None
,
head_mask
=
None
):
attention_output
=
self
.
attention
(
hidden_states
,
attention_mask
)
attention_output
=
self
.
attention
(
hidden_states
,
attention_mask
,
head_mask
)
ffn_output
=
self
.
ffn
(
attention_output
[
0
])
ffn_output
=
self
.
activation
(
ffn_output
)
ffn_output
=
self
.
ffn_output
(
ffn_output
)
...
...
@@ -245,8 +245,8 @@ class AlbertLayerGroup(nn.Module):
layer_hidden_states
=
()
layer_attentions
=
()
for
albert_layer
in
self
.
albert_layers
:
layer_output
=
albert_layer
(
hidden_states
,
attention_mask
,
head_mask
)
for
layer_index
,
albert_layer
in
enumerate
(
self
.
albert_layers
)
:
layer_output
=
albert_layer
(
hidden_states
,
attention_mask
,
head_mask
[
layer_index
]
)
hidden_states
=
layer_output
[
0
]
if
self
.
output_attentions
:
...
...
@@ -283,7 +283,8 @@ class AlbertTransformer(nn.Module):
for
layer_idx
in
range
(
self
.
config
.
num_hidden_layers
):
group_idx
=
int
(
layer_idx
/
self
.
config
.
num_hidden_layers
*
self
.
config
.
num_hidden_groups
)
layer_group_output
=
self
.
albert_layer_groups
[
group_idx
](
hidden_states
,
attention_mask
,
head_mask
)
layers_per_group
=
int
(
self
.
config
.
num_hidden_layers
/
self
.
config
.
num_hidden_groups
)
layer_group_output
=
self
.
albert_layer_groups
[
group_idx
](
hidden_states
,
attention_mask
,
head_mask
[
group_idx
*
layers_per_group
:(
group_idx
+
1
)
*
layers_per_group
])
hidden_states
=
layer_group_output
[
0
]
...
...
@@ -544,7 +545,7 @@ class AlbertForMaskedLM(AlbertPreTrainedModel):
def
forward
(
self
,
input_ids
,
attention_mask
=
None
,
token_type_ids
=
None
,
position_ids
=
None
,
head_mask
=
None
,
masked_lm_labels
=
None
):
outputs
=
self
.
albert
(
input_ids
,
attention_mask
=
None
,
token_type_ids
=
None
,
position_ids
=
None
,
head_mask
=
None
)
outputs
=
self
.
albert
(
input_ids
,
attention_mask
,
token_type_ids
,
position_ids
,
head_mask
)
sequence_outputs
=
outputs
[
0
]
prediction_scores
=
self
.
predictions
(
sequence_outputs
)
...
...
transformers/tests/modeling_albert_test.py
View file @
16263f96
...
...
@@ -35,7 +35,6 @@ else:
class
AlbertModelTest
(
CommonTestCases
.
CommonModelTester
):
all_model_classes
=
(
AlbertModel
,
AlbertForMaskedLM
)
if
is_torch_available
()
else
()
test_head_masking
=
False
class
AlbertModelTester
(
object
):
...
...
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