My understanding is that create_graph will construct the whole graph for the backwards pass, this graph is needed when you want to calculate gradients of the gradients, as I do in my example: by calling grad_sum.backwards() I calculate the gradients of the loss function in respect to the grads.
The flag retain_graph preserves this backwards graph,  in case you need to use it again for some reason, for example, in my case I also wanted to penalize the growth of the second order gradients (diag of the hessian).