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
0ca54eb7
Unverified
Commit
0ca54eb7
authored
2 years ago
by
Zaida Zhou
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[Fix] Fix unit tests when gpu is not available (#163)
parent
25014af3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_dist/test_dist.py
+10
-2
10 additions, 2 deletions
tests/test_dist/test_dist.py
tests/test_dist/test_utils.py
+7
-1
7 additions, 1 deletion
tests/test_dist/test_utils.py
with
17 additions
and
3 deletions
tests/test_dist/test_dist.py
+
10
−
2
View file @
0ca54eb7
...
@@ -6,6 +6,7 @@ from unittest.mock import patch
...
@@ -6,6 +6,7 @@ from unittest.mock import patch
import
pytest
import
pytest
import
torch
import
torch
import
torch.distributed
as
torch_dist
import
torch.multiprocessing
as
mp
import
torch.multiprocessing
as
mp
import
mmengine.dist
as
dist
import
mmengine.dist
as
dist
...
@@ -108,9 +109,16 @@ def init_process(rank, world_size, functions, backend='gloo'):
...
@@ -108,9 +109,16 @@ def init_process(rank, world_size, functions, backend='gloo'):
os
.
environ
[
'
MASTER_ADDR
'
]
=
'
127.0.0.1
'
os
.
environ
[
'
MASTER_ADDR
'
]
=
'
127.0.0.1
'
os
.
environ
[
'
MASTER_PORT
'
]
=
'
29505
'
os
.
environ
[
'
MASTER_PORT
'
]
=
'
29505
'
os
.
environ
[
'
RANK
'
]
=
str
(
rank
)
os
.
environ
[
'
RANK
'
]
=
str
(
rank
)
dist
.
init_dist
(
'
pytorch
'
,
backend
,
rank
=
rank
,
world_size
=
world_size
)
device
=
'
cpu
'
if
backend
==
'
gloo
'
else
'
cuda
'
if
backend
==
'
nccl
'
:
num_gpus
=
torch
.
cuda
.
device_count
()
torch
.
cuda
.
set_device
(
rank
%
num_gpus
)
device
=
'
cuda
'
else
:
device
=
'
cpu
'
torch_dist
.
init_process_group
(
backend
=
backend
,
rank
=
rank
,
world_size
=
world_size
)
for
func
in
functions
:
for
func
in
functions
:
func
(
device
)
func
(
device
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_dist/test_utils.py
+
7
−
1
View file @
0ca54eb7
...
@@ -55,7 +55,13 @@ def init_process(rank, world_size, functions, backend='gloo'):
...
@@ -55,7 +55,13 @@ def init_process(rank, world_size, functions, backend='gloo'):
os
.
environ
[
'
MASTER_ADDR
'
]
=
'
127.0.0.1
'
os
.
environ
[
'
MASTER_ADDR
'
]
=
'
127.0.0.1
'
os
.
environ
[
'
MASTER_PORT
'
]
=
'
29501
'
os
.
environ
[
'
MASTER_PORT
'
]
=
'
29501
'
os
.
environ
[
'
RANK
'
]
=
str
(
rank
)
os
.
environ
[
'
RANK
'
]
=
str
(
rank
)
dist
.
init_dist
(
'
pytorch
'
,
backend
,
rank
=
rank
,
world_size
=
world_size
)
if
backend
==
'
nccl
'
:
num_gpus
=
torch
.
cuda
.
device_count
()
torch
.
cuda
.
set_device
(
rank
%
num_gpus
)
torch_dist
.
init_process_group
(
backend
=
backend
,
rank
=
rank
,
world_size
=
world_size
)
dist
.
init_local_group
(
0
,
world_size
)
dist
.
init_local_group
(
0
,
world_size
)
for
func
in
functions
:
for
func
in
functions
:
...
...
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