Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mednet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
medai
software
mednet
Commits
826d392e
Commit
826d392e
authored
1 year ago
by
Daniel CARRON
Committed by
André Anjos
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Resume from last checkpoint by default if exists in output_folder
parent
9f737974
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Making use of LightningDataModule and simplification of data loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ptbench/utils/checkpointer.py
+15
-6
15 additions, 6 deletions
src/ptbench/utils/checkpointer.py
with
15 additions
and
6 deletions
src/ptbench/utils/checkpointer.py
+
15
−
6
View file @
826d392e
import
logging
import
logging
import
os
import
os
import
typing
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
def
get_checkpoint
(
output_folder
,
resume_from
)
:
def
get_checkpoint
(
output_folder
:
str
,
resume_from
:
typing
.
Literal
[
"
last
"
,
"
best
"
]
|
str
|
None
)
->
str
|
None
:
"""
Gets a checkpoint file.
"""
Gets a checkpoint file.
Can return the best or last checkpoint, or a checkpoint at a specific path.
Can return the best or last checkpoint, or a checkpoint at a specific path.
Ensures the checkpoint exists, raising an error if it is not the case.
Ensures the checkpoint exists, raising an error if it is not the case.
If resume_from is None, checks the output directory if a checkpoint already exists and returns it.
If no checkpoint is found, returns None.
Parameters
Parameters
----------
----------
output_folder
: :py:class:`str`
output_folder
:
Directory in which checkpoints are stored.
Directory in which checkpoints are stored.
resume_from
: :py:class:`str`
resume_from
:
Which model to get. Can be one of
"
best
"
,
"
last
"
, or a path to a checkpoint.
Which model to get. Can be one of
"
best
"
,
"
last
"
, or a path to a checkpoint.
If None, gets the last checkpoint if it exists, otherwise returns None
Returns
Returns
-------
-------
checkpoint_file
: :py:class:`str`
checkpoint_file
:
T
he requested
model
.
Path to t
he requested
checkpoint or None
.
"""
"""
last_checkpoint_path
=
os
.
path
.
join
(
output_folder
,
"
model_final_epoch.ckpt
"
)
last_checkpoint_path
=
os
.
path
.
join
(
output_folder
,
"
model_final_epoch.ckpt
"
)
best_checkpoint_path
=
os
.
path
.
join
(
best_checkpoint_path
=
os
.
path
.
join
(
...
@@ -49,7 +54,11 @@ def get_checkpoint(output_folder, resume_from):
...
@@ -49,7 +54,11 @@ def get_checkpoint(output_folder, resume_from):
)
)
elif
resume_from
is
None
:
elif
resume_from
is
None
:
checkpoint_file
=
None
if
os
.
path
.
isfile
(
last_checkpoint_path
):
checkpoint_file
=
last_checkpoint_path
logger
.
info
(
f
"
Found existing checkpoint
{
last_checkpoint_path
}
. Loading.
"
)
else
:
return
None
else
:
else
:
if
os
.
path
.
isfile
(
resume_from
):
if
os
.
path
.
isfile
(
resume_from
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment