def _construct_optimizer_from_config(module: Any, config: Union[str, Dict], model=None):
    """
    construct from the config, the config can be class name as a `str`, or a dict containing the construct parameters.
    """
    instance = None
    if isinstance(config, str):
        construct_name = getattr(module, config)
        if model is not None:
            trainable_params = [p for p in model.parameters() if p.requires_grad]
            instance = construct_name(trainable_params)
    elif isinstance(config, Dict):
        optimizer_construct_name = config[NAME]
        construct_name = getattr(module, optimizer_construct_name)
        kwargs = {}
        for arg_name in config:
            if arg_name != NAME:
                kwargs[arg_name] = config[arg_name]
        if model is not None:
            trainable_params = [p for p in model.parameters() if p.requires_grad]
            instance = construct_name(trainable_params, **kwargs)
    return instance
construct from the config, the config can be class name as a `str`, or a dict containing the construct parameters.
towhee/trainer/utils/trainer_utils.py