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

Get device name without hlsmi #240

Merged
merged 6 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

-
- Fixed device name retrieval without hlsmi ([#240](https://github.com/Lightning-AI/lightning-Habana/pull/240))

### Removed

Expand Down
2 changes: 1 addition & 1 deletion src/lightning_habana/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.7.0"
__version__ = "1.7.0.rc0"
__author__ = "Lightning-AI et al."
__author_email__ = "[email protected]"
__license__ = "Apache-2.0"
Expand Down
15 changes: 13 additions & 2 deletions src/lightning_habana/utils/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ def get_hpu_synapse_version() -> str:
return hl or "0.0.0"


@lru_cache
def get_device_name_from_backend() -> str:
"""Return the name of the HPU device."""
try:
# this opens up a device to retrieve the name
return torch_hpu.get_device_name()
except (AttributeError, NameError):
# return GAUDI as default name
return "GAUDI"


def _parse_for_device_name(line: str) -> str:
"""Parse the CMD output with version capture.

Expand Down Expand Up @@ -123,9 +134,9 @@ def get_device_name_from_hlsmi() -> str:
"""Get hpu device name from hl-smi."""
try:
proc = subprocess.Popen(["hl-smi", "-L"], stdout=subprocess.PIPE)
# TODO: FileNotFoundError: No such file or directory: 'hl-smi'
except (FileNotFoundError, NotADirectoryError):
return "GAUDI"
# if hl-smi is not present, we open a device to get the name
return get_device_name_from_backend()
out = proc.communicate()[0]
return _parse_for_device_name(out.decode("utf-8"))

Expand Down
Loading