Skip to content

Commit 2b550c4

Browse files
authored
Remove deprecated training arguments (#36946)
* Remove deprecated training arguments * More fixes * More fixes * More fixes
1 parent 4471522 commit 2b550c4

File tree

8 files changed

+15
-108
lines changed

8 files changed

+15
-108
lines changed

examples/pytorch/instance-segmentation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ python run_instance_segmentation.py \
6666
--dataloader_persistent_workers \
6767
--dataloader_prefetch_factor 4 \
6868
--do_eval \
69-
--evaluation_strategy epoch \
69+
--eval_strategy epoch \
7070
--logging_strategy epoch \
7171
--save_strategy epoch \
7272
--save_total_limit 2 \

examples/pytorch/object-detection/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ python run_object_detection.py \
5656
--greater_is_better true \
5757
--load_best_model_at_end true \
5858
--logging_strategy epoch \
59-
--evaluation_strategy epoch \
59+
--eval_strategy epoch \
6060
--save_strategy epoch \
6161
--save_total_limit 2 \
6262
--push_to_hub true \

examples/pytorch/test_pytorch_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ def test_run_instance_segmentation(self):
667667
--per_device_train_batch_size 2
668668
--per_device_eval_batch_size 1
669669
--do_eval
670-
--evaluation_strategy epoch
670+
--eval_strategy epoch
671671
--seed 32
672672
""".split()
673673

src/transformers/trainer_pt_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ class AcceleratorConfig:
12631263
" in your script multiplied by the number of processes."
12641264
},
12651265
)
1266-
dispatch_batches: bool = field(
1266+
dispatch_batches: Optional[bool] = field(
12671267
default=None,
12681268
metadata={
12691269
"help": "If set to `True`, the dataloader prepared by the Accelerator is only iterated through on the main process"

src/transformers/training_args.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -768,14 +768,6 @@ class TrainingArguments:
768768
Refer to the PyTorch doc for possible values and note that they may change across PyTorch versions.
769769
770770
This flag is experimental and subject to change in future releases.
771-
split_batches (`bool`, *optional*):
772-
Whether or not the accelerator should split the batches yielded by the dataloaders across the devices
773-
during distributed training. If
774-
775-
set to `True`, the actual batch size used will be the same on any kind of distributed processes, but it
776-
must be a
777-
778-
round multiple of the number of processes you are using (such as GPUs).
779771
include_tokens_per_second (`bool`, *optional*):
780772
Whether or not to compute the number of tokens per second per device for training speed metrics.
781773
@@ -1426,10 +1418,6 @@ class TrainingArguments:
14261418
"choices": ["auto", "apex", "cpu_amp"],
14271419
},
14281420
)
1429-
evaluation_strategy: Union[IntervalStrategy, str] = field(
1430-
default=None,
1431-
metadata={"help": "Deprecated. Use `eval_strategy` instead"},
1432-
)
14331421
push_to_hub_model_id: Optional[str] = field(
14341422
default=None, metadata={"help": "The name of the repository to which push the `Trainer`."}
14351423
)
@@ -1504,16 +1492,6 @@ class TrainingArguments:
15041492
},
15051493
)
15061494

1507-
dispatch_batches: Optional[bool] = field(
1508-
default=None,
1509-
metadata={"help": "Deprecated. Pass {'dispatch_batches':VALUE} to `accelerator_config`."},
1510-
)
1511-
1512-
split_batches: Optional[bool] = field(
1513-
default=None,
1514-
metadata={"help": "Deprecated. Pass {'split_batches':True} to `accelerator_config`."},
1515-
)
1516-
15171495
include_tokens_per_second: Optional[bool] = field(
15181496
default=False,
15191497
metadata={"help": "If set to `True`, the speed metrics will include `tgs` (tokens per second per device)."},
@@ -1606,13 +1584,6 @@ def __post_init__(self):
16061584
if self.disable_tqdm is None:
16071585
self.disable_tqdm = logger.getEffectiveLevel() > logging.WARN
16081586

1609-
if self.evaluation_strategy is not None:
1610-
warnings.warn(
1611-
"`evaluation_strategy` is deprecated and will be removed in version 4.46 of 🤗 Transformers. Use `eval_strategy` instead",
1612-
FutureWarning,
1613-
)
1614-
self.eval_strategy = self.evaluation_strategy
1615-
16161587
if isinstance(self.eval_strategy, EvaluationStrategy):
16171588
warnings.warn(
16181589
"using `EvaluationStrategy` for `eval_strategy` is deprecated and will be removed in version 5"
@@ -1771,7 +1742,7 @@ def __post_init__(self):
17711742

17721743
# We need to setup the accelerator config here *before* the first call to `self.device`
17731744
if is_accelerate_available():
1774-
if not isinstance(self.accelerator_config, (AcceleratorConfig)):
1745+
if not isinstance(self.accelerator_config, AcceleratorConfig):
17751746
if self.accelerator_config is None:
17761747
self.accelerator_config = AcceleratorConfig()
17771748
elif isinstance(self.accelerator_config, dict):
@@ -1786,22 +1757,6 @@ def __post_init__(self):
17861757
else:
17871758
self.accelerator_config = AcceleratorConfig.from_json_file(self.accelerator_config)
17881759

1789-
if self.dispatch_batches is not None:
1790-
warnings.warn(
1791-
"Using `--dispatch_batches` is deprecated and will be removed in version 4.41 of 🤗 Transformers. Use"
1792-
" `--accelerator_config {'dispatch_batches':VALUE} instead",
1793-
FutureWarning,
1794-
)
1795-
self.accelerator_config.dispatch_batches = self.dispatch_batches
1796-
1797-
if self.split_batches is not None:
1798-
warnings.warn(
1799-
"Using `--split_batches` is deprecated and will be removed in version 4.41 of 🤗 Transformers. Use"
1800-
" `--accelerator_config {'split_batches':VALUE} instead",
1801-
FutureWarning,
1802-
)
1803-
self.accelerator_config.split_batches = self.split_batches
1804-
18051760
# Initialize device before we proceed
18061761
if self.framework == "pt" and is_torch_available():
18071762
self.device

src/transformers/utils/quantization_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ def __init__(
646646
sym: bool = True,
647647
true_sequential: bool = True,
648648
checkpoint_format: str = "gptq",
649-
meta: Optional[Dict[str, any]] = None,
649+
meta: Optional[Dict[str, Any]] = None,
650650
backend: Optional[str] = None,
651651
use_cuda_fp16: bool = False,
652652
model_seqlen: Optional[int] = None,

tests/trainer/test_trainer.py

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from functools import partial
2929
from itertools import product
3030
from pathlib import Path
31-
from typing import Any, Dict, List
31+
from typing import Any
3232
from unittest.mock import Mock, patch
3333

3434
import numpy as np
@@ -2982,7 +2982,7 @@ def __init__(self):
29822982
self.tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
29832983
self.tokenizer.add_tokens(["<NEW_TOKEN1>", "<NEW_TOKEN2>"])
29842984

2985-
def __call__(self, features: List[Any], return_tensors="pt") -> Dict[str, Any]:
2985+
def __call__(self, features: list[Any], return_tensors="pt") -> dict[str, Any]:
29862986
return default_data_collator(features, return_tensors)
29872987

29882988
data_collator = FakeCollator()
@@ -2999,7 +2999,7 @@ def test_load_best_model_with_save(self):
29992999
trainer = get_regression_trainer(
30003000
output_dir=tmp_dir,
30013001
save_steps=5,
3002-
evaluation_strategy="steps",
3002+
eval_strategy="steps",
30033003
eval_steps=5,
30043004
max_steps=9,
30053005
)
@@ -3020,7 +3020,7 @@ def test_load_best_model_with_save(self):
30203020
trainer = get_regression_trainer(
30213021
output_dir=tmp_dir,
30223022
save_steps=5,
3023-
evaluation_strategy="steps",
3023+
eval_strategy="steps",
30243024
eval_steps=5,
30253025
load_best_model_at_end=True,
30263026
save_total_limit=2,
@@ -4260,7 +4260,7 @@ def test_accelerator_config_from_dict(self):
42604260
model = RegressionPreTrainedModel(config)
42614261
eval_dataset = SampleIterableDataset()
42624262

4263-
accelerator_config = {
4263+
accelerator_config: dict[str, Any] = {
42644264
"split_batches": True,
42654265
"dispatch_batches": True,
42664266
"even_batches": False,
@@ -4370,56 +4370,6 @@ def test_accelerator_config_from_partial(self):
43704370
self.assertEqual(trainer.accelerator.even_batches, True)
43714371
self.assertEqual(trainer.accelerator.use_seedable_sampler, True)
43724372

4373-
def test_accelerator_config_from_dict_with_deprecated_args(self):
4374-
# Checks that accelerator kwargs can be passed through
4375-
# and the accelerator is initialized respectively
4376-
# and maintains the deprecated args if passed in
4377-
with tempfile.TemporaryDirectory() as tmp_dir:
4378-
config = RegressionModelConfig(a=1.5, b=2.5)
4379-
model = RegressionPreTrainedModel(config)
4380-
eval_dataset = SampleIterableDataset()
4381-
4382-
# Leaves all options as something *not* basic
4383-
with self.assertWarns(FutureWarning) as cm:
4384-
args = RegressionTrainingArguments(
4385-
output_dir=tmp_dir,
4386-
accelerator_config={
4387-
"split_batches": True,
4388-
},
4389-
dispatch_batches=False,
4390-
)
4391-
self.assertIn("dispatch_batches", str(cm.warnings[0].message))
4392-
trainer = Trainer(model=model, args=args, eval_dataset=eval_dataset)
4393-
self.assertEqual(trainer.accelerator.dispatch_batches, False)
4394-
self.assertEqual(trainer.accelerator.split_batches, True)
4395-
with self.assertWarns(FutureWarning) as cm:
4396-
args = RegressionTrainingArguments(
4397-
output_dir=tmp_dir,
4398-
accelerator_config={
4399-
"even_batches": False,
4400-
},
4401-
split_batches=True,
4402-
)
4403-
self.assertIn("split_batches", str(cm.warnings[0].message))
4404-
trainer = Trainer(model=model, args=args, eval_dataset=eval_dataset)
4405-
self.assertEqual(trainer.accelerator.split_batches, True)
4406-
self.assertEqual(trainer.accelerator.even_batches, False)
4407-
self.assertEqual(trainer.accelerator.dispatch_batches, None)
4408-
4409-
def test_accelerator_config_only_deprecated_args(self):
4410-
with tempfile.TemporaryDirectory() as tmp_dir:
4411-
with self.assertWarns(FutureWarning) as cm:
4412-
args = RegressionTrainingArguments(
4413-
output_dir=tmp_dir,
4414-
split_batches=True,
4415-
)
4416-
self.assertIn("split_batches", str(cm.warnings[0].message))
4417-
config = RegressionModelConfig(a=1.5, b=2.5)
4418-
model = RegressionPreTrainedModel(config)
4419-
eval_dataset = SampleIterableDataset()
4420-
trainer = Trainer(model=model, args=args, eval_dataset=eval_dataset)
4421-
self.assertEqual(trainer.accelerator.split_batches, True)
4422-
44234373
def test_accelerator_custom_state(self):
44244374
AcceleratorState._reset_state(reset_partial_state=True)
44254375
with tempfile.TemporaryDirectory() as tmp_dir:
@@ -5191,7 +5141,7 @@ def model_init(trial):
51915141
def hp_name(trial):
51925142
return MyTrialShortNamer.shortname(trial.params)
51935143

5194-
def compute_objective(metrics: Dict[str, float]) -> List[float]:
5144+
def compute_objective(metrics: dict[str, float]) -> list[float]:
51955145
return metrics["eval_loss"], metrics["eval_accuracy"]
51965146

51975147
with tempfile.TemporaryDirectory() as tmp_dir:

tests/trainer/test_trainer_distributed.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ def compute_metrics(p: EvalPrediction) -> Dict:
200200
model = RegressionModel()
201201
training_args.per_device_train_batch_size = 1
202202
training_args.max_steps = 1
203-
training_args.dispatch_batches = False
203+
training_args.accelerator_config = {
204+
"dispatch_batches": False,
205+
}
204206
trainer = Trainer(model, training_args, train_dataset=train_dataset)
205207
trainer.train()

0 commit comments

Comments
 (0)