def METHOD_NAME(self, out: torch.Tensor) -> int:
    q = deque([out.grad_fn])
    num_functions = 0
    while len(q):
        fn = q.pop()
        num_functions += 1
        for next_fn, _ in fn.next_functions:
            if next_fn:
                q.append(next_fn)
    return num_functions