2022-01-25 14:20:54 +00:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
import torch
|
|
|
|
|
|
|
|
|
|
|
|
class BaseOpHook(ABC):
|
|
|
|
"""This class allows users to add customized operations
|
|
|
|
before and after the execution of a PyTorch submodule"""
|
2022-03-31 13:37:17 +00:00
|
|
|
|
2022-01-25 14:20:54 +00:00
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def pre_fwd_exec(self, module: torch.nn.Module, *args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def post_fwd_exec(self, module: torch.nn.Module, *args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def pre_bwd_exec(self, module: torch.nn.Module, input, output):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def post_bwd_exec(self, module: torch.nn.Module, input):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def post_iter(self):
|
|
|
|
pass
|