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
f7d80cb3
Unverified
Commit
f7d80cb3
authored
Jun 12, 2023
by
Ethan
Committed by
GitHub
Jun 12, 2023
Browse files
Fix steps bugs in no trainer examples (#24197)
Fix step bugs in no trainer + load checkpoint + grad acc
parent
08ae37c8
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
34 additions
and
17 deletions
+34
-17
examples/pytorch/image-classification/run_image_classification_no_trainer.py
...age-classification/run_image_classification_no_trainer.py
+3
-2
examples/pytorch/image-pretraining/run_mim_no_trainer.py
examples/pytorch/image-pretraining/run_mim_no_trainer.py
+1
-1
examples/pytorch/language-modeling/run_clm_no_trainer.py
examples/pytorch/language-modeling/run_clm_no_trainer.py
+1
-1
examples/pytorch/language-modeling/run_mlm_no_trainer.py
examples/pytorch/language-modeling/run_mlm_no_trainer.py
+1
-1
examples/pytorch/multiple-choice/run_swag_no_trainer.py
examples/pytorch/multiple-choice/run_swag_no_trainer.py
+3
-2
examples/pytorch/question-answering/run_qa_beam_search_no_trainer.py
...torch/question-answering/run_qa_beam_search_no_trainer.py
+3
-2
examples/pytorch/question-answering/run_qa_no_trainer.py
examples/pytorch/question-answering/run_qa_no_trainer.py
+1
-1
examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py
...ntic-segmentation/run_semantic_segmentation_no_trainer.py
+3
-2
examples/pytorch/summarization/run_summarization_no_trainer.py
...les/pytorch/summarization/run_summarization_no_trainer.py
+3
-2
examples/pytorch/text-classification/run_glue_no_trainer.py
examples/pytorch/text-classification/run_glue_no_trainer.py
+7
-1
examples/pytorch/token-classification/run_ner_no_trainer.py
examples/pytorch/token-classification/run_ner_no_trainer.py
+7
-1
examples/pytorch/translation/run_translation_no_trainer.py
examples/pytorch/translation/run_translation_no_trainer.py
+1
-1
No files found.
examples/pytorch/image-classification/run_image_classification_no_trainer.py
View file @
f7d80cb3
...
...
@@ -453,10 +453,11 @@ def main():
resume_step
=
None
completed_steps
=
starting_epoch
*
num_update_steps_per_epoch
else
:
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
# need to multiply `gradient_accumulation_steps` to reflect real steps
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
*
args
.
gradient_accumulation_steps
starting_epoch
=
resume_step
//
len
(
train_dataloader
)
resume_step
-=
starting_epoch
*
len
(
train_dataloader
)
completed_steps
=
resume_step
completed_steps
=
resume_step
//
args
.
gradient_accumulation_step
# update the progress_bar if load from checkpoint
progress_bar
.
update
(
completed_steps
)
...
...
examples/pytorch/image-pretraining/run_mim_no_trainer.py
View file @
f7d80cb3
...
...
@@ -666,7 +666,7 @@ def main():
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
*
args
.
gradient_accumulation_steps
starting_epoch
=
resume_step
//
len
(
train_dataloader
)
resume_step
-=
starting_epoch
*
len
(
train_dataloader
)
completed_steps
=
resume_step
completed_steps
=
resume_step
//
args
.
gradient_accumulation_steps
# update the progress_bar if load from checkpoint
progress_bar
.
update
(
completed_steps
)
...
...
examples/pytorch/language-modeling/run_clm_no_trainer.py
View file @
f7d80cb3
...
...
@@ -572,7 +572,7 @@ def main():
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
*
args
.
gradient_accumulation_steps
starting_epoch
=
resume_step
//
len
(
train_dataloader
)
resume_step
-=
starting_epoch
*
len
(
train_dataloader
)
completed_steps
=
resume_step
completed_steps
=
resume_step
//
args
.
gradient_accumulation_steps
# update the progress_bar if load from checkpoint
progress_bar
.
update
(
completed_steps
)
...
...
examples/pytorch/language-modeling/run_mlm_no_trainer.py
View file @
f7d80cb3
...
...
@@ -616,7 +616,7 @@ def main():
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
*
args
.
gradient_accumulation_steps
starting_epoch
=
resume_step
//
len
(
train_dataloader
)
resume_step
-=
starting_epoch
*
len
(
train_dataloader
)
completed_steps
=
resume_step
completed_steps
=
resume_step
//
args
.
gradient_accumulation_steps
# update the progress_bar if load from checkpoint
progress_bar
.
update
(
completed_steps
)
...
...
examples/pytorch/multiple-choice/run_swag_no_trainer.py
View file @
f7d80cb3
...
...
@@ -559,10 +559,11 @@ def main():
resume_step
=
None
completed_steps
=
starting_epoch
*
num_update_steps_per_epoch
else
:
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
# need to multiply `gradient_accumulation_steps` to reflect real steps
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
*
args
.
gradient_accumulation_steps
starting_epoch
=
resume_step
//
len
(
train_dataloader
)
resume_step
-=
starting_epoch
*
len
(
train_dataloader
)
completed_steps
=
resume_step
completed_steps
=
resume_step
//
args
.
gradient_accumulation_stepp
# update the progress_bar if load from checkpoint
progress_bar
.
update
(
completed_steps
)
...
...
examples/pytorch/question-answering/run_qa_beam_search_no_trainer.py
View file @
f7d80cb3
...
...
@@ -811,10 +811,11 @@ def main():
resume_step
=
None
completed_steps
=
starting_epoch
*
num_update_steps_per_epoch
else
:
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
# need to multiply `gradient_accumulation_steps` to reflect real steps
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
*
args
.
gradient_accumulation_steps
starting_epoch
=
resume_step
//
len
(
train_dataloader
)
resume_step
-=
starting_epoch
*
len
(
train_dataloader
)
completed_steps
=
resume_step
completed_steps
=
resume_step
//
args
.
gradient_accumulation_stepp
# update the progress_bar if load from checkpoint
progress_bar
.
update
(
completed_steps
)
...
...
examples/pytorch/question-answering/run_qa_no_trainer.py
View file @
f7d80cb3
...
...
@@ -830,7 +830,7 @@ def main():
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
starting_epoch
=
resume_step
//
len
(
train_dataloader
)
resume_step
-=
starting_epoch
*
len
(
train_dataloader
)
completed_steps
=
resume_step
completed_steps
=
resume_step
//
args
.
gradient_accumulation_stepp
# update the progress_bar if load from checkpoint
progress_bar
.
update
(
completed_steps
)
...
...
examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py
View file @
f7d80cb3
...
...
@@ -556,10 +556,11 @@ def main():
resume_step
=
None
completed_steps
=
starting_epoch
*
num_update_steps_per_epoch
else
:
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
# need to multiply `gradient_accumulation_steps` to reflect real steps
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
*
args
.
gradient_accumulation_steps
starting_epoch
=
resume_step
//
len
(
train_dataloader
)
resume_step
-=
starting_epoch
*
len
(
train_dataloader
)
completed_steps
=
resume_step
completed_steps
=
resume_step
//
args
.
gradient_accumulation_stepp
# update the progress_bar if load from checkpoint
progress_bar
.
update
(
completed_steps
)
...
...
examples/pytorch/summarization/run_summarization_no_trainer.py
View file @
f7d80cb3
...
...
@@ -628,10 +628,11 @@ def main():
resume_step
=
None
completed_steps
=
starting_epoch
*
num_update_steps_per_epoch
else
:
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
# need to multiply `gradient_accumulation_steps` to reflect real steps
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
*
args
.
gradient_accumulation_steps
starting_epoch
=
resume_step
//
len
(
train_dataloader
)
resume_step
-=
starting_epoch
*
len
(
train_dataloader
)
completed_steps
=
resume_step
completed_steps
=
resume_step
//
args
.
gradient_accumulation_stepp
# update the progress_bar if load from checkpoint
progress_bar
.
update
(
completed_steps
)
...
...
examples/pytorch/text-classification/run_glue_no_trainer.py
View file @
f7d80cb3
...
...
@@ -501,10 +501,16 @@ def main():
if
"epoch"
in
training_difference
:
starting_epoch
=
int
(
training_difference
.
replace
(
"epoch_"
,
""
))
+
1
resume_step
=
None
completed_steps
=
starting_epoch
*
num_update_steps_per_epoch
else
:
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
# need to multiply `gradient_accumulation_steps` to reflect real steps
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
*
args
.
gradient_accumulation_steps
starting_epoch
=
resume_step
//
len
(
train_dataloader
)
resume_step
-=
starting_epoch
*
len
(
train_dataloader
)
completed_steps
=
resume_step
//
args
.
gradient_accumulation_step
# update the progress_bar if load from checkpoint
progress_bar
.
update
(
completed_steps
)
for
epoch
in
range
(
starting_epoch
,
args
.
num_train_epochs
):
model
.
train
()
...
...
examples/pytorch/token-classification/run_ner_no_trainer.py
View file @
f7d80cb3
...
...
@@ -659,10 +659,16 @@ def main():
if
"epoch"
in
training_difference
:
starting_epoch
=
int
(
training_difference
.
replace
(
"epoch_"
,
""
))
+
1
resume_step
=
None
completed_steps
=
starting_epoch
*
num_update_steps_per_epoch
else
:
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
# need to multiply `gradient_accumulation_steps` to reflect real steps
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
*
args
.
gradient_accumulation_steps
starting_epoch
=
resume_step
//
len
(
train_dataloader
)
resume_step
-=
starting_epoch
*
len
(
train_dataloader
)
completed_steps
=
resume_step
//
args
.
gradient_accumulation_stepp
# update the progress_bar if load from checkpoint
progress_bar
.
update
(
completed_steps
)
for
epoch
in
range
(
starting_epoch
,
args
.
num_train_epochs
):
model
.
train
()
...
...
examples/pytorch/translation/run_translation_no_trainer.py
View file @
f7d80cb3
...
...
@@ -613,7 +613,7 @@ def main():
resume_step
=
int
(
training_difference
.
replace
(
"step_"
,
""
))
*
args
.
gradient_accumulation_steps
starting_epoch
=
resume_step
//
len
(
train_dataloader
)
resume_step
-=
starting_epoch
*
len
(
train_dataloader
)
completed_steps
=
resume_step
completed_steps
=
resume_step
//
args
.
gradient_accumulation_stepp
# update the progress_bar if load from checkpoint
progress_bar
.
update
(
completed_steps
)
...
...
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