Piège
Par défaut, Pytorch libère le graphe après le premier backward(). Appeler une 2e fois lève RuntimeError: Trying to backward through the graph a second time. Pour le faire, il faut loss.backward(retain_graph=True). Cas typique : on veut analyser plusieurs gradients dérivés de la même loss, on oublie le flag.