torch.autograd.function.FunctionCtx.mark_non_differentiable
- FunctionCtx.mark_non_differentiable(*args)
Mark outputs as non-differentiable.
This should be called at most once, in either the
setup_context()orforward()methods, and all arguments should be tensor outputs.This will mark outputs as not requiring gradients, increasing the efficiency of backward computation. You still need to accept a gradient for each output in
, but it’s always going to be a zero tensor with the same shape as the shape of a corresponding output.