Errors thown when using custom loss function (rmsle)
See original GitHub issueHello! I’m super excited to dig into using pytorch_tabnet, but I’ve been banging my head against a wall for the past 2 nights on this issue, so I’m putting out a call for assistance.
I’ve got everything setup properly and confirmed that my data has no missing values and no values outside the defined dimensions.
I can train properly using the default (MSELoss) loss function, but for my particular problem I need to use either mean squared log error or, ideally, root mean squared log error.
I’ve defined a custom loss function as follows:
def rmsle_loss(y_pred, y_true):
return torch.sqrt(nn.functional.mse_loss(torch.log(y_pred + 1), torch.log(y_true + 1)))
And I’m applying it to the model with the loss_fn=rmsle_loss
parameter to .fit()
.
However - when I do this, I’m getting these dreaded errors.
Using CPU:
index -1 is out of bounds for dimension 1 with size 22
Using GPU:
CUDA error: device-side assert triggered
Both of these are being thrown at line 94 in sparsemax.py:
tau = input_cumsum.gather(dim, support_size - 1)
Note this ONLY happens when I’m using a custom loss function. I am able to train the model just fine using the default loss function, but since that’s not ideal for my domain, I really need to use the custom function. As I mentioned above, I’ve confirmed that there are no inf, NA, or out-of-bounds data in my training set.
Any thoughts? Help would be deeply appreciated!
Issue Analytics
- State:
- Created a year ago
- Comments:10
Thanks for the detailed information.
The model should not predict negative values if training data is only positive. And that will probably be the case when training is finished. However, at start the model weights are randomly initialized so it’s very likely that negative values will occur. Even after few epochs, if the model needs to reach values as high as 10K, it’s hard to implicitly be sure that no input will yield negative scores. So as long as you don’t explicitly prevent the model to make negative predictions it might always happen.
Good luck with tuning your model!
Oh wow you are legendary @Optimox! Thanks for uncovering that and I’m glad I was (indirectly) able to help fix a bug 😃
I’m retraining now and there’s still a slight discrepancy (see below), but it’s now within range and likely for the reasons you mentioned, so I think we’re all good. Many many thanks.