[Accelerator][Chore] Use existing acc when raising an error (#150829)

As the title said, `acc` already exists so we just use it instead of calling `current_accelerator()` again.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/150829
Approved by: https://github.com/guangyey, https://github.com/Skylion007
This commit is contained in:
Yuanhao Ji
2025-04-08 16:05:03 +00:00
committed by PyTorch MergeBot
parent ec5f2e3028
commit 1239260a0e

View File

@ -16,7 +16,7 @@ def _get_device_index(device: _device_t, optional: bool = False) -> int:
raise RuntimeError("Accelerator expected")
if acc.type != device.type:
raise ValueError(
f"{device.type} doesn't match the current accelerator {torch.accelerator.current_accelerator()}."
f"{device.type} doesn't match the current accelerator {acc}."
)
device_index = device.index
if device_index is None: