Why 'CUDA error: device-side assert triggered'?

sometimes CUDA error: device-side assert triggered occurs. with this.

The error indicates loss = torch.tensor(0).float().cuda().

This is my code.
loss = torch.tensor(0).float().cuda()
...get loss_A
loss += loss_A

What`s wrong in my code?

I don’t think loss = torch.tensor(0).float().cuda() is needed. loss = 0 will suffice. Did you try just that?

The error message points to a target values, which is out of bounds:

Assertion `cur_target >= 0 && cur_target < n_classes` failed

Make sure the target contains values in the range [0, nb_classes-1] for nn.CrossEntropyLoss or nn.NLLLoss.

1 Like