MCPcopy
hub / github.com/huggingface/transformers / get_available_devices

Function get_available_devices

src/transformers/utils/__init__.py:315–342  ·  view source on GitHub ↗

Returns a frozenset of devices available for the current PyTorch installation.

()

Source from the content-addressed store, hash-verified

313
314@lru_cache
315def 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)

Callers 2

_setup_static_tensorsMethod · 0.85

Calls 8

is_torch_cuda_availableFunction · 0.85
is_torch_mps_availableFunction · 0.85
is_torch_xpu_availableFunction · 0.85
is_torch_npu_availableFunction · 0.85
is_torch_hpu_availableFunction · 0.85
is_torch_mlu_availableFunction · 0.85
is_torch_musa_availableFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected