Solved by mcarilli in post #2 
              
              
                I don’t believe your use case is different from what’s shown in the docs, aside from more explicit kwargs and outputs being a Tensor with (presumably) more than one element.  Perhaps, instead of 

To implement a gradient penalty with gradient scaling, the loss passed to  torch.autograd.grad()  shoul…