How to convert list of dimension 0 tensors, each attached with gradient, to a dimension 1 tensor with only one gradient?
I'm trying to make some adjustments to some pre-existing code, and can get a list that looks like the following:
[tensor(0.5209, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5572, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.7117, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5730, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.3471, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.3096, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.2592, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5197, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5979, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5248, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.4771, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.6718, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.6507, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5259, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.7259, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5728, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5604, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5691, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.4161, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.6565, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.7343, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.2743, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5333, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5636, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5657, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.3685, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5717, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.4868, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.6732, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.6726, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.3469, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5695, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5520, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.7080, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.3662, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5197, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.3505, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5745, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.6562, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5050, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5242, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.7020, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.4714, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.4119, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.6880, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5224, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.7321, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.5861, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.4058, grad_fn=&lt;SqueezeBackward0&gt;), tensor(0.6726, grad_fn=&lt;SqueezeBackward0&gt;)]
As you can see, each individual entry is a tensor requiring gradient. Of course, the backpropagation does not work unless a pass in a tensor of the form tensor([a,b,c,d,..., z], grad_fn = _) but I am not sure how to convert this list of tensors with gradient to a tensor of a list with a single attached gradient. After I obtain that, my plan is to just use something like .MSELoss() on the result. Any ideas on how to do this?

Using torch.hstack, you can put all tensors into a large one with one grad_fn.
tensors = [...]  # some tensors with grad_fn
torch.hstack(tensors)  # grad_fn is CatBackward0

