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
bf34a252
Commit
bf34a252
authored
Oct 07, 2019
by
jinoobaek-qz
Committed by
Lysandre Debut
Oct 09, 2019
Browse files
Golden path
parent
528d3f32
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
17 deletions
+19
-17
examples/run_lm_finetuning.py
examples/run_lm_finetuning.py
+19
-17
No files found.
examples/run_lm_finetuning.py
View file @
bf34a252
...
@@ -114,23 +114,25 @@ def _rotate_checkpoints(args, checkpoint_prefix, use_mtime=False):
...
@@ -114,23 +114,25 @@ def _rotate_checkpoints(args, checkpoint_prefix, use_mtime=False):
# Check if we should delete older checkpoint(s)
# Check if we should delete older checkpoint(s)
glob_checkpoints
=
glob
.
glob
(
os
.
path
.
join
(
args
.
output_dir
,
'{}-*'
.
format
(
checkpoint_prefix
)))
glob_checkpoints
=
glob
.
glob
(
os
.
path
.
join
(
args
.
output_dir
,
'{}-*'
.
format
(
checkpoint_prefix
)))
if
len
(
glob_checkpoints
)
>
args
.
save_total_limit
:
if
len
(
glob_checkpoints
)
<=
args
.
save_total_limit
:
checkpoints_sorted
=
[]
return
for
path
in
glob_checkpoints
:
regex_match
=
re
.
match
(
'.*{}-([0-9]+)'
.
format
(
checkpoint_prefix
),
path
)
checkpoints_sorted
=
[]
if
regex_match
and
regex_match
.
groups
():
for
path
in
glob_checkpoints
:
if
use_mtime
:
regex_match
=
re
.
match
(
'.*{}-([0-9]+)'
.
format
(
checkpoint_prefix
),
path
)
checkpoints_sorted
.
append
((
os
.
path
.
getmtime
(
path
),
path
))
if
regex_match
and
regex_match
.
groups
():
else
:
if
use_mtime
:
checkpoints_sorted
.
append
((
int
(
regex_match
.
groups
()[
0
]),
path
))
checkpoints_sorted
.
append
((
os
.
path
.
getmtime
(
path
),
path
))
else
:
checkpoints_sorted
=
sorted
(
checkpoints_sorted
)
checkpoints_sorted
.
append
((
int
(
regex_match
.
groups
()[
0
]),
path
))
checkpoints_sorted
=
[
checkpoint
[
1
]
for
checkpoint
in
checkpoints_sorted
]
number_of_checkpoints_to_delete
=
max
(
0
,
len
(
checkpoints_sorted
)
-
args
.
save_total_limit
)
checkpoints_sorted
=
sorted
(
checkpoints_sorted
)
checkpoints_to_be_deleted
=
checkpoints_sorted
[:
number_of_checkpoints_to_delete
]
checkpoints_sorted
=
[
checkpoint
[
1
]
for
checkpoint
in
checkpoints_sorted
]
for
checkpoint
in
checkpoints_to_be_deleted
:
number_of_checkpoints_to_delete
=
max
(
0
,
len
(
checkpoints_sorted
)
-
args
.
save_total_limit
)
logger
.
info
(
"Deleting older checkpoint [{}] due to args.save_total_limit"
.
format
(
checkpoint
))
checkpoints_to_be_deleted
=
checkpoints_sorted
[:
number_of_checkpoints_to_delete
]
shutil
.
rmtree
(
checkpoint
)
for
checkpoint
in
checkpoints_to_be_deleted
:
logger
.
info
(
"Deleting older checkpoint [{}] due to args.save_total_limit"
.
format
(
checkpoint
))
shutil
.
rmtree
(
checkpoint
)
def
mask_tokens
(
inputs
,
tokenizer
,
args
):
def
mask_tokens
(
inputs
,
tokenizer
,
args
):
...
...
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