From c005be3b611204898c385c7803677c068b88cec7 Mon Sep 17 00:00:00 2001 From: Andrew Choi Date: Fri, 27 Mar 2026 11:07:13 -0700 Subject: [PATCH] Have global_norm properly handle when input consists of only None --- alf/utils/tensor_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alf/utils/tensor_utils.py b/alf/utils/tensor_utils.py index a45a972e2..ace1a1de3 100644 --- a/alf/utils/tensor_utils.py +++ b/alf/utils/tensor_utils.py @@ -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 ]))