How to use torch.autograd.backward when variables are non-scalar

Dear smth, thank you very much for your help! And I understood your idea! I also find another related problem and wish it is helpful for others. Thanks!