The computation graph is created during the forward pass dynamically and you could traverse it back using the .grad_fn of the output.
Based on this graph, the backward() call can backpropagate through all operations and calculate the gradients for all parameters.