Hi,
Your forward takes 3 arguments here so the backward should return 3 things: the gradient for v1, v2 and margin.
Since margin is a plain number, you cannot have gradients for it and you should return None. So the backward return statement should be return grad_v1, grad_v2, None.
You should use save_for_backward() if you need to save any input or output of the forward for the backward.