Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HPU support #1

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/transformers/training_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
is_torch_available,
is_torch_bf16_cpu_available,
is_torch_bf16_gpu_available,
is_torch_hpu_available,
is_torch_mlu_available,
is_torch_mps_available,
is_torch_musa_available,
Expand Down Expand Up @@ -2268,6 +2269,9 @@ def _setup_devices(self) -> "torch.device":
elif is_torch_npu_available():
device = torch.device("npu:0")
torch.npu.set_device(device)
elif is_torch_hpu_available():
device = torch.device("hpu:0")
torch.hpu.set_device(device)
else:
# if n_gpu is > 1 we'll use nn.DataParallel.
# If you only want to use a specific subset of GPUs use `CUDA_VISIBLE_DEVICES=0`
Expand Down
1 change: 1 addition & 0 deletions src/transformers/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
is_torch_fx_available,
is_torch_fx_proxy,
is_torch_greater_or_equal,
is_torch_hpu_available,
is_torch_mlu_available,
is_torch_mps_available,
is_torch_musa_available,
Expand Down
9 changes: 9 additions & 0 deletions src/transformers/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,15 @@ def is_torch_musa_available(check_device=False):
return hasattr(torch, "musa") and torch.musa.is_available()


@lru_cache()
def is_torch_hpu_available():
try:
import torch
return torch.device("hpu") is not None
except (ImportError, RuntimeError):
return False


def is_torchdynamo_available():
if not is_torch_available():
return False
Expand Down
Loading