-
Notifications
You must be signed in to change notification settings - Fork 438
[Feature] Add the support for musa device support #1453
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e8a3e05
add musa device support, skip some ut, can find the place that is ski…
hanhaowen-mt 51c5cb1
lint
hanhaowen-mt 243d093
comment a test case(test_get_max_memory) for musa
hanhaowen-mt 658a2f2
revise logging/logger.py for ci
hanhaowen-mt f7c0b07
Apply suggestions from code review
hanhaowen-mt beeff1f
Apply suggestions from code review
zhouzaida File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| # Copyright (c) OpenMMLab. All rights reserved. | ||
| from .utils import (get_device, get_max_cuda_memory, is_cuda_available, | ||
| is_dipu_available, is_mlu_available, is_mps_available, | ||
| is_npu_available, is_npu_support_full_precision) | ||
| from .utils import (get_device, get_max_cuda_memory, get_max_musa_memory, | ||
| is_cuda_available, is_dipu_available, is_mlu_available, | ||
| is_mps_available, is_musa_available, is_npu_available, | ||
| is_npu_support_full_precision) | ||
|
|
||
| __all__ = [ | ||
| 'get_max_cuda_memory', 'get_device', 'is_cuda_available', | ||
| 'is_mlu_available', 'is_mps_available', 'is_npu_available', | ||
| 'is_dipu_available', 'is_npu_support_full_precision' | ||
| 'is_dipu_available', 'get_max_musa_memory', 'is_musa_available', | ||
| 'is_npu_support_full_precision' | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,12 @@ | |
| except Exception: | ||
| IS_DIPU_AVAILABLE = False | ||
|
|
||
| try: | ||
| import torch_musa # noqa: F401 | ||
| IS_MUSA_AVAILABLE = True | ||
| except Exception: | ||
| IS_MUSA_AVAILABLE = False | ||
|
|
||
|
|
||
| def get_max_cuda_memory(device: Optional[torch.device] = None) -> int: | ||
| """Returns the maximum GPU memory occupied by tensors in megabytes (MB) for | ||
|
|
@@ -73,6 +79,34 @@ def is_dipu_available() -> bool: | |
| return IS_DIPU_AVAILABLE | ||
|
|
||
|
|
||
| def get_max_musa_memory(device: Optional[torch.device] = None) -> int: | ||
| """Returns the maximum GPU memory occupied by tensors in megabytes (MB) for | ||
| a given device. By default, this returns the peak allocated memory since | ||
| the beginning of this program. | ||
|
|
||
| Args: | ||
| device (torch.device, optional): selected device. Returns | ||
| statistic for the current device, given by | ||
| :func:`~torch.musa.current_device`, if ``device`` is None. | ||
| Defaults to None. | ||
|
|
||
| Returns: | ||
| int: The maximum GPU memory occupied by tensors in megabytes | ||
| for a given device. | ||
| """ | ||
| mem = torch.musa.max_memory_allocated(device=device) | ||
| mem_mb = torch.tensor([int(mem) // (1024 * 1024)], | ||
| dtype=torch.int, | ||
| device=device) | ||
| # TODO:[email protected]: This function is not supported by musa yet. | ||
| # torch.musa.reset_peak_memory_stats() | ||
| return int(mem_mb.item()) | ||
|
|
||
|
|
||
| def is_musa_available() -> bool: | ||
| return IS_MUSA_AVAILABLE | ||
|
|
||
|
|
||
| def is_npu_support_full_precision() -> bool: | ||
| """Returns True if npu devices support full precision training.""" | ||
| version_of_support_full_precision = 220 | ||
|
|
@@ -91,12 +125,14 @@ def is_npu_support_full_precision() -> bool: | |
| DEVICE = 'mps' | ||
| elif is_dipu_available(): | ||
| DEVICE = 'dipu' | ||
| elif is_musa_available(): | ||
| DEVICE = 'musa' | ||
|
|
||
|
|
||
| def get_device() -> str: | ||
| """Returns the currently existing device type. | ||
|
|
||
| Returns: | ||
| str: cuda | npu | mlu | mps | cpu. | ||
| str: cuda | npu | mlu | mps | musa | cpu. | ||
| """ | ||
| return DEVICE | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.