Scott_Hoang:

       loss2.backward()
       optimizer_2.zero_grad()
       optimizer_2.step()



I believe you need to call zero_grad() either before backward() or after step(). Otherwise, the grad is always 0 when optimizer step tries to use it.