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
c90119e5
Commit
c90119e5
authored
Jul 29, 2019
by
David Pollack
Browse files
spelling mistake
parent
09ecf225
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
2 deletions
+2
-2
pytorch_transformers/convert_pytorch_checkpoint_to_tf.py
pytorch_transformers/convert_pytorch_checkpoint_to_tf.py
+2
-2
No files found.
pytorch_transformers/convert_pytorch_checkpoint_to_tf.py
View file @
c90119e5
...
@@ -41,7 +41,7 @@ def convert_pytorch_checkpoint_to_tf(model:BertModel, ckpt_dir:str, model_name:s
...
@@ -41,7 +41,7 @@ def convert_pytorch_checkpoint_to_tf(model:BertModel, ckpt_dir:str, model_name:s
N BertForQuestionAnswering
N BertForQuestionAnswering
"""
"""
tensors_to_trans
o
pse
=
(
tensors_to_transp
o
se
=
(
"dense.weight"
,
"dense.weight"
,
"attention.self.query"
,
"attention.self.query"
,
"attention.self.key"
,
"attention.self.key"
,
...
@@ -81,7 +81,7 @@ def convert_pytorch_checkpoint_to_tf(model:BertModel, ckpt_dir:str, model_name:s
...
@@ -81,7 +81,7 @@ def convert_pytorch_checkpoint_to_tf(model:BertModel, ckpt_dir:str, model_name:s
for
var_name
in
state_dict
:
for
var_name
in
state_dict
:
tf_name
=
to_tf_var_name
(
var_name
)
tf_name
=
to_tf_var_name
(
var_name
)
torch_tensor
=
state_dict
[
var_name
].
numpy
()
torch_tensor
=
state_dict
[
var_name
].
numpy
()
if
any
([
x
in
var_name
for
x
in
tensors_to_trans
o
pse
]):
if
any
([
x
in
var_name
for
x
in
tensors_to_transp
o
se
]):
torch_tensor
=
torch_tensor
.
T
torch_tensor
=
torch_tensor
.
T
tf_var
=
create_tf_var
(
tensor
=
torch_tensor
,
name
=
tf_name
,
session
=
session
)
tf_var
=
create_tf_var
(
tensor
=
torch_tensor
,
name
=
tf_name
,
session
=
session
)
tf
.
keras
.
backend
.
set_value
(
tf_var
,
torch_tensor
)
tf
.
keras
.
backend
.
set_value
(
tf_var
,
torch_tensor
)
...
...
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