Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLU devices : Checks if mlu is available via an cndev-based check which won't trigger the drivers and leave mlu #34326

Merged
merged 25 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2d36736
add Cambricon MLUs support
huismiling Mar 13, 2024
3ac7123
fix mlu device rng state
huismiling Mar 13, 2024
51ec085
up for quality check
huismiling Mar 14, 2024
db0fbe6
up mlu to support fp16
huismiling Mar 14, 2024
fe39b56
fix mlu device dependency error
huismiling Mar 14, 2024
c43b68e
fix mlu device dependency error
huismiling Mar 14, 2024
bd4d3f9
enable mlu device for bf16
huismiling Mar 14, 2024
988b2d6
fix mlu device memory tracker
huismiling Mar 25, 2024
e33678f
merge from hf main
huismiling Mar 25, 2024
0600601
Merge remote-tracking branch 'hf-transformers/main'
huismiling Apr 10, 2024
432febf
Merge branch 'huggingface:main' into main
huismiling May 8, 2024
44323c3
Merge branch 'huggingface:main' into main
huismiling May 20, 2024
6adf3d9
Cambricon support SDPA and flash_attn
huismiling May 29, 2024
9126fd5
Merge branch 'huggingface:main' into main
huismiling May 29, 2024
7dc5505
Merge branch 'huggingface:main' into main
huismiling Jun 25, 2024
e5cab7f
Merge branch 'huggingface:main' into main
huismiling Jul 18, 2024
596174e
Merge branch 'huggingface:main' into main
huismiling Aug 22, 2024
372c028
Merge branch 'huggingface:main' into main
huismiling Oct 15, 2024
18aa1bb
MLU devices : Checks if `mlu` is available via an `cndev-based` check…
huismiling Oct 23, 2024
c2ce606
Merge branch 'main' into main
huismiling Oct 25, 2024
6f9cca9
Merge branch 'main' into main
huismiling Oct 28, 2024
7770186
Merge branch 'main' into main
huismiling Nov 5, 2024
582a3b8
Merge branch 'main' into main
huismiling Nov 12, 2024
f28c917
Merge branch 'main' into main
huismiling Nov 15, 2024
586329e
Merge branch 'main' into main
huismiling Nov 19, 2024
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
26 changes: 14 additions & 12 deletions src/transformers/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,25 +684,27 @@ def is_torch_npu_available(check_device=False):

@lru_cache()
def is_torch_mlu_available(check_device=False):
"Checks if `torch_mlu` is installed and potentially if a MLU is in the environment"
"""
Checks if `mlu` is available via an `cndev-based` check which won't trigger the drivers and leave mlu
uninitialized.
"""
if not _torch_available or importlib.util.find_spec("torch_mlu") is None:
return False

import torch
import torch_mlu # noqa: F401

from ..dependency_versions_table import deps

deps["deepspeed"] = "deepspeed-mlu>=0.10.1"
pytorch_cndev_based_mlu_check_previous_value = os.environ.get("PYTORCH_CNDEV_BASED_MLU_CHECK")
try:
os.environ["PYTORCH_CNDEV_BASED_MLU_CHECK"] = str(1)
available = torch.mlu.is_available()
finally:
if pytorch_cndev_based_mlu_check_previous_value:
os.environ["PYTORCH_CNDEV_BASED_MLU_CHECK"] = pytorch_cndev_based_mlu_check_previous_value
else:
os.environ.pop("PYTORCH_CNDEV_BASED_MLU_CHECK", None)

if check_device:
try:
# Will raise a RuntimeError if no MLU is found
_ = torch.mlu.device_count()
return torch.mlu.is_available()
except RuntimeError:
return False
return hasattr(torch, "mlu") and torch.mlu.is_available()
return available


@lru_cache()
Expand Down
  NODES
COMMUNITY 2
Note 1
Project 4
USERS 1