Loss.backward() gives RuntimeError: CUDA error: device-side assert triggered

I’m trying to use BCELoss without any success.

loss = BCELoss()
opt   = optim.AdamW  (model.parameters(), lr=0.01, betas=(0.9, 0.99), weight_decay=0.001)
loss = Loss(z, y)
opt.zero_grad() 
loss.backward()

z, y have the shape: (128, 2)

I’m getting error (from loss.backward()):

RuntimeError: CUDA error: device-side assert triggered
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
  1. What is wrong ?
  2. What do I need to change ?