Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
resolve
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
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
ift
resolve
Commits
f09f19e2
Commit
f09f19e2
authored
4 years ago
by
Philipp Arras
Browse files
Options
Downloads
Patches
Plain Diff
Generalize to case where some tasks are empty
parent
656ea0f8
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!9
Mpi adder
Pipeline
#93670
passed
4 years ago
Stage: build_docker
Stage: testing
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
resolve/mpi_operators.py
+24
-9
24 additions, 9 deletions
resolve/mpi_operators.py
with
24 additions
and
9 deletions
resolve/mpi_operators.py
+
24
−
9
View file @
f09f19e2
...
@@ -8,8 +8,12 @@ import nifty7 as ift
...
@@ -8,8 +8,12 @@ import nifty7 as ift
class
AllreduceSum
(
ift
.
Operator
):
class
AllreduceSum
(
ift
.
Operator
):
def
__init__
(
self
,
oplist
,
comm
):
def
__init__
(
self
,
oplist
,
comm
):
self
.
_oplist
,
self
.
_comm
=
oplist
,
comm
self
.
_oplist
,
self
.
_comm
=
oplist
,
comm
self
.
_domain
=
self
.
_oplist
[
0
].
domain
self
.
_domain
=
ift
.
makeDomain
(
self
.
_target
=
self
.
_oplist
[
0
].
target
_get_global_unique
(
oplist
,
lambda
op
:
op
.
domain
,
comm
)
)
self
.
_target
=
ift
.
makeDomain
(
_get_global_unique
(
oplist
,
lambda
op
:
op
.
target
,
comm
)
)
def
apply
(
self
,
x
):
def
apply
(
self
,
x
):
self
.
_check_input
(
x
)
self
.
_check_input
(
x
)
...
@@ -20,7 +24,7 @@ class AllreduceSum(ift.Operator):
...
@@ -20,7 +24,7 @@ class AllreduceSum(ift.Operator):
opx
=
[
op
(
x
)
for
op
in
self
.
_oplist
]
opx
=
[
op
(
x
)
for
op
in
self
.
_oplist
]
val
=
ift
.
utilities
.
allreduce_sum
([
lin
.
val
for
lin
in
opx
],
self
.
_comm
)
val
=
ift
.
utilities
.
allreduce_sum
([
lin
.
val
for
lin
in
opx
],
self
.
_comm
)
jac
=
AllreduceSumLinear
([
lin
.
jac
for
lin
in
opx
],
self
.
_comm
)
jac
=
AllreduceSumLinear
([
lin
.
jac
for
lin
in
opx
],
self
.
_comm
)
if
opx
[
0
]
.
metric
is
None
:
if
_get_global_unique
(
opx
,
lambda
op
:
op
.
metric
is
None
,
self
.
_comm
)
:
return
x
.
new
(
val
,
jac
)
return
x
.
new
(
val
,
jac
)
met
=
AllreduceSumLinear
([
lin
.
metric
for
lin
in
opx
],
self
.
_comm
)
met
=
AllreduceSumLinear
([
lin
.
metric
for
lin
in
opx
],
self
.
_comm
)
return
x
.
new
(
val
,
jac
,
met
)
return
x
.
new
(
val
,
jac
,
met
)
...
@@ -29,12 +33,13 @@ class AllreduceSum(ift.Operator):
...
@@ -29,12 +33,13 @@ class AllreduceSum(ift.Operator):
class
AllreduceSumLinear
(
ift
.
LinearOperator
):
class
AllreduceSumLinear
(
ift
.
LinearOperator
):
def
__init__
(
self
,
oplist
,
comm
=
None
):
def
__init__
(
self
,
oplist
,
comm
=
None
):
assert
all
(
isinstance
(
oo
,
ift
.
LinearOperator
)
for
oo
in
oplist
)
assert
all
(
isinstance
(
oo
,
ift
.
LinearOperator
)
for
oo
in
oplist
)
self
.
_domain
=
ift
.
makeDomain
(
oplist
[
0
].
domain
)
self
.
_domain
=
ift
.
makeDomain
(
self
.
_target
=
ift
.
makeDomain
(
oplist
[
0
].
target
)
_get_global_unique
(
oplist
,
lambda
op
:
op
.
domain
,
comm
)
cap
=
oplist
[
0
].
_capability
)
assert
all
(
oo
.
domain
==
self
.
_domain
for
oo
in
oplist
)
self
.
_target
=
ift
.
makeDomain
(
assert
all
(
oo
.
target
==
self
.
_target
for
oo
in
oplist
)
_get_global_unique
(
oplist
,
lambda
op
:
op
.
target
,
comm
)
assert
all
(
oo
.
_capability
==
cap
for
oo
in
oplist
)
)
cap
=
_get_global_unique
(
oplist
,
lambda
op
:
op
.
_capability
,
comm
)
self
.
_capability
=
(
self
.
TIMES
|
self
.
ADJOINT_TIMES
)
&
cap
self
.
_capability
=
(
self
.
TIMES
|
self
.
ADJOINT_TIMES
)
&
cap
self
.
_oplist
=
oplist
self
.
_oplist
=
oplist
self
.
_comm
=
comm
self
.
_comm
=
comm
...
@@ -57,3 +62,13 @@ class AllreduceSumLinear(ift.LinearOperator):
...
@@ -57,3 +62,13 @@ class AllreduceSumLinear(ift.LinearOperator):
with
ift
.
random
.
Context
(
sseq
[
lo
+
ii
]):
with
ift
.
random
.
Context
(
sseq
[
lo
+
ii
]):
local_samples
.
append
(
op
.
draw_sample
(
from_inverse
))
local_samples
.
append
(
op
.
draw_sample
(
from_inverse
))
return
ift
.
utilities
.
allreduce_sum
(
local_samples
,
self
.
_comm
)
return
ift
.
utilities
.
allreduce_sum
(
local_samples
,
self
.
_comm
)
def
_get_global_unique
(
lst
,
f
,
comm
):
caps
=
[
f
(
oo
)
for
oo
in
lst
]
if
comm
is
not
None
:
caps
=
comm
.
allgather
(
caps
)
caps
=
[
aa
for
cc
in
caps
for
aa
in
cc
]
cap
=
caps
[
0
]
assert
all
(
cc
==
cap
for
cc
in
caps
)
return
cap
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