Skip to content

Commit

Permalink
Initialize AcceleratorConfig in optimum TrainingArgs. (huggingface#1750)
Browse files Browse the repository at this point in the history
* add accelerator config

* make style
  • Loading branch information
AdamLouly authored and young-developer committed May 10, 2024
1 parent 55a3afd commit ace6dac
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions optimum/onnxruntime/training_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
if is_torch_available():
import torch

if is_accelerate_available():
from transformers.trainer_pt_utils import AcceleratorConfig


class ORTOptimizerNames(ExplicitEnum):
"""
Expand Down Expand Up @@ -446,6 +449,30 @@ def __post_init__(self):
os.environ[f"{prefix}SYNC_MODULE_STATES"] = self.fsdp_config.get("sync_module_states", "true")
os.environ[f"{prefix}USE_ORIG_PARAMS"] = self.fsdp_config.get("use_orig_params", "false")

if is_accelerate_available():
if not isinstance(self.accelerator_config, (AcceleratorConfig)):
if self.accelerator_config is None:
self.accelerator_config = AcceleratorConfig()
elif isinstance(self.accelerator_config, dict):
self.accelerator_config = AcceleratorConfig(**self.accelerator_config)
else:
self.accelerator_config = AcceleratorConfig.from_json_file(self.accelerator_config)
if self.dispatch_batches is not None:
warnings.warn(
"Using `--dispatch_batches` is deprecated and will be removed in version 4.41 of 🤗 Transformers. Use"
" `--accelerator_config {'dispatch_batches':VALUE} instead",
FutureWarning,
)
self.accelerator_config.dispatch_batches = self.dispatch_batches

if self.split_batches is not None:
warnings.warn(
"Using `--split_batches` is deprecated and will be removed in version 4.41 of 🤗 Transformers. Use"
" `--accelerator_config {'split_batches':VALUE} instead",
FutureWarning,
)
self.accelerator_config.split_batches = self.split_batches

if self.tpu_metrics_debug:
warnings.warn(
"using `--tpu_metrics_debug` is deprecated and will be removed in version 5 of 🤗 Transformers. Use"
Expand Down

0 comments on commit ace6dac

Please sign in to comment.