deprecate use_mps_device (#24239)
This commit is contained in:
committed by
GitHub
parent
3e142cb0f5
commit
3723329d01
@@ -656,7 +656,8 @@ Therefore, improving end-to-end performance.
|
|||||||
please follow this nice medium article [GPU-Acceleration Comes to PyTorch on M1 Macs](https://medium.com/towards-data-science/gpu-acceleration-comes-to-pytorch-on-m1-macs-195c399efcc1).
|
please follow this nice medium article [GPU-Acceleration Comes to PyTorch on M1 Macs](https://medium.com/towards-data-science/gpu-acceleration-comes-to-pytorch-on-m1-macs-195c399efcc1).
|
||||||
|
|
||||||
**Usage**:
|
**Usage**:
|
||||||
User has to just pass `--use_mps_device` argument.
|
`mps` device will be used by default if available similar to the way `cuda` device is used.
|
||||||
|
Therefore, no action from user is required.
|
||||||
For example, you can run the official Glue text classififcation task (from the root folder) using Apple Silicon GPU with below command:
|
For example, you can run the official Glue text classififcation task (from the root folder) using Apple Silicon GPU with below command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -672,7 +673,6 @@ python examples/pytorch/text-classification/run_glue.py \
|
|||||||
--learning_rate 2e-5 \
|
--learning_rate 2e-5 \
|
||||||
--num_train_epochs 3 \
|
--num_train_epochs 3 \
|
||||||
--output_dir /tmp/$TASK_NAME/ \
|
--output_dir /tmp/$TASK_NAME/ \
|
||||||
--use_mps_device \
|
|
||||||
--overwrite_output_dir
|
--overwrite_output_dir
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -581,7 +581,7 @@ class TrainingArguments:
|
|||||||
(https://pytorch.org/docs/stable/distributed.html#torch.distributed.init_process_group) for more
|
(https://pytorch.org/docs/stable/distributed.html#torch.distributed.init_process_group) for more
|
||||||
information.
|
information.
|
||||||
use_mps_device (`bool`, *optional*, defaults to `False`):
|
use_mps_device (`bool`, *optional*, defaults to `False`):
|
||||||
Whether to use Apple Silicon chip based `mps` device.
|
This argument is deprecated.`mps` device will be used if it is available similar to `cuda` device.
|
||||||
torch_compile (`bool`, *optional*, defaults to `False`):
|
torch_compile (`bool`, *optional*, defaults to `False`):
|
||||||
Whether or not to compile the model using PyTorch 2.0
|
Whether or not to compile the model using PyTorch 2.0
|
||||||
[`torch.compile`](https://pytorch.org/get-started/pytorch-2.0/).
|
[`torch.compile`](https://pytorch.org/get-started/pytorch-2.0/).
|
||||||
@@ -780,7 +780,11 @@ class TrainingArguments:
|
|||||||
)
|
)
|
||||||
no_cuda: bool = field(default=False, metadata={"help": "Do not use CUDA even when it is available"})
|
no_cuda: bool = field(default=False, metadata={"help": "Do not use CUDA even when it is available"})
|
||||||
use_mps_device: bool = field(
|
use_mps_device: bool = field(
|
||||||
default=False, metadata={"help": "Whether to use Apple Silicon chip based `mps` device."}
|
default=False,
|
||||||
|
metadata={
|
||||||
|
"help": "This argument is deprecated. `mps` device will be used if available similar to `cuda` device."
|
||||||
|
" It will be removed in version 5.0 of 🤗 Transformers"
|
||||||
|
},
|
||||||
)
|
)
|
||||||
seed: int = field(default=42, metadata={"help": "Random seed that will be set at the beginning of training."})
|
seed: int = field(default=42, metadata={"help": "Random seed that will be set at the beginning of training."})
|
||||||
data_seed: Optional[int] = field(default=None, metadata={"help": "Random seed to be used with data samplers."})
|
data_seed: Optional[int] = field(default=None, metadata={"help": "Random seed to be used with data samplers."})
|
||||||
@@ -1714,29 +1718,18 @@ class TrainingArguments:
|
|||||||
pass
|
pass
|
||||||
elif self.distributed_state.distributed_type == DistributedType.NO:
|
elif self.distributed_state.distributed_type == DistributedType.NO:
|
||||||
if self.use_mps_device:
|
if self.use_mps_device:
|
||||||
if not torch.backends.mps.is_available():
|
warnings.warn(
|
||||||
if not torch.backends.mps.is_built():
|
"`use_mps_device` is deprecated and will be removed in version 5.0 of 🤗 Transformers."
|
||||||
raise AssertionError(
|
"`mps` device will be used by default if available similar to the way `cuda` device is used."
|
||||||
"MPS not available because the current PyTorch install was not "
|
"Therefore, no action from user is required. "
|
||||||
"built with MPS enabled. Please install torch version >=1.12.0 on "
|
)
|
||||||
"your Apple silicon Mac running macOS 12.3 or later with a native "
|
if device.type != "mps":
|
||||||
"version (arm64) of Python"
|
raise ValueError(
|
||||||
)
|
"Either you do not have an MPS-enabled device on this machine or MacOS version is not 12.3+ "
|
||||||
else:
|
"or current PyTorch install was not built with MPS enabled."
|
||||||
raise AssertionError(
|
)
|
||||||
"MPS not available because the current MacOS version is not 12.3+ "
|
if device.type == "mps":
|
||||||
"and/or you do not have an MPS-enabled device on this machine."
|
self._n_gpu = 1
|
||||||
)
|
|
||||||
else:
|
|
||||||
if not version.parse(version.parse(torch.__version__).base_version) > version.parse("1.12.0"):
|
|
||||||
warnings.warn(
|
|
||||||
"We strongly recommend to install PyTorch >= 1.13 (nightly version at the time of writing)"
|
|
||||||
" on your MacOS machine. It has major fixes related to model correctness and performance"
|
|
||||||
" improvements for transformer based models. Please refer to"
|
|
||||||
" https://github.com/pytorch/pytorch/issues/82707 for more details."
|
|
||||||
)
|
|
||||||
device = torch.device("mps")
|
|
||||||
self._n_gpu = 1
|
|
||||||
elif self.no_cuda:
|
elif self.no_cuda:
|
||||||
device = torch.device("cpu")
|
device = torch.device("cpu")
|
||||||
self._n_gpu = 0
|
self._n_gpu = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user