Files
pytorch-lightning/pytorch_lightning/trainer/model_hooks.py
T
Jirka BorovecandNic Eggert 3be81cb54e test deprecated - model (#1074)
* pylint

* model API

* update test

* formatting

* disable logger

* fix checking overwrite

* fix test

* typo

* deprecated model

* fix for DDP

* drop Flake8 in GH actions

* Update pytorch_lightning/trainer/evaluation_loop.py

* fix imports

Co-authored-by: Nic Eggert <nic@eggert.io>
2020-03-20 20:51:14 +01:00

35 lines
1.1 KiB
Python

import inspect
from abc import ABC, abstractmethod
from pytorch_lightning.core.lightning import LightningModule
class TrainerModelHooksMixin(ABC):
def is_function_implemented(self, f_name):
model = self.get_model()
f_op = getattr(model, f_name, None)
return callable(f_op)
def is_overriden(self, method_name: str, model: LightningModule = None) -> bool:
if model is None:
model = self.get_model()
super_object = LightningModule
if not hasattr(model, method_name):
# in case of calling deprecated method
return False
# when code pointers are different, it was overriden
is_overriden = getattr(model, method_name).__code__ is not getattr(super_object, method_name).__code__
return is_overriden
def has_arg(self, f_name, arg_name):
model = self.get_model()
f_op = getattr(model, f_name, None)
return arg_name in inspect.signature(f_op).parameters
@abstractmethod
def get_model(self):
"""Warning: this is just empty shell for code implemented in other class."""