Returns a frozenset of devices available for the current PyTorch installation.
()
| 313 | |
| 314 | @lru_cache |
| 315 | def get_available_devices() -> frozenset[str]: |
| 316 | """ |
| 317 | Returns a frozenset of devices available for the current PyTorch installation. |
| 318 | """ |
| 319 | devices = {"cpu"} # `cpu` is always supported as a device in PyTorch |
| 320 | |
| 321 | if is_torch_cuda_available(): |
| 322 | devices.add("cuda") |
| 323 | |
| 324 | if is_torch_mps_available(): |
| 325 | devices.add("mps") |
| 326 | |
| 327 | if is_torch_xpu_available(): |
| 328 | devices.add("xpu") |
| 329 | |
| 330 | if is_torch_npu_available(): |
| 331 | devices.add("npu") |
| 332 | |
| 333 | if is_torch_hpu_available(): |
| 334 | devices.add("hpu") |
| 335 | |
| 336 | if is_torch_mlu_available(): |
| 337 | devices.add("mlu") |
| 338 | |
| 339 | if is_torch_musa_available(): |
| 340 | devices.add("musa") |
| 341 | |
| 342 | return frozenset(devices) |
no test coverage detected