Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
e9c23fa0
Unverified
Commit
e9c23fa0
authored
Apr 09, 2024
by
NielsRogge
Committed by
GitHub
Apr 09, 2024
Browse files
[Trainer] Undo #29896 (#30129)
* Undo * Use tokenizer * Undo data collator
parent
ba1b24e0
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
24 additions
and
41 deletions
+24
-41
docs/source/en/tasks/image_classification.md
docs/source/en/tasks/image_classification.md
+2
-2
docs/source/en/tasks/object_detection.md
docs/source/en/tasks/object_detection.md
+1
-1
docs/source/en/tasks/semantic_segmentation.md
docs/source/en/tasks/semantic_segmentation.md
+1
-1
docs/source/en/tasks/video_classification.md
docs/source/en/tasks/video_classification.md
+1
-1
docs/source/es/tasks/image_classification.md
docs/source/es/tasks/image_classification.md
+1
-1
docs/source/ja/tasks/image_classification.md
docs/source/ja/tasks/image_classification.md
+2
-2
docs/source/ja/tasks/object_detection.md
docs/source/ja/tasks/object_detection.md
+1
-1
docs/source/ja/tasks/semantic_segmentation.md
docs/source/ja/tasks/semantic_segmentation.md
+1
-1
docs/source/ja/tasks/video_classification.md
docs/source/ja/tasks/video_classification.md
+1
-1
docs/source/ko/tasks/image_classification.md
docs/source/ko/tasks/image_classification.md
+2
-2
docs/source/ko/tasks/object_detection.md
docs/source/ko/tasks/object_detection.md
+1
-1
docs/source/ko/tasks/semantic_segmentation.md
docs/source/ko/tasks/semantic_segmentation.md
+1
-1
docs/source/ko/tasks/video_classification.md
docs/source/ko/tasks/video_classification.md
+1
-1
examples/pytorch/image-classification/run_image_classification.py
.../pytorch/image-classification/run_image_classification.py
+1
-1
examples/pytorch/image-pretraining/run_mae.py
examples/pytorch/image-pretraining/run_mae.py
+1
-1
examples/pytorch/image-pretraining/run_mim.py
examples/pytorch/image-pretraining/run_mim.py
+1
-1
examples/pytorch/semantic-segmentation/run_semantic_segmentation.py
...ytorch/semantic-segmentation/run_semantic_segmentation.py
+1
-1
examples/tensorflow/image-classification/run_image_classification.py
...nsorflow/image-classification/run_image_classification.py
+1
-1
src/transformers/trainer.py
src/transformers/trainer.py
+2
-15
src/transformers/trainer_callback.py
src/transformers/trainer_callback.py
+1
-5
No files found.
docs/source/en/tasks/image_classification.md
View file @
e9c23fa0
...
@@ -322,7 +322,7 @@ At this point, only three steps remain:
...
@@ -322,7 +322,7 @@ At this point, only three steps remain:
...
data_collator
=
data_collator
,
...
data_collator
=
data_collator
,
...
train_dataset
=
food
[
"train"
],
...
train_dataset
=
food
[
"train"
],
...
eval_dataset
=
food
[
"test"
],
...
eval_dataset
=
food
[
"test"
],
...
image_processo
r
=
image_processor
,
...
tokenize
r
=
image_processor
,
...
compute_metrics
=
compute_metrics
,
...
compute_metrics
=
compute_metrics
,
...
)
...
)
...
@@ -418,7 +418,7 @@ and use the [PushToHubCallback](../main_classes/keras_callbacks#transformers.Pus
...
@@ -418,7 +418,7 @@ and use the [PushToHubCallback](../main_classes/keras_callbacks#transformers.Pus
>>>
metric_callback
=
KerasMetricCallback
(
metric_fn
=
compute_metrics
,
eval_dataset
=
tf_eval_dataset
)
>>>
metric_callback
=
KerasMetricCallback
(
metric_fn
=
compute_metrics
,
eval_dataset
=
tf_eval_dataset
)
>>>
push_to_hub_callback
=
PushToHubCallback
(
>>>
push_to_hub_callback
=
PushToHubCallback
(
...
output_dir
=
"food_classifier"
,
...
output_dir
=
"food_classifier"
,
...
image_processo
r
=
image_processor
,
...
tokenize
r
=
image_processor
,
...
save_strategy
=
"no"
,
...
save_strategy
=
"no"
,
...
)
...
)
>>>
callbacks
=
[
metric_callback
,
push_to_hub_callback
]
>>>
callbacks
=
[
metric_callback
,
push_to_hub_callback
]
...
...
docs/source/en/tasks/object_detection.md
View file @
e9c23fa0
...
@@ -384,7 +384,7 @@ Finally, bring everything together, and call [`~transformers.Trainer.train`]:
...
@@ -384,7 +384,7 @@ Finally, bring everything together, and call [`~transformers.Trainer.train`]:
...
args
=
training_args
,
...
args
=
training_args
,
...
data_collator
=
collate_fn
,
...
data_collator
=
collate_fn
,
...
train_dataset
=
cppe5
[
"train"
],
...
train_dataset
=
cppe5
[
"train"
],
...
image_processo
r
=
image_processor
,
...
tokenize
r
=
image_processor
,
...
)
...
)
>>>
trainer
.
train
()
>>>
trainer
.
train
()
...
...
docs/source/en/tasks/semantic_segmentation.md
View file @
e9c23fa0
...
@@ -642,7 +642,7 @@ and use the [`PushToHubCallback`] to upload the model:
...
@@ -642,7 +642,7 @@ and use the [`PushToHubCallback`] to upload the model:
...
metric_fn
=
compute_metrics
,
eval_dataset
=
tf_eval_dataset
,
batch_size
=
batch_size
,
label_cols
=
[
"labels"
]
...
metric_fn
=
compute_metrics
,
eval_dataset
=
tf_eval_dataset
,
batch_size
=
batch_size
,
label_cols
=
[
"labels"
]
...
)
...
)
>>>
push_to_hub_callback
=
PushToHubCallback
(
output_dir
=
"scene_segmentation"
,
image_processo
r
=
image_processor
)
>>>
push_to_hub_callback
=
PushToHubCallback
(
output_dir
=
"scene_segmentation"
,
tokenize
r
=
image_processor
)
>>>
callbacks
=
[
metric_callback
,
push_to_hub_callback
]
>>>
callbacks
=
[
metric_callback
,
push_to_hub_callback
]
```
```
...
...
docs/source/en/tasks/video_classification.md
View file @
e9c23fa0
...
@@ -407,7 +407,7 @@ Then you just pass all of this along with the datasets to `Trainer`:
...
@@ -407,7 +407,7 @@ Then you just pass all of this along with the datasets to `Trainer`:
...
args
,
...
args
,
...
train_dataset
=
train_dataset
,
...
train_dataset
=
train_dataset
,
...
eval_dataset
=
val_dataset
,
...
eval_dataset
=
val_dataset
,
...
image_processo
r
=
image_processor
,
...
tokenize
r
=
image_processor
,
...
compute_metrics
=
compute_metrics
,
...
compute_metrics
=
compute_metrics
,
...
data_collator
=
collate_fn
,
...
data_collator
=
collate_fn
,
...
)
...
)
...
...
docs/source/es/tasks/image_classification.md
View file @
e9c23fa0
...
@@ -160,7 +160,7 @@ Al llegar a este punto, solo quedan tres pasos:
...
@@ -160,7 +160,7 @@ Al llegar a este punto, solo quedan tres pasos:
...
data_collator
=
data_collator
,
...
data_collator
=
data_collator
,
...
train_dataset
=
food
[
"train"
],
...
train_dataset
=
food
[
"train"
],
...
eval_dataset
=
food
[
"test"
],
...
eval_dataset
=
food
[
"test"
],
...
image_processo
r
=
image_processor
,
...
tokenize
r
=
image_processor
,
...
)
...
)
>>>
trainer
.
train
()
>>>
trainer
.
train
()
...
...
docs/source/ja/tasks/image_classification.md
View file @
e9c23fa0
...
@@ -328,7 +328,7 @@ food["test"].set_transform(preprocess_val)
...
@@ -328,7 +328,7 @@ food["test"].set_transform(preprocess_val)
...
data_collator
=
data_collator
,
...
data_collator
=
data_collator
,
...
train_dataset
=
food
[
"train"
],
...
train_dataset
=
food
[
"train"
],
...
eval_dataset
=
food
[
"test"
],
...
eval_dataset
=
food
[
"test"
],
...
image_processo
r
=
image_processor
,
...
tokenize
r
=
image_processor
,
...
compute_metrics
=
compute_metrics
,
...
compute_metrics
=
compute_metrics
,
...
)
...
)
...
@@ -426,7 +426,7 @@ Convert your datasets to the `tf.data.Dataset` format using the [`~datasets.Data
...
@@ -426,7 +426,7 @@ Convert your datasets to the `tf.data.Dataset` format using the [`~datasets.Data
>>>
metric_callback
=
KerasMetricCallback
(
metric_fn
=
compute_metrics
,
eval_dataset
=
tf_eval_dataset
)
>>>
metric_callback
=
KerasMetricCallback
(
metric_fn
=
compute_metrics
,
eval_dataset
=
tf_eval_dataset
)
>>>
push_to_hub_callback
=
PushToHubCallback
(
>>>
push_to_hub_callback
=
PushToHubCallback
(
...
output_dir
=
"food_classifier"
,
...
output_dir
=
"food_classifier"
,
...
image_processo
r
=
image_processor
,
...
tokenize
r
=
image_processor
,
...
save_strategy
=
"no"
,
...
save_strategy
=
"no"
,
...
)
...
)
>>>
callbacks
=
[
metric_callback
,
push_to_hub_callback
]
>>>
callbacks
=
[
metric_callback
,
push_to_hub_callback
]
...
...
docs/source/ja/tasks/object_detection.md
View file @
e9c23fa0
...
@@ -376,7 +376,7 @@ DETR モデルをトレーニングできる「ラベル」。画像プロセッ
...
@@ -376,7 +376,7 @@ DETR モデルをトレーニングできる「ラベル」。画像プロセッ
...
args
=
training_args
,
...
args
=
training_args
,
...
data_collator
=
collate_fn
,
...
data_collator
=
collate_fn
,
...
train_dataset
=
cppe5
[
"train"
],
...
train_dataset
=
cppe5
[
"train"
],
...
image_processo
r
=
image_processor
,
...
tokenize
r
=
image_processor
,
...
)
...
)
>>>
trainer
.
train
()
>>>
trainer
.
train
()
...
...
docs/source/ja/tasks/semantic_segmentation.md
View file @
e9c23fa0
...
@@ -434,7 +434,7 @@ TensorFlow でモデルを微調整するには、次の手順に従います。
...
@@ -434,7 +434,7 @@ TensorFlow でモデルを微調整するには、次の手順に従います。
...
metric_fn
=
compute_metrics
,
eval_dataset
=
tf_eval_dataset
,
batch_size
=
batch_size
,
label_cols
=
[
"labels"
]
...
metric_fn
=
compute_metrics
,
eval_dataset
=
tf_eval_dataset
,
batch_size
=
batch_size
,
label_cols
=
[
"labels"
]
...
)
...
)
>>>
push_to_hub_callback
=
PushToHubCallback
(
output_dir
=
"scene_segmentation"
,
image_processo
r
=
image_processor
)
>>>
push_to_hub_callback
=
PushToHubCallback
(
output_dir
=
"scene_segmentation"
,
tokenize
r
=
image_processor
)
>>>
callbacks
=
[
metric_callback
,
push_to_hub_callback
]
>>>
callbacks
=
[
metric_callback
,
push_to_hub_callback
]
```
```
...
...
docs/source/ja/tasks/video_classification.md
View file @
e9c23fa0
...
@@ -414,7 +414,7 @@ def compute_metrics(eval_pred):
...
@@ -414,7 +414,7 @@ def compute_metrics(eval_pred):
... args,
... args,
... train_dataset=train_dataset,
... train_dataset=train_dataset,
... eval_dataset=val_dataset,
... eval_dataset=val_dataset,
...
image_processo
r=image_processor,
...
tokenize
r=image_processor,
... compute_metrics=compute_metrics,
... compute_metrics=compute_metrics,
... data_collator=collate_fn,
... data_collator=collate_fn,
... )
... )
...
...
docs/source/ko/tasks/image_classification.md
View file @
e9c23fa0
...
@@ -321,7 +321,7 @@ food["test"].set_transform(preprocess_val)
...
@@ -321,7 +321,7 @@ food["test"].set_transform(preprocess_val)
...
data_collator
=
data_collator
,
...
data_collator
=
data_collator
,
...
train_dataset
=
food
[
"train"
],
...
train_dataset
=
food
[
"train"
],
...
eval_dataset
=
food
[
"test"
],
...
eval_dataset
=
food
[
"test"
],
...
image_processo
r
=
image_processor
,
...
tokenize
r
=
image_processor
,
...
compute_metrics
=
compute_metrics
,
...
compute_metrics
=
compute_metrics
,
...
)
...
)
...
@@ -417,7 +417,7 @@ TensorFlow에서 모델을 미세 조정하려면 다음 단계를 따르세요:
...
@@ -417,7 +417,7 @@ TensorFlow에서 모델을 미세 조정하려면 다음 단계를 따르세요:
>>>
metric_callback
=
KerasMetricCallback
(
metric_fn
=
compute_metrics
,
eval_dataset
=
tf_eval_dataset
)
>>>
metric_callback
=
KerasMetricCallback
(
metric_fn
=
compute_metrics
,
eval_dataset
=
tf_eval_dataset
)
>>>
push_to_hub_callback
=
PushToHubCallback
(
>>>
push_to_hub_callback
=
PushToHubCallback
(
...
output_dir
=
"food_classifier"
,
...
output_dir
=
"food_classifier"
,
...
image_processo
r
=
image_processor
,
...
tokenize
r
=
image_processor
,
...
save_strategy
=
"no"
,
...
save_strategy
=
"no"
,
...
)
...
)
>>>
callbacks
=
[
metric_callback
,
push_to_hub_callback
]
>>>
callbacks
=
[
metric_callback
,
push_to_hub_callback
]
...
...
docs/source/ko/tasks/object_detection.md
View file @
e9c23fa0
...
@@ -366,7 +366,7 @@ DatasetDict({
...
@@ -366,7 +366,7 @@ DatasetDict({
...
args
=
training_args
,
...
args
=
training_args
,
...
data_collator
=
collate_fn
,
...
data_collator
=
collate_fn
,
...
train_dataset
=
cppe5
[
"train"
],
...
train_dataset
=
cppe5
[
"train"
],
...
image_processo
r
=
image_processor
,
...
tokenize
r
=
image_processor
,
...
)
...
)
>>>
trainer
.
train
()
>>>
trainer
.
train
()
...
...
docs/source/ko/tasks/semantic_segmentation.md
View file @
e9c23fa0
...
@@ -424,7 +424,7 @@ TensorFlow에서 모델을 미세 조정하려면 다음 단계를 따르세요:
...
@@ -424,7 +424,7 @@ TensorFlow에서 모델을 미세 조정하려면 다음 단계를 따르세요:
...
metric_fn
=
compute_metrics
,
eval_dataset
=
tf_eval_dataset
,
batch_size
=
batch_size
,
label_cols
=
[
"labels"
]
...
metric_fn
=
compute_metrics
,
eval_dataset
=
tf_eval_dataset
,
batch_size
=
batch_size
,
label_cols
=
[
"labels"
]
...
)
...
)
>>>
push_to_hub_callback
=
PushToHubCallback
(
output_dir
=
"scene_segmentation"
,
image_processo
r
=
image_processor
)
>>>
push_to_hub_callback
=
PushToHubCallback
(
output_dir
=
"scene_segmentation"
,
tokenize
r
=
image_processor
)
>>>
callbacks
=
[
metric_callback
,
push_to_hub_callback
]
>>>
callbacks
=
[
metric_callback
,
push_to_hub_callback
]
```
```
...
...
docs/source/ko/tasks/video_classification.md
View file @
e9c23fa0
...
@@ -411,7 +411,7 @@ def compute_metrics(eval_pred):
...
@@ -411,7 +411,7 @@ def compute_metrics(eval_pred):
...
args
,
...
args
,
...
train_dataset
=
train_dataset
,
...
train_dataset
=
train_dataset
,
...
eval_dataset
=
val_dataset
,
...
eval_dataset
=
val_dataset
,
...
image_processo
r
=
image_processor
,
...
tokenize
r
=
image_processor
,
...
compute_metrics
=
compute_metrics
,
...
compute_metrics
=
compute_metrics
,
...
data_collator
=
collate_fn
,
...
data_collator
=
collate_fn
,
...
)
...
)
...
...
examples/pytorch/image-classification/run_image_classification.py
View file @
e9c23fa0
...
@@ -411,7 +411,7 @@ def main():
...
@@ -411,7 +411,7 @@ def main():
train_dataset
=
dataset
[
"train"
]
if
training_args
.
do_train
else
None
,
train_dataset
=
dataset
[
"train"
]
if
training_args
.
do_train
else
None
,
eval_dataset
=
dataset
[
"validation"
]
if
training_args
.
do_eval
else
None
,
eval_dataset
=
dataset
[
"validation"
]
if
training_args
.
do_eval
else
None
,
compute_metrics
=
compute_metrics
,
compute_metrics
=
compute_metrics
,
image_processo
r
=
image_processor
,
tokenize
r
=
image_processor
,
data_collator
=
collate_fn
,
data_collator
=
collate_fn
,
)
)
...
...
examples/pytorch/image-pretraining/run_mae.py
View file @
e9c23fa0
...
@@ -369,7 +369,7 @@ def main():
...
@@ -369,7 +369,7 @@ def main():
args
=
training_args
,
args
=
training_args
,
train_dataset
=
ds
[
"train"
]
if
training_args
.
do_train
else
None
,
train_dataset
=
ds
[
"train"
]
if
training_args
.
do_train
else
None
,
eval_dataset
=
ds
[
"validation"
]
if
training_args
.
do_eval
else
None
,
eval_dataset
=
ds
[
"validation"
]
if
training_args
.
do_eval
else
None
,
image_processo
r
=
image_processor
,
tokenize
r
=
image_processor
,
data_collator
=
collate_fn
,
data_collator
=
collate_fn
,
)
)
...
...
examples/pytorch/image-pretraining/run_mim.py
View file @
e9c23fa0
...
@@ -458,7 +458,7 @@ def main():
...
@@ -458,7 +458,7 @@ def main():
args
=
training_args
,
args
=
training_args
,
train_dataset
=
ds
[
"train"
]
if
training_args
.
do_train
else
None
,
train_dataset
=
ds
[
"train"
]
if
training_args
.
do_train
else
None
,
eval_dataset
=
ds
[
"validation"
]
if
training_args
.
do_eval
else
None
,
eval_dataset
=
ds
[
"validation"
]
if
training_args
.
do_eval
else
None
,
image_processo
r
=
image_processor
,
tokenize
r
=
image_processor
,
data_collator
=
collate_fn
,
data_collator
=
collate_fn
,
)
)
...
...
examples/pytorch/semantic-segmentation/run_semantic_segmentation.py
View file @
e9c23fa0
...
@@ -510,7 +510,7 @@ def main():
...
@@ -510,7 +510,7 @@ def main():
train_dataset
=
dataset
[
"train"
]
if
training_args
.
do_train
else
None
,
train_dataset
=
dataset
[
"train"
]
if
training_args
.
do_train
else
None
,
eval_dataset
=
dataset
[
"validation"
]
if
training_args
.
do_eval
else
None
,
eval_dataset
=
dataset
[
"validation"
]
if
training_args
.
do_eval
else
None
,
compute_metrics
=
compute_metrics
,
compute_metrics
=
compute_metrics
,
image_processo
r
=
image_processor
,
tokenize
r
=
image_processor
,
data_collator
=
default_data_collator
,
data_collator
=
default_data_collator
,
)
)
...
...
examples/tensorflow/image-classification/run_image_classification.py
View file @
e9c23fa0
...
@@ -552,7 +552,7 @@ def main():
...
@@ -552,7 +552,7 @@ def main():
output_dir
=
training_args
.
output_dir
,
output_dir
=
training_args
.
output_dir
,
hub_model_id
=
push_to_hub_model_id
,
hub_model_id
=
push_to_hub_model_id
,
hub_token
=
training_args
.
push_to_hub_token
,
hub_token
=
training_args
.
push_to_hub_token
,
image_processo
r
=
image_processor
,
tokenize
r
=
image_processor
,
**
model_card_kwargs
,
**
model_card_kwargs
,
)
)
)
)
...
...
src/transformers/trainer.py
View file @
e9c23fa0
...
@@ -60,7 +60,6 @@ from .data.data_collator import DataCollator, DataCollatorWithPadding, default_d
...
@@ -60,7 +60,6 @@ from .data.data_collator import DataCollator, DataCollatorWithPadding, default_d
from
.debug_utils
import
DebugOption
,
DebugUnderflowOverflow
from
.debug_utils
import
DebugOption
,
DebugUnderflowOverflow
from
.feature_extraction_sequence_utils
import
SequenceFeatureExtractor
from
.feature_extraction_sequence_utils
import
SequenceFeatureExtractor
from
.hyperparameter_search
import
ALL_HYPERPARAMETER_SEARCH_BACKENDS
,
default_hp_search_backend
from
.hyperparameter_search
import
ALL_HYPERPARAMETER_SEARCH_BACKENDS
,
default_hp_search_backend
from
.image_processing_utils
import
BaseImageProcessor
from
.integrations.deepspeed
import
deepspeed_init
,
deepspeed_load_checkpoint
,
is_deepspeed_available
from
.integrations.deepspeed
import
deepspeed_init
,
deepspeed_load_checkpoint
,
is_deepspeed_available
from
.integrations.tpu
import
tpu_spmd_dataloader
from
.integrations.tpu
import
tpu_spmd_dataloader
from
.modelcard
import
TrainingSummary
from
.modelcard
import
TrainingSummary
...
@@ -331,9 +330,6 @@ class Trainer:
...
@@ -331,9 +330,6 @@ class Trainer:
by this function will be reflected in the predictions received by `compute_metrics`.
by this function will be reflected in the predictions received by `compute_metrics`.
Note that the labels (second parameter) will be `None` if the dataset does not have them.
Note that the labels (second parameter) will be `None` if the dataset does not have them.
image_processor ([`BaseImageProcessor`], *optional*):
The image processor used to preprocess the data. If provided, it will be saved along the model to make it easier
to rerun an interrupted training or reuse the fine-tuned model.
Important attributes:
Important attributes:
...
@@ -369,7 +365,6 @@ class Trainer:
...
@@ -369,7 +365,6 @@ class Trainer:
callbacks
:
Optional
[
List
[
TrainerCallback
]]
=
None
,
callbacks
:
Optional
[
List
[
TrainerCallback
]]
=
None
,
optimizers
:
Tuple
[
torch
.
optim
.
Optimizer
,
torch
.
optim
.
lr_scheduler
.
LambdaLR
]
=
(
None
,
None
),
optimizers
:
Tuple
[
torch
.
optim
.
Optimizer
,
torch
.
optim
.
lr_scheduler
.
LambdaLR
]
=
(
None
,
None
),
preprocess_logits_for_metrics
:
Optional
[
Callable
[[
torch
.
Tensor
,
torch
.
Tensor
],
torch
.
Tensor
]]
=
None
,
preprocess_logits_for_metrics
:
Optional
[
Callable
[[
torch
.
Tensor
,
torch
.
Tensor
],
torch
.
Tensor
]]
=
None
,
image_processor
:
Optional
[
"BaseImageProcessor"
]
=
None
,
):
):
if
args
is
None
:
if
args
is
None
:
output_dir
=
"tmp_trainer"
output_dir
=
"tmp_trainer"
...
@@ -502,7 +497,6 @@ class Trainer:
...
@@ -502,7 +497,6 @@ class Trainer:
self
.
train_dataset
=
train_dataset
self
.
train_dataset
=
train_dataset
self
.
eval_dataset
=
eval_dataset
self
.
eval_dataset
=
eval_dataset
self
.
tokenizer
=
tokenizer
self
.
tokenizer
=
tokenizer
self
.
image_processor
=
image_processor
# Bnb Quantized models doesn't support `.to` operation.
# Bnb Quantized models doesn't support `.to` operation.
if
(
if
(
...
@@ -554,7 +548,7 @@ class Trainer:
...
@@ -554,7 +548,7 @@ class Trainer:
default_callbacks
=
DEFAULT_CALLBACKS
+
get_reporting_integration_callbacks
(
self
.
args
.
report_to
)
default_callbacks
=
DEFAULT_CALLBACKS
+
get_reporting_integration_callbacks
(
self
.
args
.
report_to
)
callbacks
=
default_callbacks
if
callbacks
is
None
else
default_callbacks
+
callbacks
callbacks
=
default_callbacks
if
callbacks
is
None
else
default_callbacks
+
callbacks
self
.
callback_handler
=
CallbackHandler
(
self
.
callback_handler
=
CallbackHandler
(
callbacks
,
self
.
model
,
self
.
tokenizer
,
self
.
image_processor
,
self
.
optimizer
,
self
.
lr_scheduler
callbacks
,
self
.
model
,
self
.
tokenizer
,
self
.
optimizer
,
self
.
lr_scheduler
)
)
self
.
add_callback
(
PrinterCallback
if
self
.
args
.
disable_tqdm
else
DEFAULT_PROGRESS_CALLBACK
)
self
.
add_callback
(
PrinterCallback
if
self
.
args
.
disable_tqdm
else
DEFAULT_PROGRESS_CALLBACK
)
...
@@ -3289,8 +3283,6 @@ class Trainer:
...
@@ -3289,8 +3283,6 @@ class Trainer:
)
)
if
self
.
tokenizer
is
not
None
and
self
.
args
.
should_save
:
if
self
.
tokenizer
is
not
None
and
self
.
args
.
should_save
:
self
.
tokenizer
.
save_pretrained
(
output_dir
)
self
.
tokenizer
.
save_pretrained
(
output_dir
)
if
self
.
image_processor
is
not
None
and
self
.
args
.
should_save
:
self
.
image_processor
.
save_pretrained
(
output_dir
)
# We moved the model from TPU -> CPU for saving the weights.
# We moved the model from TPU -> CPU for saving the weights.
# Now we should move it back to subsequent compute still works.
# Now we should move it back to subsequent compute still works.
...
@@ -3328,8 +3320,6 @@ class Trainer:
...
@@ -3328,8 +3320,6 @@ class Trainer:
if
self
.
tokenizer
is
not
None
:
if
self
.
tokenizer
is
not
None
:
self
.
tokenizer
.
save_pretrained
(
output_dir
)
self
.
tokenizer
.
save_pretrained
(
output_dir
)
if
self
.
image_processor
is
not
None
:
self
.
image_processor
.
save_pretrained
(
output_dir
)
# Good practice: save your training arguments together with the trained model
# Good practice: save your training arguments together with the trained model
torch
.
save
(
self
.
args
,
os
.
path
.
join
(
output_dir
,
TRAINING_ARGS_NAME
))
torch
.
save
(
self
.
args
,
os
.
path
.
join
(
output_dir
,
TRAINING_ARGS_NAME
))
...
@@ -4027,9 +4017,6 @@ class Trainer:
...
@@ -4027,9 +4017,6 @@ class Trainer:
# Saving the tokenizer is fast and we don't know how many files it may have spawned, so we resave it to be sure.
# Saving the tokenizer is fast and we don't know how many files it may have spawned, so we resave it to be sure.
if
self
.
tokenizer
is
not
None
:
if
self
.
tokenizer
is
not
None
:
self
.
tokenizer
.
save_pretrained
(
output_dir
)
self
.
tokenizer
.
save_pretrained
(
output_dir
)
# Same for the image processor
if
self
.
image_processor
is
not
None
:
self
.
image_processor
.
save_pretrained
(
output_dir
)
# Same for the training arguments
# Same for the training arguments
torch
.
save
(
self
.
args
,
os
.
path
.
join
(
output_dir
,
TRAINING_ARGS_NAME
))
torch
.
save
(
self
.
args
,
os
.
path
.
join
(
output_dir
,
TRAINING_ARGS_NAME
))
...
@@ -4083,7 +4070,7 @@ class Trainer:
...
@@ -4083,7 +4070,7 @@ class Trainer:
**
kwargs
,
**
kwargs
,
)
->
str
:
)
->
str
:
"""
"""
Upload `self.model` and `self.tokenizer`
or `self.image_processor`
to the 🤗 model hub on the repo `self.args.hub_model_id`.
Upload `self.model` and `self.tokenizer` to the 🤗 model hub on the repo `self.args.hub_model_id`.
Parameters:
Parameters:
commit_message (`str`, *optional*, defaults to `"End of training"`):
commit_message (`str`, *optional*, defaults to `"End of training"`):
...
...
src/transformers/trainer_callback.py
View file @
e9c23fa0
...
@@ -189,8 +189,6 @@ class TrainerCallback:
...
@@ -189,8 +189,6 @@ class TrainerCallback:
The model being trained.
The model being trained.
tokenizer ([`PreTrainedTokenizer`]):
tokenizer ([`PreTrainedTokenizer`]):
The tokenizer used for encoding the data.
The tokenizer used for encoding the data.
image_processor ([`BaseImageProcessor`]):
The image processor used for encoding the images.
optimizer (`torch.optim.Optimizer`):
optimizer (`torch.optim.Optimizer`):
The optimizer used for the training steps.
The optimizer used for the training steps.
lr_scheduler (`torch.optim.lr_scheduler.LambdaLR`):
lr_scheduler (`torch.optim.lr_scheduler.LambdaLR`):
...
@@ -309,13 +307,12 @@ class TrainerCallback:
...
@@ -309,13 +307,12 @@ class TrainerCallback:
class
CallbackHandler
(
TrainerCallback
):
class
CallbackHandler
(
TrainerCallback
):
"""Internal class that just calls the list of callbacks in order."""
"""Internal class that just calls the list of callbacks in order."""
def
__init__
(
self
,
callbacks
,
model
,
tokenizer
,
image_processor
,
optimizer
,
lr_scheduler
):
def
__init__
(
self
,
callbacks
,
model
,
tokenizer
,
optimizer
,
lr_scheduler
):
self
.
callbacks
=
[]
self
.
callbacks
=
[]
for
cb
in
callbacks
:
for
cb
in
callbacks
:
self
.
add_callback
(
cb
)
self
.
add_callback
(
cb
)
self
.
model
=
model
self
.
model
=
model
self
.
tokenizer
=
tokenizer
self
.
tokenizer
=
tokenizer
self
.
image_processor
=
image_processor
self
.
optimizer
=
optimizer
self
.
optimizer
=
optimizer
self
.
lr_scheduler
=
lr_scheduler
self
.
lr_scheduler
=
lr_scheduler
self
.
train_dataloader
=
None
self
.
train_dataloader
=
None
...
@@ -420,7 +417,6 @@ class CallbackHandler(TrainerCallback):
...
@@ -420,7 +417,6 @@ class CallbackHandler(TrainerCallback):
control
,
control
,
model
=
self
.
model
,
model
=
self
.
model
,
tokenizer
=
self
.
tokenizer
,
tokenizer
=
self
.
tokenizer
,
image_processor
=
self
.
image_processor
,
optimizer
=
self
.
optimizer
,
optimizer
=
self
.
optimizer
,
lr_scheduler
=
self
.
lr_scheduler
,
lr_scheduler
=
self
.
lr_scheduler
,
train_dataloader
=
self
.
train_dataloader
,
train_dataloader
=
self
.
train_dataloader
,
...
...
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