Can't save jit model with forward hook and custom function using torch.jit.script

Hi all, I’m recently learning to convert a model into jit model since I want to load a model without source class. And I use forward hook to extract middle layer outputs as features and then try to return the modified features, the code looks like follows:

from typing import Tuple, List, Callable

class MyClass(nn.Module):
    features: List[torch.Tensor]

    def __init__(self):
        super(MyClass, self).__init__()
        self.features = []
        self.model = torchvision.models.resnet50()

    def extract_feature(self) -> Callable:
        def hook(module, input: Tuple[torch.Tensor], output):
        return hook_t

    def __some_operation(self):
        self.result =[0], self.features[1]), 1)

    def forward(self, x):
        self.features = []
        _ = self.model(x)
        return self.result

my_model = MyClass()
my_script = jit.torch.scipt(my_model)"my_jit_model.pth")

but I got this error:

attribute lookup is not defined on python value of type 'MyClass':
            ~~~~~~~~~~~~~ <--- HERE

Sorry I’m not familiar with jit and just getting started, I would appreciate it if anyone could help me figure out the mistakes I make, thanks!