The error indicates that sum(norm) returns a tensor with multiple values. If you intend to sum all values in norm, use torch.sum(norm) or norm.sum(). Using the built-in sum function will only sum over a single dimension.