Converting a list of tensors to a tensor and set grad_fn

I have a list of tensors in this form:

[tensor(-2.9222, grad_fn=), tensor(-2.8192, grad_fn=SqueezeBackward1>), tensor(-3.1894, grad_fn=), tensor(-2.9048, grad_fn=)]

and what I need is this list to be in the form of a tensor like this:

tensor([-0.5575, -0.9004, -0.8491, …, -0.7345, -0.6729, -0.7553],grad_fn=SqueezeBackward1>)

Is it possible to do such a conversion and keep the grad_fn set as it is per tensor in the original image?

In the second case there is only one tensor. grad_fn is stored as an attribute of a tensor. So you cannot store the grad_fn of multiple tensors in a single tensor (you can use a proxy to sum all the tensors, but your case that is not valid).