import torch


def create_optimizer(cfg, model):
    """
    Creates an adam optimizer with correct weight
    decay method.
    """
    optimizer = torch.optim.AdamW(
        model.parameters(),
        eps=cfg.adam_epsilon,
        lr=cfg.lr,
        weight_decay=cfg.weight_decay)

    return optimizer