from sklearn.metrics.pairwise import euclidean_distances as ED
optimizer = AdamW(model.parameters(), lr=opt.lr, betas=(opt.b1, opt.b2))
optimizer.zero_grad()
prediction = model(x)
loss = ED(prediction.detach.cpu().numpy(),labels.cpu().numpy()) # ED function requires numpy arrays
loss.backward()
optimizer.step()
Now the gradients are None. Surely, this is because I'm converting tensor to NumPy, the loss function needs NumPy but conversion leads to a vanishing gradient problem.
How to overcome this?
Any kind of reference is helpful.