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

Function is_torch_mlu_available

src/transformers/utils/import_utils.py:335–356  ·  view source on GitHub ↗

Checks if `mlu` is available via an `cndev-based` check which won't trigger the drivers and leave mlu uninitialized.

()

Source from the content-addressed store, hash-verified

333
334@lru_cache
335def is_torch_mlu_available() -> bool:
336 """
337 Checks if `mlu` is available via an `cndev-based` check which won't trigger the drivers and leave mlu
338 uninitialized.
339 """
340 if not is_torch_available() or not _is_package_available("torch_mlu")[0]:
341 return False
342
343 import torch
344 import torch_mlu # noqa: F401
345
346 pytorch_cndev_based_mlu_check_previous_value = os.environ.get("PYTORCH_CNDEV_BASED_MLU_CHECK")
347 try:
348 os.environ["PYTORCH_CNDEV_BASED_MLU_CHECK"] = str(1)
349 available = torch.mlu.is_available() if hasattr(torch, "mlu") else False
350 finally:
351 if pytorch_cndev_based_mlu_check_previous_value:
352 os.environ["PYTORCH_CNDEV_BASED_MLU_CHECK"] = pytorch_cndev_based_mlu_check_previous_value
353 else:
354 os.environ.pop("PYTORCH_CNDEV_BASED_MLU_CHECK", None)
355
356 return available
357
358
359@lru_cache

Callers 12

set_seedFunction · 0.85
__init__Method · 0.85
startMethod · 0.85
stopMethod · 0.85
testing_utils.pyFile · 0.85
_setup_devicesMethod · 0.85
_save_rng_stateMethod · 0.85
_load_rng_stateMethod · 0.85
get_available_devicesFunction · 0.85
__init__Method · 0.85

Calls 5

is_torch_availableFunction · 0.85
_is_package_availableFunction · 0.85
getMethod · 0.45
is_availableMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected