I tried it in a slightly different manner and it works
import os
import numpy as np
import time
import torch
import torchvision
from torch import nn
from torch.autograd import Variable

def func0(x, y):
    return x + y

class SomeModule(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.y = nn.Parameter(torch.randn([1]))

    def forward(self, inp):
        def func1(x):
            return x + self.y

        out0 = func0(inp, self.y)
        out1 = func1(inp)
        return out0, out1
        
model = SomeModule()
inp = torch.randn(1) + 1
print(inp.grad_fn)
out0, out1 = model(inp)
print(out0.grad_fn)
print(out1.grad_fn)

torch.__version__
'1.8.1'