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
439e7abd
Unverified
Commit
439e7abd
authored
Aug 30, 2021
by
Hwijeen Ahn
Committed by
GitHub
Aug 30, 2021
Browse files
use float 16 in causal mask and masked bias (#13194)
parent
8be921f9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
2 deletions
+2
-2
src/transformers/models/megatron_gpt2/convert_megatron_gpt2_checkpoint.py
.../models/megatron_gpt2/convert_megatron_gpt2_checkpoint.py
+2
-2
No files found.
src/transformers/models/megatron_gpt2/convert_megatron_gpt2_checkpoint.py
View file @
439e7abd
...
@@ -157,11 +157,11 @@ def convert_megatron_checkpoint(args, input_state_dict, config):
...
@@ -157,11 +157,11 @@ def convert_megatron_checkpoint(args, input_state_dict, config):
)
and
weight_or_bias
==
"weight"
:
)
and
weight_or_bias
==
"weight"
:
# Insert a tensor of 1x1xDxD bias.
# Insert a tensor of 1x1xDxD bias.
causal_mask
=
torch
.
tril
(
torch
.
ones
((
n_embed
,
n_embed
),
dtype
=
torch
.
uint8
)).
view
(
1
,
1
,
n_embed
,
n_embed
)
causal_mask
=
torch
.
tril
(
torch
.
ones
((
n_embed
,
n_embed
),
dtype
=
torch
.
float16
)).
view
(
1
,
1
,
n_embed
,
n_embed
)
output_state_dict
[
layer_name
+
".attn.bias"
]
=
causal_mask
output_state_dict
[
layer_name
+
".attn.bias"
]
=
causal_mask
# Insert a "dummy" tensor for masked_bias.
# Insert a "dummy" tensor for masked_bias.
masked_bias
=
torch
.
tensor
(
-
1e4
)
masked_bias
=
torch
.
tensor
(
-
1e4
,
dtype
=
torch
.
float16
)
output_state_dict
[
layer_name
+
".attn.masked_bias"
]
=
masked_bias
output_state_dict
[
layer_name
+
".attn.masked_bias"
]
=
masked_bias
out_val
=
fix_query_key_value_ordering
(
val
,
checkpoint_version
,
3
,
heads
,
hidden_size_per_head
)
out_val
=
fix_query_key_value_ordering
(
val
,
checkpoint_version
,
3
,
heads
,
hidden_size_per_head
)
...
...
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