I’m not sure you can set this up in a numerically stable way because as you said, the problem is that if the input approaches -1, 1 the derivative of acos goes to infinity.
Is it possible to just use the dot product as a part of the loss function, and not include the acos?