Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
SOLOv2-pytorch
Commits
d04fa0f3
Commit
d04fa0f3
authored
Sep 25, 2018
by
Kai Chen
Browse files
move _sync_param from forward to init
parent
b7968de7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
6 deletions
+3
-6
mmdet/nn/parallel/distributed.py
mmdet/nn/parallel/distributed.py
+2
-5
tools/train.py
tools/train.py
+1
-1
No files found.
mmdet/nn/parallel/distributed.py
View file @
d04fa0f3
...
@@ -15,8 +15,8 @@ class MMDistributedDataParallel(nn.Module):
...
@@ -15,8 +15,8 @@ class MMDistributedDataParallel(nn.Module):
self
.
dim
=
dim
self
.
dim
=
dim
self
.
broadcast_buffers
=
broadcast_buffers
self
.
broadcast_buffers
=
broadcast_buffers
self
.
first_synced
=
False
self
.
broadcast_bucket_size
=
32
*
1024
*
1024
self
.
broadcast_bucket_size
=
32
*
1024
*
1024
self
.
_sync_params
()
def
_dist_broadcast_coalesced
(
self
,
tensors
,
buffer_size
):
def
_dist_broadcast_coalesced
(
self
,
tensors
,
buffer_size
):
for
tensors
in
_take_tensors
(
tensors
,
buffer_size
):
for
tensors
in
_take_tensors
(
tensors
,
buffer_size
):
...
@@ -26,7 +26,7 @@ class MMDistributedDataParallel(nn.Module):
...
@@ -26,7 +26,7 @@ class MMDistributedDataParallel(nn.Module):
tensors
,
_unflatten_dense_tensors
(
flat_tensors
,
tensors
)):
tensors
,
_unflatten_dense_tensors
(
flat_tensors
,
tensors
)):
tensor
.
copy_
(
synced
)
tensor
.
copy_
(
synced
)
def
sync_params
(
self
):
def
_
sync_params
(
self
):
module_states
=
list
(
self
.
module
.
state_dict
().
values
())
module_states
=
list
(
self
.
module
.
state_dict
().
values
())
if
len
(
module_states
)
>
0
:
if
len
(
module_states
)
>
0
:
self
.
_dist_broadcast_coalesced
(
module_states
,
self
.
_dist_broadcast_coalesced
(
module_states
,
...
@@ -41,9 +41,6 @@ class MMDistributedDataParallel(nn.Module):
...
@@ -41,9 +41,6 @@ class MMDistributedDataParallel(nn.Module):
return
scatter_kwargs
(
inputs
,
kwargs
,
device_ids
,
dim
=
self
.
dim
)
return
scatter_kwargs
(
inputs
,
kwargs
,
device_ids
,
dim
=
self
.
dim
)
def
forward
(
self
,
*
inputs
,
**
kwargs
):
def
forward
(
self
,
*
inputs
,
**
kwargs
):
if
not
self
.
first_synced
:
self
.
sync_params
()
self
.
first_synced
=
True
inputs
,
kwargs
=
self
.
scatter
(
inputs
,
kwargs
,
inputs
,
kwargs
=
self
.
scatter
(
inputs
,
kwargs
,
[
torch
.
cuda
.
current_device
()])
[
torch
.
cuda
.
current_device
()])
return
self
.
module
(
*
inputs
[
0
],
**
kwargs
[
0
])
return
self
.
module
(
*
inputs
[
0
],
**
kwargs
[
0
])
tools/train.py
View file @
d04fa0f3
...
@@ -95,7 +95,7 @@ def main():
...
@@ -95,7 +95,7 @@ def main():
model
=
build_detector
(
model
=
build_detector
(
cfg
.
model
,
train_cfg
=
cfg
.
train_cfg
,
test_cfg
=
cfg
.
test_cfg
)
cfg
.
model
,
train_cfg
=
cfg
.
train_cfg
,
test_cfg
=
cfg
.
test_cfg
)
if
dist
:
if
dist
:
model
=
MMDistributedDataParallel
(
model
)
.
cuda
()
model
=
MMDistributedDataParallel
(
model
.
cuda
()
)
else
:
else
:
model
=
MMDataParallel
(
model
,
device_ids
=
range
(
cfg
.
gpus
)).
cuda
()
model
=
MMDataParallel
(
model
,
device_ids
=
range
(
cfg
.
gpus
)).
cuda
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment