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
Megatron-LM
Commits
9873a8da
Commit
9873a8da
authored
Mar 26, 2020
by
Neel Kant
Browse files
Reformat parts of BertModel
parent
fd33e930
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
14 deletions
+15
-14
megatron/model/bert_model.py
megatron/model/bert_model.py
+15
-14
No files found.
megatron/model/bert_model.py
View file @
9873a8da
...
@@ -159,6 +159,7 @@ class BertModel(MegatronModule):
...
@@ -159,6 +159,7 @@ class BertModel(MegatronModule):
apply_query_key_layer_scaling
=
apply_query_key_layer_scaling
,
apply_query_key_layer_scaling
=
apply_query_key_layer_scaling
,
attention_softmax_in_fp32
=
attention_softmax_in_fp32
)
attention_softmax_in_fp32
=
attention_softmax_in_fp32
)
if
not
self
.
add_ict_head
:
self
.
lm_head
=
BertLMHead
(
self
.
lm_head
=
BertLMHead
(
self
.
language_model
.
embedding
.
word_embeddings
.
weight
.
size
(
0
),
self
.
language_model
.
embedding
.
word_embeddings
.
weight
.
size
(
0
),
hidden_size
,
init_method
,
layernorm_epsilon
,
parallel_output
)
hidden_size
,
init_method
,
layernorm_epsilon
,
parallel_output
)
...
@@ -192,15 +193,15 @@ class BertModel(MegatronModule):
...
@@ -192,15 +193,15 @@ class BertModel(MegatronModule):
tokentype_ids
=
tokentype_ids
)
tokentype_ids
=
tokentype_ids
)
# Output.
# Output.
if
self
.
add_ict_head
:
ict_logits
=
self
.
ict_head
(
pooled_output
)
return
ict_logits
,
None
lm_logits
=
self
.
lm_head
(
lm_logits
=
self
.
lm_head
(
lm_output
,
self
.
language_model
.
embedding
.
word_embeddings
.
weight
)
lm_output
,
self
.
language_model
.
embedding
.
word_embeddings
.
weight
)
if
self
.
add_binary_head
:
if
self
.
add_binary_head
:
binary_logits
=
self
.
binary_head
(
pooled_output
)
binary_logits
=
self
.
binary_head
(
pooled_output
)
return
lm_logits
,
binary_logits
return
lm_logits
,
binary_logits
elif
self
.
add_ict_head
:
ict_logits
=
self
.
ict_head
(
pooled_output
)
return
lm_logits
,
ict_logits
return
lm_logits
,
None
return
lm_logits
,
None
...
@@ -231,14 +232,14 @@ class BertModel(MegatronModule):
...
@@ -231,14 +232,14 @@ class BertModel(MegatronModule):
self
.
language_model
.
load_state_dict
(
self
.
language_model
.
load_state_dict
(
state_dict
[
self
.
_language_model_key
],
strict
=
strict
)
state_dict
[
self
.
_language_model_key
],
strict
=
strict
)
self
.
lm_head
.
load_state_dict
(
state_dict
[
self
.
_lm_head_key
],
self
.
lm_head
.
load_state_dict
(
strict
=
strict
)
state_dict
[
self
.
_lm_head_key
],
strict
=
strict
)
if
self
.
add_binary_head
:
if
self
.
add_binary_head
:
self
.
binary_head
.
load_state_dict
(
state_dict
[
self
.
_binary_head_key
],
self
.
binary_head
.
load_state_dict
(
strict
=
strict
)
state_dict
[
self
.
_binary_head_key
],
strict
=
strict
)
elif
self
.
add_ict_head
:
elif
self
.
add_ict_head
:
self
.
ict_head
.
load_state_dict
(
state_dict
[
self
.
_ict_head_key
],
self
.
ict_head
.
load_state_dict
(
strict
=
strict
)
state_dict
[
self
.
_ict_head_key
],
strict
=
strict
)
class
ICTBertModel
(
MegatronModule
):
class
ICTBertModel
(
MegatronModule
):
...
...
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