Torch.stack cryptic error when using out= parameter

You are right. My example does pass, and that’s because the grad_fn attribute is None. Apologies for putting the wrong example. To get that error you must put a through a nn.Conv2d, that will result in torch.stack failing. However, if you use nn.functional.conv2d it will not populate a.grad_fn and therefore it will not fail.