    def set_optimizer(self, optimizer: optim.Optimizer, optimizer_name: str = None):
        """
        Set custom optimizer

        Args:
            optimizer (`optim.Optimizer`):
                User's custom optimizer instance.
            optimizer_name (`str`):
                The optimizer string in training config, if it is `None`, the string will be a default value.

        Examples:
            >>> from towhee.trainer.trainer import Trainer
            >>> from typing import Optional, Callable
            >>> from torch import optim
            >>> import torchvision.models as models
            >>> model = models.resnet18()
            >>> trainer = Trainer(model)
            2022-03-01 17:22:52,306 - 8614221312 - trainer.py-trainer:173 - WARNING: No `TrainingConfig` passed.
            >>> class MyOptimizer(optim.Optimizer):
            ...     def step(self, closure: Optional[Callable[[], float]]=...) -> Optional[float]:
            ...         print('my step...')
            ...
            >>> my_optimizer = MyOptimizer(model.parameters(), defaults={})
            >>> trainer.set_optimizer(my_optimizer)
            >>> type(trainer.optimizer)
            <class '__main__.MyOptimizer'>
        """
        self.override_optimizer = True
        self.configs.optimizer = CUSTOM if optimizer_name is None else optimizer_name
        self.optimizer = optimizer
Set custom optimizer

Args:
optimizer (`optim.Optimizer`):
User's custom optimizer instance.
optimizer_name (`str`):
The optimizer string in training config, if it is `None`, the string will be a default value.

Examples:
>>> from towhee.trainer.trainer import Trainer
>>> from typing import Optional, Callable
>>> from torch import optim
>>> import torchvision.models as models
>>> model = models.resnet18()
>>> trainer = Trainer(model)
2022-03-01 17:22:52,306 - 8614221312 - trainer.py-trainer:173 - WARNING: No `TrainingConfig` passed.
>>> class MyOptimizer(optim.Optimizer):
...     def step(self, closure: Optional[Callable[[], float]]=...) -> Optional[float]:
...         print('my step...')
...
>>> my_optimizer = MyOptimizer(model.parameters(), defaults={})
>>> trainer.set_optimizer(my_optimizer)
>>> type(trainer.optimizer)
<class '__main__.MyOptimizer'>
towhee/trainer/trainer.py