Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Use multi-tensor sumSQ in clip_global_norm #17652

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions python/mxnet/gluon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import weakref
import requests

import mxnet as mx
from mxnet import nd
import numpy as np

from .. import ndarray
Expand Down Expand Up @@ -145,12 +143,12 @@ def group_by_ctx(arr_list):
all_ctx_sum = []
ctx = arrays[0].context
for group in arrays_groups:
sum_sq = mx.nd.multi_sum_sq(*arrays_groups[group],
num_arrays=len(arrays_groups[group]))
sum_sq = nd.add_n(*sum_sq)
sum_sq = ndarray.multi_sum_sq(*arrays_groups[group],
eric-haibin-lin marked this conversation as resolved.
Show resolved Hide resolved
num_arrays=len(arrays_groups[group]))
sum_sq = ndarray.add_n(*sum_sq)
all_ctx_sum.append(sum_sq.as_in_context(ctx))
# global reduce
total_norm = nd.add_n(*all_ctx_sum).sqrt()
total_norm = ndarray.add_n(*all_ctx_sum).sqrt()
if check_isfinite:
if not np.isfinite(total_norm.asscalar()):
warnings.warn(
Expand Down