@contextmanager
def loss_not_reduced(self):
    if hasattr(self.loss_func, 'reduction'):
        return replacing_yield(self.loss_func, 'reduction', 'none')
    else:
        return replacing_yield(self, 'loss_func', partial(self.loss_func, reduction='none'))
@contextmanager
def loss_not_reduced(self):
    if hasattr(self.loss_func, 'reduction'):
        return replacing_yield(self.loss_func, 'reduction', 'none')
    else:
        return replacing_yield(self, 'loss_func', partial(self.loss_func, reduction='none'))