Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda authored and williamFalcon committed Oct 5, 2020
1 parent ccc5701 commit 97b858c
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions pytorch_lightning/metrics/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,23 +325,23 @@ def sync_horovod_if_available(
reduced value
"""

if HOROVOD_AVAILABLE and hvd.is_initialized():
if group is not None:
raise ValueError("Horovod does not support allreduce using a subcommunicator at "
"this time. Unset `group`.")

if reduce_op is None or reduce_op == "sum":
reduce_op = hvd.Sum
elif isinstance(reduce_op, str) and reduce_op in ("avg", "mean"):
reduce_op = hvd.Average
else:
raise ValueError(f"unrecognized `reduce_op`: {reduce_op}")

# sync all processes before reduction
hvd.join()
result = hvd.allreduce(result, op=reduce_op)

return result
if not (HOROVOD_AVAILABLE and hvd.is_initialized()):
return result
if group is not None:
raise ValueError(
"Horovod does not support allreduce using a subcommunicator at this time. Unset `group`."
)

if reduce_op is None or reduce_op == "sum":
reduce_op = hvd.Sum
elif isinstance(reduce_op, str) and reduce_op in ("avg", "mean"):
reduce_op = hvd.Average
else:
raise ValueError(f"unrecognized `reduce_op`: {reduce_op}")

# sync all processes before reduction
hvd.join()
return hvd.allreduce(result, op=reduce_op)


def at_least_1d(tensor: Union[np.ndarray, torch.Tensor]) -> Union[np.ndarray, torch.Tensor]:
Expand Down

0 comments on commit 97b858c

Please sign in to comment.