Hi,
Yes automatic differentiation is used.
This basically computes gradients with the chain rule: if you have y = f(x) and z = g(y).
Then you compute dz/dx = dz/dy * dy/dx (with * being a matrix multiply).
So the only thing needed to compute any gradient is to have the formula for all the elementary functions and some mechanic to know how to apply them.
You can find (most) of the formulas in this 42 file that we use to define the mapping between a function and its derivative.
And the order is given by an acyclic graph that we create during the forward.