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
05a93067
Unverified
Commit
05a93067
authored
May 10, 2021
by
Sylvain Gugger
Committed by
GitHub
May 10, 2021
Browse files
Save scaler state dict when checkpointing (#11663)
parent
ef8d32c5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
0 deletions
+6
-0
src/transformers/trainer.py
src/transformers/trainer.py
+6
-0
No files found.
src/transformers/trainer.py
View file @
05a93067
...
@@ -1480,12 +1480,16 @@ class Trainer:
...
@@ -1480,12 +1480,16 @@ class Trainer:
with
warnings
.
catch_warnings
(
record
=
True
)
as
caught_warnings
:
with
warnings
.
catch_warnings
(
record
=
True
)
as
caught_warnings
:
torch
.
save
(
self
.
lr_scheduler
.
state_dict
(),
os
.
path
.
join
(
output_dir
,
"scheduler.pt"
))
torch
.
save
(
self
.
lr_scheduler
.
state_dict
(),
os
.
path
.
join
(
output_dir
,
"scheduler.pt"
))
reissue_pt_warnings
(
caught_warnings
)
reissue_pt_warnings
(
caught_warnings
)
if
self
.
use_amp
:
torch
.
save
(
self
.
scaler
.
state_dict
(),
os
.
path
.
join
(
output_dir
,
"scaler.pt"
))
elif
self
.
is_world_process_zero
()
and
not
self
.
deepspeed
:
elif
self
.
is_world_process_zero
()
and
not
self
.
deepspeed
:
# deepspeed.save_checkpoint above saves model/optim/sched
# deepspeed.save_checkpoint above saves model/optim/sched
torch
.
save
(
self
.
optimizer
.
state_dict
(),
os
.
path
.
join
(
output_dir
,
"optimizer.pt"
))
torch
.
save
(
self
.
optimizer
.
state_dict
(),
os
.
path
.
join
(
output_dir
,
"optimizer.pt"
))
with
warnings
.
catch_warnings
(
record
=
True
)
as
caught_warnings
:
with
warnings
.
catch_warnings
(
record
=
True
)
as
caught_warnings
:
torch
.
save
(
self
.
lr_scheduler
.
state_dict
(),
os
.
path
.
join
(
output_dir
,
"scheduler.pt"
))
torch
.
save
(
self
.
lr_scheduler
.
state_dict
(),
os
.
path
.
join
(
output_dir
,
"scheduler.pt"
))
reissue_pt_warnings
(
caught_warnings
)
reissue_pt_warnings
(
caught_warnings
)
if
self
.
use_amp
:
torch
.
save
(
self
.
scaler
.
state_dict
(),
os
.
path
.
join
(
output_dir
,
"scaler.pt"
))
# Determine the new best metric / best model checkpoint
# Determine the new best metric / best model checkpoint
if
metrics
is
not
None
and
self
.
args
.
metric_for_best_model
is
not
None
:
if
metrics
is
not
None
and
self
.
args
.
metric_for_best_model
is
not
None
:
...
@@ -1569,6 +1573,8 @@ class Trainer:
...
@@ -1569,6 +1573,8 @@ class Trainer:
with
warnings
.
catch_warnings
(
record
=
True
)
as
caught_warnings
:
with
warnings
.
catch_warnings
(
record
=
True
)
as
caught_warnings
:
self
.
lr_scheduler
.
load_state_dict
(
torch
.
load
(
os
.
path
.
join
(
checkpoint
,
"scheduler.pt"
)))
self
.
lr_scheduler
.
load_state_dict
(
torch
.
load
(
os
.
path
.
join
(
checkpoint
,
"scheduler.pt"
)))
reissue_pt_warnings
(
caught_warnings
)
reissue_pt_warnings
(
caught_warnings
)
if
self
.
use_amp
and
os
.
path
.
isfile
(
os
.
path
.
join
(
checkpoint
,
"scaler.pt"
)):
self
.
scaler
.
load_state_dict
(
torch
.
load
(
os
.
path
.
join
(
checkpoint
,
"scaler.pt"
)))
def
hyperparameter_search
(
def
hyperparameter_search
(
self
,
self
,
...
...
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