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
01ab39b6
Unverified
Commit
01ab39b6
authored
Aug 08, 2023
by
Zach Mueller
Committed by
GitHub
Aug 08, 2023
Browse files
Load state in else (#25318)
* Load else * New approach * Propagate
parent
36d5b8b0
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
72 additions
and
24 deletions
+72
-24
examples/pytorch/image-classification/run_image_classification_no_trainer.py
...age-classification/run_image_classification_no_trainer.py
+6
-2
examples/pytorch/image-pretraining/run_mim_no_trainer.py
examples/pytorch/image-pretraining/run_mim_no_trainer.py
+6
-2
examples/pytorch/language-modeling/run_clm_no_trainer.py
examples/pytorch/language-modeling/run_clm_no_trainer.py
+6
-2
examples/pytorch/language-modeling/run_mlm_no_trainer.py
examples/pytorch/language-modeling/run_mlm_no_trainer.py
+6
-2
examples/pytorch/multiple-choice/run_swag_no_trainer.py
examples/pytorch/multiple-choice/run_swag_no_trainer.py
+6
-2
examples/pytorch/question-answering/run_qa_beam_search_no_trainer.py
...torch/question-answering/run_qa_beam_search_no_trainer.py
+6
-2
examples/pytorch/question-answering/run_qa_no_trainer.py
examples/pytorch/question-answering/run_qa_no_trainer.py
+6
-2
examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py
...ntic-segmentation/run_semantic_segmentation_no_trainer.py
+6
-2
examples/pytorch/summarization/run_summarization_no_trainer.py
...les/pytorch/summarization/run_summarization_no_trainer.py
+6
-2
examples/pytorch/text-classification/run_glue_no_trainer.py
examples/pytorch/text-classification/run_glue_no_trainer.py
+6
-2
examples/pytorch/token-classification/run_ner_no_trainer.py
examples/pytorch/token-classification/run_ner_no_trainer.py
+6
-2
examples/pytorch/translation/run_translation_no_trainer.py
examples/pytorch/translation/run_translation_no_trainer.py
+6
-2
No files found.
examples/pytorch/image-classification/run_image_classification_no_trainer.py
View file @
01ab39b6
...
@@ -454,14 +454,18 @@ def main():
...
@@ -454,14 +454,18 @@ def main():
# Potentially load in the weights and states from a previous save
# Potentially load in the weights and states from a previous save
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
accelerator
.
print
(
f
"Resumed from checkpoint:
{
args
.
resume_from_checkpoint
}
"
)
checkpoint_path
=
args
.
resume_from_checkpoint
accelerator
.
load_state
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
else
:
else
:
# Get the most recent checkpoint
# Get the most recent checkpoint
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
checkpoint_path
=
path
path
=
os
.
path
.
basename
(
checkpoint_path
)
accelerator
.
print
(
f
"Resumed from checkpoint:
{
checkpoint_path
}
"
)
accelerator
.
load_state
(
path
)
# Extract `epoch_{i}` or `step_{i}`
# Extract `epoch_{i}` or `step_{i}`
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
...
...
examples/pytorch/image-pretraining/run_mim_no_trainer.py
View file @
01ab39b6
...
@@ -664,14 +664,18 @@ def main():
...
@@ -664,14 +664,18 @@ def main():
# Potentially load in the weights and states from a previous save
# Potentially load in the weights and states from a previous save
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
accelerator
.
print
(
f
"Resumed from checkpoint:
{
args
.
resume_from_checkpoint
}
"
)
checkpoint_path
=
args
.
resume_from_checkpoint
accelerator
.
load_state
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
else
:
else
:
# Get the most recent checkpoint
# Get the most recent checkpoint
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
checkpoint_path
=
path
path
=
os
.
path
.
basename
(
checkpoint_path
)
accelerator
.
print
(
f
"Resumed from checkpoint:
{
checkpoint_path
}
"
)
accelerator
.
load_state
(
path
)
# Extract `epoch_{i}` or `step_{i}`
# Extract `epoch_{i}` or `step_{i}`
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
...
...
examples/pytorch/language-modeling/run_clm_no_trainer.py
View file @
01ab39b6
...
@@ -575,14 +575,18 @@ def main():
...
@@ -575,14 +575,18 @@ def main():
# Potentially load in the weights and states from a previous save
# Potentially load in the weights and states from a previous save
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
accelerator
.
print
(
f
"Resumed from checkpoint:
{
args
.
resume_from_checkpoint
}
"
)
checkpoint_path
=
args
.
resume_from_checkpoint
accelerator
.
load_state
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
else
:
else
:
# Get the most recent checkpoint
# Get the most recent checkpoint
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
checkpoint_path
=
path
path
=
os
.
path
.
basename
(
checkpoint_path
)
accelerator
.
print
(
f
"Resumed from checkpoint:
{
checkpoint_path
}
"
)
accelerator
.
load_state
(
path
)
# Extract `epoch_{i}` or `step_{i}`
# Extract `epoch_{i}` or `step_{i}`
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
...
...
examples/pytorch/language-modeling/run_mlm_no_trainer.py
View file @
01ab39b6
...
@@ -613,14 +613,18 @@ def main():
...
@@ -613,14 +613,18 @@ def main():
# Potentially load in the weights and states from a previous save
# Potentially load in the weights and states from a previous save
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
accelerator
.
print
(
f
"Resumed from checkpoint:
{
args
.
resume_from_checkpoint
}
"
)
checkpoint_path
=
args
.
resume_from_checkpoint
accelerator
.
load_state
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
else
:
else
:
# Get the most recent checkpoint
# Get the most recent checkpoint
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
checkpoint_path
=
path
path
=
os
.
path
.
basename
(
checkpoint_path
)
accelerator
.
print
(
f
"Resumed from checkpoint:
{
checkpoint_path
}
"
)
accelerator
.
load_state
(
path
)
# Extract `epoch_{i}` or `step_{i}`
# Extract `epoch_{i}` or `step_{i}`
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
...
...
examples/pytorch/multiple-choice/run_swag_no_trainer.py
View file @
01ab39b6
...
@@ -560,14 +560,18 @@ def main():
...
@@ -560,14 +560,18 @@ def main():
# Potentially load in the weights and states from a previous save
# Potentially load in the weights and states from a previous save
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
accelerator
.
print
(
f
"Resumed from checkpoint:
{
args
.
resume_from_checkpoint
}
"
)
checkpoint_path
=
args
.
resume_from_checkpoint
accelerator
.
load_state
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
else
:
else
:
# Get the most recent checkpoint
# Get the most recent checkpoint
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
checkpoint_path
=
path
path
=
os
.
path
.
basename
(
checkpoint_path
)
accelerator
.
print
(
f
"Resumed from checkpoint:
{
checkpoint_path
}
"
)
accelerator
.
load_state
(
path
)
# Extract `epoch_{i}` or `step_{i}`
# Extract `epoch_{i}` or `step_{i}`
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
...
...
examples/pytorch/question-answering/run_qa_beam_search_no_trainer.py
View file @
01ab39b6
...
@@ -797,14 +797,18 @@ def main():
...
@@ -797,14 +797,18 @@ def main():
# Potentially load in the weights and states from a previous save
# Potentially load in the weights and states from a previous save
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
accelerator
.
print
(
f
"Resumed from checkpoint:
{
args
.
resume_from_checkpoint
}
"
)
checkpoint_path
=
args
.
resume_from_checkpoint
accelerator
.
load_state
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
else
:
else
:
# Get the most recent checkpoint
# Get the most recent checkpoint
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
checkpoint_path
=
path
path
=
os
.
path
.
basename
(
checkpoint_path
)
accelerator
.
print
(
f
"Resumed from checkpoint:
{
checkpoint_path
}
"
)
accelerator
.
load_state
(
path
)
# Extract `epoch_{i}` or `step_{i}`
# Extract `epoch_{i}` or `step_{i}`
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
...
...
examples/pytorch/question-answering/run_qa_no_trainer.py
View file @
01ab39b6
...
@@ -828,14 +828,18 @@ def main():
...
@@ -828,14 +828,18 @@ def main():
# Potentially load in the weights and states from a previous save
# Potentially load in the weights and states from a previous save
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
accelerator
.
print
(
f
"Resumed from checkpoint:
{
args
.
resume_from_checkpoint
}
"
)
checkpoint_path
=
args
.
resume_from_checkpoint
accelerator
.
load_state
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
else
:
else
:
# Get the most recent checkpoint
# Get the most recent checkpoint
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
checkpoint_path
=
path
path
=
os
.
path
.
basename
(
checkpoint_path
)
accelerator
.
print
(
f
"Resumed from checkpoint:
{
checkpoint_path
}
"
)
accelerator
.
load_state
(
path
)
# Extract `epoch_{i}` or `step_{i}`
# Extract `epoch_{i}` or `step_{i}`
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
...
...
examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py
View file @
01ab39b6
...
@@ -558,14 +558,18 @@ def main():
...
@@ -558,14 +558,18 @@ def main():
# Potentially load in the weights and states from a previous save
# Potentially load in the weights and states from a previous save
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
accelerator
.
print
(
f
"Resumed from checkpoint:
{
args
.
resume_from_checkpoint
}
"
)
checkpoint_path
=
args
.
resume_from_checkpoint
accelerator
.
load_state
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
else
:
else
:
# Get the most recent checkpoint
# Get the most recent checkpoint
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
checkpoint_path
=
path
path
=
os
.
path
.
basename
(
checkpoint_path
)
accelerator
.
print
(
f
"Resumed from checkpoint:
{
checkpoint_path
}
"
)
accelerator
.
load_state
(
path
)
# Extract `epoch_{i}` or `step_{i}`
# Extract `epoch_{i}` or `step_{i}`
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
...
...
examples/pytorch/summarization/run_summarization_no_trainer.py
View file @
01ab39b6
...
@@ -629,14 +629,18 @@ def main():
...
@@ -629,14 +629,18 @@ def main():
# Potentially load in the weights and states from a previous save
# Potentially load in the weights and states from a previous save
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
accelerator
.
print
(
f
"Resumed from checkpoint:
{
args
.
resume_from_checkpoint
}
"
)
checkpoint_path
=
args
.
resume_from_checkpoint
accelerator
.
load_state
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
else
:
else
:
# Get the most recent checkpoint
# Get the most recent checkpoint
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
checkpoint_path
=
path
path
=
os
.
path
.
basename
(
checkpoint_path
)
accelerator
.
print
(
f
"Resumed from checkpoint:
{
checkpoint_path
}
"
)
accelerator
.
load_state
(
path
)
# Extract `epoch_{i}` or `step_{i}`
# Extract `epoch_{i}` or `step_{i}`
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
...
...
examples/pytorch/text-classification/run_glue_no_trainer.py
View file @
01ab39b6
...
@@ -507,14 +507,18 @@ def main():
...
@@ -507,14 +507,18 @@ def main():
# Potentially load in the weights and states from a previous save
# Potentially load in the weights and states from a previous save
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
accelerator
.
print
(
f
"Resumed from checkpoint:
{
args
.
resume_from_checkpoint
}
"
)
checkpoint_path
=
args
.
resume_from_checkpoint
accelerator
.
load_state
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
else
:
else
:
# Get the most recent checkpoint
# Get the most recent checkpoint
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
checkpoint_path
=
path
path
=
os
.
path
.
basename
(
checkpoint_path
)
accelerator
.
print
(
f
"Resumed from checkpoint:
{
checkpoint_path
}
"
)
accelerator
.
load_state
(
path
)
# Extract `epoch_{i}` or `step_{i}`
# Extract `epoch_{i}` or `step_{i}`
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
...
...
examples/pytorch/token-classification/run_ner_no_trainer.py
View file @
01ab39b6
...
@@ -667,14 +667,18 @@ def main():
...
@@ -667,14 +667,18 @@ def main():
# Potentially load in the weights and states from a previous save
# Potentially load in the weights and states from a previous save
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
accelerator
.
print
(
f
"Resumed from checkpoint:
{
args
.
resume_from_checkpoint
}
"
)
checkpoint_path
=
args
.
resume_from_checkpoint
accelerator
.
load_state
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
else
:
else
:
# Get the most recent checkpoint
# Get the most recent checkpoint
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
checkpoint_path
=
path
path
=
os
.
path
.
basename
(
checkpoint_path
)
accelerator
.
print
(
f
"Resumed from checkpoint:
{
checkpoint_path
}
"
)
accelerator
.
load_state
(
path
)
# Extract `epoch_{i}` or `step_{i}`
# Extract `epoch_{i}` or `step_{i}`
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
...
...
examples/pytorch/translation/run_translation_no_trainer.py
View file @
01ab39b6
...
@@ -610,14 +610,18 @@ def main():
...
@@ -610,14 +610,18 @@ def main():
# Potentially load in the weights and states from a previous save
# Potentially load in the weights and states from a previous save
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
if
args
.
resume_from_checkpoint
is
not
None
or
args
.
resume_from_checkpoint
!=
""
:
accelerator
.
print
(
f
"Resumed from checkpoint:
{
args
.
resume_from_checkpoint
}
"
)
checkpoint_path
=
args
.
resume_from_checkpoint
accelerator
.
load_state
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
path
=
os
.
path
.
basename
(
args
.
resume_from_checkpoint
)
else
:
else
:
# Get the most recent checkpoint
# Get the most recent checkpoint
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
=
[
f
.
name
for
f
in
os
.
scandir
(
os
.
getcwd
())
if
f
.
is_dir
()]
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
dirs
.
sort
(
key
=
os
.
path
.
getctime
)
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
path
=
dirs
[
-
1
]
# Sorts folders by date modified, most recent checkpoint is the last
checkpoint_path
=
path
path
=
os
.
path
.
basename
(
checkpoint_path
)
accelerator
.
print
(
f
"Resumed from checkpoint:
{
checkpoint_path
}
"
)
accelerator
.
load_state
(
path
)
# Extract `epoch_{i}` or `step_{i}`
# Extract `epoch_{i}` or `step_{i}`
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
training_difference
=
os
.
path
.
splitext
(
path
)[
0
]
...
...
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