Hello,
Sometimes my program crashes with the following stack trace:
File "/Users/GeorgesKanaan/Documents/Development/Python/KNet/src/main_scripts/train.py", line 101, in l1
    penalty += param.norm(1)
  File "/Users/GeorgesKanaan/Documents/Development/Python/KNet/venv/lib/python3.8/site-packages/torch/tensor.py", line 342, in norm
    return torch.norm(self, p, dim, keepdim, dtype=dtype)
  File "/Users/GeorgesKanaan/Documents/Development/Python/KNet/venv/lib/python3.8/site-packages/torch/functional.py", line 838, in norm
    return _VF.norm(input, p)
 (print_stack at ../torch/csrc/autograd/python_anomaly_mode.cpp:60)
Traceback (most recent call last):
  File "/Users/GeorgesKanaan/Documents/Development/Python/KNet/src/main_scripts/train.py", line 58, in train
    total_loss.backward()
  File "/Users/GeorgesKanaan/Documents/Development/Python/KNet/venv/lib/python3.8/site-packages/torch/tensor.py", line 198, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph)
  File "/Users/GeorgesKanaan/Documents/Development/Python/KNet/venv/lib/python3.8/site-packages/torch/autograd/__init__.py", line 98, in backward
    Variable._execution_engine.run_backward(
RuntimeError: 'ActiveGradsHook' object has no attribute '__name__'

ActiveGradsHook is below:
class ActiveGradsHook:
    """
    Resets the gradient according to the passed masks.
    """

    def __init__(self, previously_active: [bool], currently_active: [bool], bias=False):

        # Could be None for biases
        if previously_active is not None:
            self.previously_active = torch.BoolTensor(previously_active).long().nonzero().view(-1).numpy()

        # Should never be None
        self.currently_active = torch.BoolTensor(currently_active).long().nonzero().view(-1).numpy()

        self.is_bias = bias

    def __call__(self, grad):
        print("called hook")
        grad_clone = grad.clone().detach()
        print("cloned correctly")

        if self.is_bias:
            grad_clone[self.currently_active] = 0

        else:
            grad_clone[self.previously_active, :] = 0
            grad_clone[:, self.currently_active] = 0

        return grad_clone

It is passed as an initialized object as so on params:
hook = ActiveGradsHook(previously_active_weights, active_weights, bias=False)
param.register_hook(hook)

Why does pytorch expect the class to have an attribute __name__?