Not sure why you need the custom Function? Is the goal just to flip the multiply the gradient by -alpha?
In your code above, you do
loss = XXX
(loss - loss).backward()

If you do that you won’t get any gradient because your loss is just 0 all the time.
What I was saying is to do (loss_a - loss_b).backward()