Hello Clement!



 Bled_Clement:

I tried this but couldn’t get it to work for my application.


Please feel free to post a short, complete, runnable script
that has the original code you posted (that fails when the
tensor values become to large), together with your improved
attempt (using logsumexp() or whatever).  If you show us
what fails or what the discrepancy is, someone here will
probably be able to help you out.


Should it be as simple as replacing torch.log with torch. logsumexp()?


In isolation, such a direct replacement won’t work.
First, note that log10 (x) = log (x) / log (10).
Second, you wish to calculate
torch.log (1 + torch.exp (step2)).  Because
torch.exp (0) = 1, this can be written as
torch.log (torch.exp (0) + torch.exp (step2)),
for which you can use torch.logsumexp().
Since you are working with tensors, I imagine that you would
add a new dimension of length 2 to your tensor.  Along this
dimension, the first element would be that of your original
tensor, and the second element would be 0.  You would then
apply torch.logsumexp() along the new dimension, e.g.,
torch.logsumexp (my_new_tensor, dim = 0), where
the extra new dimension added to create my_new_tensor is,
in this example, dim = 0.
Good luck!
K. Frank