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
f8fb4335
Commit
f8fb4335
authored
Dec 05, 2019
by
thomwolf
Browse files
clean up a little bit PT <=> TF conversion
parent
bebaa140
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
5 deletions
+7
-5
transformers/convert_pytorch_checkpoint_to_tf2.py
transformers/convert_pytorch_checkpoint_to_tf2.py
+5
-4
transformers/modeling_utils.py
transformers/modeling_utils.py
+2
-1
No files found.
transformers/convert_pytorch_checkpoint_to_tf2.py
View file @
f8fb4335
...
...
@@ -119,10 +119,11 @@ def convert_pt_checkpoint_to_tf(model_type, pytorch_checkpoint_path, config_file
tf_inputs
=
tf
.
constant
(
inputs_list
)
tfo
=
tf_model
(
tf_inputs
,
training
=
False
)
# build the network
pt_model
=
pt_model_class
.
from_pretrained
(
None
,
config
=
config
,
state_dict
=
torch
.
load
(
pytorch_checkpoint_path
,
map_location
=
'cpu'
))
pt_model
=
pt_model_class
(
config
)
pt_model
.
load_state_dict
(
torch
.
load
(
pytorch_checkpoint_path
,
map_location
=
'cpu'
),
strict
-
False
)
pt_model
.
eval
()
pt_inputs
=
torch
.
tensor
(
inputs_list
)
with
torch
.
no_grad
():
pto
=
pt_model
(
pt_inputs
)
...
...
transformers/modeling_utils.py
View file @
f8fb4335
...
...
@@ -318,7 +318,8 @@ class PreTrainedModel(nn.Module):
model = BertModel.from_pretrained('./tf_model/my_tf_checkpoint.ckpt.index', from_tf=True, config=config)
"""
if
"albert"
in
pretrained_model_name_or_path
and
"v2"
in
pretrained_model_name_or_path
:
if
pretrained_model_name_or_path
is
not
None
and
(
"albert"
in
pretrained_model_name_or_path
and
"v2"
in
pretrained_model_name_or_path
):
logger
.
warning
(
"There is currently an upstream reproducibility issue with ALBERT v2 models. Please see "
+
"https://github.com/google-research/google-research/issues/119 for more information."
)
...
...
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