It has no choice but to decelerate, as the train itself will decelerate up an incline (without increasing power), and they are coupled. And yes the torque balance is why steam trains could climb gentle gradients at all. However the loss of power due to fewer piston pushes means that the peak 0rpm is reached very quickly. Diesel electric locos can literally increase RPM and power as they start to climb the gradient, with no connection between the slowing train speed and engine power.