Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ICV-mmengine_basecode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Schiffel
ICV-mmengine_basecode
Commits
2994195b
Unverified
Commit
2994195b
authored
2 years ago
by
Alex Yang
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[Feat] Support training on MPS (#331)
* [Feat] Support mps * fix docstring
parent
e877862d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mmengine/device/__init__.py
+2
-2
2 additions, 2 deletions
mmengine/device/__init__.py
mmengine/device/utils.py
+11
-1
11 additions, 1 deletion
mmengine/device/utils.py
tests/test_device/test_device.py
+4
-1
4 additions, 1 deletion
tests/test_device/test_device.py
with
17 additions
and
4 deletions
mmengine/device/__init__.py
+
2
−
2
View file @
2994195b
# Copyright (c) OpenMMLab. All rights reserved.
# Copyright (c) OpenMMLab. All rights reserved.
from
.utils
import
(
get_device
,
get_max_cuda_memory
,
is_cuda_available
,
from
.utils
import
(
get_device
,
get_max_cuda_memory
,
is_cuda_available
,
is_mlu_available
)
is_mlu_available
,
is_mps_available
)
__all__
=
[
__all__
=
[
'
get_max_cuda_memory
'
,
'
get_device
'
,
'
is_cuda_available
'
,
'
get_max_cuda_memory
'
,
'
get_device
'
,
'
is_cuda_available
'
,
'
is_mlu_available
'
'
is_mlu_available
'
,
'
is_mps_available
'
]
]
This diff is collapsed.
Click to expand it.
mmengine/device/utils.py
+
11
−
1
View file @
2994195b
...
@@ -37,15 +37,25 @@ def is_mlu_available() -> bool:
...
@@ -37,15 +37,25 @@ def is_mlu_available() -> bool:
return
hasattr
(
torch
,
'
is_mlu_available
'
)
and
torch
.
is_mlu_available
()
return
hasattr
(
torch
,
'
is_mlu_available
'
)
and
torch
.
is_mlu_available
()
def
is_mps_available
()
->
bool
:
"""
Return True if mps devices exist.
It
'
s specialized for mac m1 chips and require torch version 1.12 or higher.
"""
return
hasattr
(
torch
.
backends
,
'
mps
'
)
and
torch
.
backends
.
mps
.
is_available
()
def
get_device
()
->
str
:
def
get_device
()
->
str
:
"""
Returns the currently existing device type.
"""
Returns the currently existing device type.
Returns:
Returns:
str: cuda | mlu | cpu.
str: cuda | mlu |
mps |
cpu.
"""
"""
if
is_cuda_available
():
if
is_cuda_available
():
return
'
cuda
'
return
'
cuda
'
elif
is_mlu_available
():
elif
is_mlu_available
():
return
'
mlu
'
return
'
mlu
'
elif
is_mps_available
():
return
'
mps
'
else
:
else
:
return
'
cpu
'
return
'
cpu
'
This diff is collapsed.
Click to expand it.
tests/test_device/test_device.py
+
4
−
1
View file @
2994195b
# Copyright (c) OpenMMLab. All rights reserved.
# Copyright (c) OpenMMLab. All rights reserved.
from
mmengine.device
import
get_device
,
is_cuda_available
,
is_mlu_available
from
mmengine.device
import
(
get_device
,
is_cuda_available
,
is_mlu_available
,
is_mps_available
)
def
test_get_device
():
def
test_get_device
():
...
@@ -8,5 +9,7 @@ def test_get_device():
...
@@ -8,5 +9,7 @@ def test_get_device():
assert
device
==
'
cuda
'
assert
device
==
'
cuda
'
elif
is_mlu_available
():
elif
is_mlu_available
():
assert
device
==
'
mlu
'
assert
device
==
'
mlu
'
elif
is_mps_available
():
assert
device
==
'
mps
'
else
:
else
:
assert
device
==
'
cpu
'
assert
device
==
'
cpu
'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment