Skip to content
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
7 changes: 2 additions & 5 deletions kernel-builder/src/pyproject/templates/torch/noarch/_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ def get_backend() -> str:
"""Detect the backend by inspecting torch."""
import torch

if hasattr(torch.backends, "tpu"):
# torch_tpu sets torch.backends.tpu when it is imported (via
# torch's device-backend autoload), regardless of whether TPU
# hardware is present — analogous to torch.version.cuda being
# set on CUDA builds without a GPU.
acc = torch.accelerator.current_accelerator() if hasattr(torch, "accelerator") else None
if acc is not None and acc.type == "tpu":
return "tpu"
elif hasattr(torch, "neuron"):
# Needs to be sorted before specific Torch builds, since Neuron
Expand Down
8 changes: 2 additions & 6 deletions kernels/src/kernels/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,8 @@ def _backend() -> Backend:
if has_torch:
import torch

if hasattr(torch.backends, "tpu"):
# torch_tpu sets torch.backends.tpu when it is imported (via
# torch's device-backend autoload), regardless of whether TPU
# hardware is present — analogous to torch.version.cuda being
# set on CUDA builds without a GPU. The hardware-gated
# torch.tpu namespace only appears on hosts with TPU devices.
acc = torch.accelerator.current_accelerator() if hasattr(torch, "accelerator") else None
if acc is not None and acc.type == "tpu":
return TPU()
elif hasattr(torch, "neuron"):
# Needs to be sorted before specific Torch builds, since Neuron
Expand Down
Loading