def get_optimizer_by_name(model, name, lr=1e-3, weight_decay=0,
                          adam_eps=1e-8,
                          sgd_momentum=0, sgd_nesterov=False):
    """
    Get optimizer by name

    Parameters
    ----------
    model : torch.nn.Module
        Model to be optimized.

    name : str
        Optimizer name. Available optimizers: 'adam', 'sgd'.
        See https://pytorch.org/docs/stable/optim.html for details.

    lr : float, optional (default=1e-3)
        Learning rate.

    weight_decay : float, optional (default=0)
        Weight decay (L2 penalty).

    adam_eps : float, optional (default=1e-8)
        Term added to the denominator to improve numerical stability.
        See https://pytorch.org/docs/stable/generated/torch.optim.Adam.html#torch.optim.Adam for details.

    sgd_momentum : float, optional (default=0)
        Momentum factor in SGD.
        See https://pytorch.org/docs/stable/generated/torch.optim.SGD.html#torch.optim.SGD for details.

    sgd_nesterov : bool, optional (default=False)
        Enables Nesterov momentum.
        See https://pytorch.org/docs/stable/generated/torch.optim.SGD.html#torch.optim.SGD for details.

    Returns
    -------
    optimizer : torch.optim.Optimizer
        Optimizer
    """
    optimizer_dict = {
        'adam': torch.optim.Adam(model.parameters(), lr=lr,
                                 weight_decay=weight_decay, eps=adam_eps),
        'sgd': torch.optim.SGD(model.parameters(), lr=lr,
                               momentum=sgd_momentum,
                               weight_decay=weight_decay,
                               nesterov=sgd_nesterov)
    }

    if name in optimizer_dict.keys():
        return optimizer_dict[name]

    else:
        raise ValueError(f"{name} is not a valid optimizer.")

    Get optimizer by name

    Parameters
    ----------
    model : torch.nn.Module
        Model to be optimized.

    name : str
        Optimizer name. Available optimizers: 'adam', 'sgd'.
        See https://pytorch.org/docs/stable/optim.html for details.

    lr : float, optional (default=1e-3)
        Learning rate.

    weight_decay : float, optional (default=0)
        Weight decay (L2 penalty).

    adam_eps : float, optional (default=1e-8)
        Term added to the denominator to improve numerical stability.
        See https://pytorch.org/docs/stable/generated/torch.optim.Adam.html#torch.optim.Adam for details.

    sgd_momentum : float, optional (default=0)
        Momentum factor in SGD.
        See https://pytorch.org/docs/stable/generated/torch.optim.SGD.html#torch.optim.SGD for details.

    sgd_nesterov : bool, optional (default=False)
        Enables Nesterov momentum.
        See https://pytorch.org/docs/stable/generated/torch.optim.SGD.html#torch.optim.SGD for details.

    Returns
    -------
    optimizer : torch.optim.Optimizer
        Optimizer
    
pyod/utils/torch_utility.py