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
f71b1bb0
"...ops/git@developer.sourcefind.cn:OpenDAS/mmdetection3d.git" did not exist on "7a872356765429251de4a9ec2e8f291736db9a34"
Commit
f71b1bb0
authored
Nov 27, 2019
by
Bilal Khan
Committed by
Lysandre Debut
Dec 09, 2019
Browse files
Save optimizer state, scheduler state and current epoch
parent
0cb16386
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
1 deletion
+5
-1
examples/run_lm_finetuning.py
examples/run_lm_finetuning.py
+5
-1
No files found.
examples/run_lm_finetuning.py
View file @
f71b1bb0
...
...
@@ -224,7 +224,7 @@ def train(args, train_dataset, model, tokenizer):
model
.
zero_grad
()
train_iterator
=
trange
(
int
(
args
.
num_train_epochs
),
desc
=
"Epoch"
,
disable
=
args
.
local_rank
not
in
[
-
1
,
0
])
set_seed
(
args
)
# Added here for reproducibility (even between python 2 and 3)
for
_
in
train_iterator
:
for
epoch
in
train_iterator
:
epoch_iterator
=
tqdm
(
train_dataloader
,
desc
=
"Iteration"
,
disable
=
args
.
local_rank
not
in
[
-
1
,
0
])
for
step
,
batch
in
enumerate
(
epoch_iterator
):
inputs
,
labels
=
mask_tokens
(
batch
,
tokenizer
,
args
)
if
args
.
mlm
else
(
batch
,
batch
)
...
...
@@ -279,6 +279,10 @@ def train(args, train_dataset, model, tokenizer):
_rotate_checkpoints
(
args
,
checkpoint_prefix
)
torch
.
save
(
optimizer
.
state_dict
(),
os
.
path
.
join
(
output_dir
,
'optimizer.pt'
))
torch
.
save
(
scheduler
.
state_dict
(),
os
.
path
.
join
(
output_dir
,
'scheduler.pt'
))
torch
.
save
(
epoch
,
os
.
path
.
join
(
output_dir
,
'training_state.pt'
))
if
args
.
max_steps
>
0
and
global_step
>
args
.
max_steps
:
epoch_iterator
.
close
()
break
...
...
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