Solved by albanD in post #4 
              
              
                Hi, 
In this case, you should not save it on ctx at all and only with save_for_backward: 
I couldn’t run the code so there might be typos. But this is the idea: 
class CustomStd(torch.autograd.Function):
    @staticmethod
    def forward(ctx, input, dim=None, keepdim=False, eps=1e-5, unbiased=True):…