I have a list of parameters and I would like to sum all the elements in the list
import torch
from torch import nn
a = nn.Parameter(torch.rand(1))
b = nn.Parameter(torch.rand(1))
my_list = [a, b]
torch.sum(*my_list)
I receive the error
Traceback (most recent call last): File "<input>", line 8, in <module> TypeError: sum() received an invalid combination of arguments - got (Parameter, Parameter), but expected one of: * (Tensor input, *, torch.dtype dtype) * (Tensor input, tuple of ints dim, bool keepdim, *, torch.dtype dtype, Tensor out) * (Tensor input, tuple of names dim, bool keepdim, *, torch.dtype dtype, Tensor out)
I was wondering if there is a way to perform operations like torch.sum
on Parameter
s?