Solved by albanD in post #2 
              
              
                Hi, 
The problem is that you’re using ctx.save_for_backawrd() for things that are neither inputs or outputs. 
You can just save these on the ctx. and it will work: 
import torch
from torch.autograd import gradcheck

class CustomAutoG(torch.autograd.Function):
    #REF: https://pytorch.org/tutorials/…