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

Function is_torch_musa_available

src/transformers/utils/import_utils.py:360–382  ·  view source on GitHub ↗

Checks if `torch_musa` is installed and potentially if a MUSA is in the environment

(check_device=False)

Source from the content-addressed store, hash-verified

358
359@lru_cache
360def is_torch_musa_available(check_device=False) -> bool:
361 "Checks if `torch_musa` is installed and potentially if a MUSA is in the environment"
362 if not is_torch_available() or not _is_package_available("torch_musa")[0]:
363 return False
364
365 import torch
366 import torch_musa # noqa: F401
367
368 torch_musa_min_version = "0.33.0"
369 accelerate_available, accelerate_version = _is_package_available("accelerate", return_version=True)
370 if accelerate_available and version.parse(accelerate_version) < version.parse(torch_musa_min_version):
371 return False
372
373 if check_device:
374 try:
375 # Will raise a RuntimeError if no MUSA is found
376 if hasattr(torch, "musa"):
377 _ = torch.musa.device_count()
378 return torch.musa.is_available()
379 return False
380 except RuntimeError:
381 return False
382 return hasattr(torch, "musa") and torch.musa.is_available()
383
384
385@lru_cache

Callers 13

set_seedFunction · 0.85
__init__Method · 0.85
startMethod · 0.85
stopMethod · 0.85
__post_init__Method · 0.85
_setup_devicesMethod · 0.85
_save_rng_stateMethod · 0.85
_load_rng_stateMethod · 0.85
is_torch_tf32_availableFunction · 0.85
enable_tf32Function · 0.85
get_available_devicesFunction · 0.85

Calls 4

is_torch_availableFunction · 0.85
_is_package_availableFunction · 0.85
parseMethod · 0.45
is_availableMethod · 0.45

Tested by

no test coverage detected