I have a complicated custom autograd function that requires a couple mechanisms to work, both of which are causing memory leaks.  I have simplified the function to essentially do nothing and it still causes the leaks just with the other mechanisms.  The simplified function is the following:
class Tagger(torch.autograd.Function):
    @staticmethod
    def forward(ctx, inp, Values):
        ctx.savedValues = Values
        return inp
    @staticmethod
    def backward(ctx, grad_out):
        return grad_out*0, None

There are two things that I believe are causing issues.  The first is that between forward and backward I add a new tensor to ‘Values’.  Even when this tensor is unused by the empty function  it still seems to cause leaks.  The simplest example I have been able to do to cause a leak is with:
Values.newVariable = torch.zeros(1)

The second place that seems to cause problems is with setting ‘grad_out’ of backwards manually.  I am doing this with a:
self.earlierOutputValue.register_hook(lambda grad: gradientValue)

I suspect it might be because I am assigning it to a self variable?  But this is required since I am setting it with a value that is not calculated until after the forward pass.