Hi,
Please check the autograd doc 4 on how to write a new Function.
For a loss, yes, the grad_ouput is just 1. Your output should be a tensor with a single value, and grad_output will as well be a tensor with a single value. Remember that loss.backward() is actually just a shortcut for loss.backward(torch.Tensor([1])).
The backward code should be an implementation of the derivative of your loss function: if your loss is output = f(input). Then your backward function should compute grad_input = df/dinput * grad_output.