So the forward method run inside a torch.no_grad() block. So even though the inputs may be marked are requiring gradient. All the elements computed inside the forward won’t require gradients.
The backward will run as any other python function (with grad enabled). So now the elements will require gradients depending on how they were computed.
Could you reformulate " How does this algorithm works to know to be safe making custom  autograd.Function 's?" I’m not sure what this means