Skip to content
Merged
Changes from all commits
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
4 changes: 2 additions & 2 deletions alf/utils/tensor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ def global_norm(tensors):
norm (Tensor): a scalar tensor
"""
assert alf.nest.is_nested(tensors), "tensors must be a nest! %s" % tensors
tensors = alf.nest.flatten(tensors)
tensors = [t for t in alf.nest.flatten(tensors) if t is not None]
if not tensors:
return torch.zeros((), dtype=torch.float32)
return torch.sqrt(
sum([
math_ops.square(torch.norm(torch.reshape(t, [-1])))
for t in tensors if t is not None
for t in tensors
]))


Expand Down
Loading