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
8d5b7f36
Unverified
Commit
8d5b7f36
authored
Jun 21, 2021
by
Suraj Patil
Committed by
GitHub
Jun 21, 2021
Browse files
[FlaxClip] fix test from/save pretrained test (#12284)
* boom boom * remove flax clip example * fix from_save_pretrained
parent
b53bc55b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
tests/test_modeling_flax_clip.py
tests/test_modeling_flax_clip.py
+34
-0
No files found.
tests/test_modeling_flax_clip.py
View file @
8d5b7f36
...
@@ -511,3 +511,37 @@ class FlaxCLIPModelTest(FlaxModelTesterMixin, unittest.TestCase):
...
@@ -511,3 +511,37 @@ class FlaxCLIPModelTest(FlaxModelTesterMixin, unittest.TestCase):
)
)
for
fx_output
,
pt_output
in
zip
(
fx_outputs
[:
4
],
pt_outputs_loaded
[:
4
]):
for
fx_output
,
pt_output
in
zip
(
fx_outputs
[:
4
],
pt_outputs_loaded
[:
4
]):
self
.
assert_almost_equals
(
fx_output
,
pt_output
.
numpy
(),
4e-2
)
self
.
assert_almost_equals
(
fx_output
,
pt_output
.
numpy
(),
4e-2
)
# overwrite from common since FlaxCLIPModel returns nested output
# which is not supported in the common test
def
test_from_pretrained_save_pretrained
(
self
):
config
,
inputs_dict
=
self
.
model_tester
.
prepare_config_and_inputs_for_common
()
for
model_class
in
self
.
all_model_classes
:
if
model_class
.
__name__
!=
"FlaxBertModel"
:
continue
with
self
.
subTest
(
model_class
.
__name__
):
model
=
model_class
(
config
)
prepared_inputs_dict
=
self
.
_prepare_for_class
(
inputs_dict
,
model_class
)
outputs
=
model
(
**
prepared_inputs_dict
).
to_tuple
()
# verify that normal save_pretrained works as expected
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
model
.
save_pretrained
(
tmpdirname
)
model_loaded
=
model_class
.
from_pretrained
(
tmpdirname
)
outputs_loaded
=
model_loaded
(
**
prepared_inputs_dict
).
to_tuple
()[:
4
]
for
output_loaded
,
output
in
zip
(
outputs_loaded
,
outputs
):
self
.
assert_almost_equals
(
output_loaded
,
output
,
1e-3
)
# verify that save_pretrained for distributed training
# with `params=params` works as expected
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
model
.
save_pretrained
(
tmpdirname
,
params
=
model
.
params
)
model_loaded
=
model_class
.
from_pretrained
(
tmpdirname
)
outputs_loaded
=
model_loaded
(
**
prepared_inputs_dict
).
to_tuple
()[:
4
]
for
output_loaded
,
output
in
zip
(
outputs_loaded
,
outputs
):
self
.
assert_almost_equals
(
output_loaded
,
output
,
1e-3
)
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