I am assuming X is a real tensor…
What is the value of B? If it is positive, you will get nan…
However, if it is negative, you can do
torch.log(torch.tensor(-B)) + X # since torch.log(torch.exp(X)) => X

to avoid really high values in exp…