Concatenation of losses raise an error

I have two tensors

# losses_q
tensor(0.0870, device='cuda:0', grad_fn=<SumBackward0>)
# this_loss_q
tensor([0.0874], device='cuda:0', grad_fn=<AddBackward0>)

when I am trying to concat them, pytorch raises an error:

losses_q =, this_loss_q), dim=0)

RuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated

How to resolve this?

unsqueeze should work as it will add a dimension to the tensor:

losses_q =, this_loss_q), dim=0)
1 Like

@ptrblck Thanks a lot, it worked.