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
ef46ccb0
Unverified
Commit
ef46ccb0
authored
May 14, 2020
by
Lysandre Debut
Committed by
GitHub
May 14, 2020
Browse files
TPU needs a rendezvous (#4339)
parent
94cb73c2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
1 deletion
+20
-1
src/transformers/trainer.py
src/transformers/trainer.py
+20
-1
No files found.
src/transformers/trainer.py
View file @
ef46ccb0
...
...
@@ -542,9 +542,28 @@ class Trainer:
Will only save from the master process.
"""
if
self
.
is_world_master
():
if
is_tpu_available
():
self
.
_save_tpu
(
output_dir
)
elif
self
.
is_world_master
():
self
.
_save
(
output_dir
)
def
_save_tpu
(
self
,
output_dir
:
Optional
[
str
]
=
None
):
output_dir
=
output_dir
if
output_dir
is
not
None
else
self
.
args
.
output_dir
logger
.
info
(
"Saving model checkpoint to %s"
,
output_dir
)
if
xm
.
is_master_ordinal
():
os
.
makedirs
(
output_dir
,
exist_ok
=
True
)
torch
.
save
(
self
.
args
,
os
.
path
.
join
(
output_dir
,
"training_args.bin"
))
# Save a trained model and configuration using `save_pretrained()`.
# They can then be reloaded using `from_pretrained()`
if
not
isinstance
(
self
.
model
,
PreTrainedModel
):
raise
ValueError
(
"Trainer.model appears to not be a PreTrainedModel"
)
xm
.
rendezvous
(
"saving_checkpoint"
)
self
.
model
.
save_pretrained
(
output_dir
)
def
_save
(
self
,
output_dir
:
Optional
[
str
]
=
None
):
output_dir
=
output_dir
if
output_dir
is
not
None
else
self
.
args
.
output_dir
os
.
makedirs
(
output_dir
,
exist_ok
=
True
)
...
...
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