def _learning_rate_fairseq(hp, t):
    """
    Computes learning rate (alpha), According to Vaswani's Magical Warm-up Technique
    https://github.com/pytorch/fairseq/blob/master/fairseq/optim/lr_scheduler/inverse_square_root_schedule.py
    """
    warmup_init_lr = 1e-07
    # lr = 0.0005
    lr = 0.001
    min_lr =  1e-09
    warmup_end_lr = lr
    warmup_updates = hp.warmup
    decay_factor = warmup_end_lr * warmup_updates**0.5
    lr_step = (warmup_end_lr - warmup_init_lr) / warmup_updates

    if t == 0:
        raise RuntimeError(
            'Can\'t determine the learning rate of Adam optimizer '
            'because the update steps have not been started.')

    num_updates = t
    if num_updates < warmup_updates:
        lr = warmup_init_lr + num_updates*lr_step
    else:
        lr = decay_factor * num_updates**-0.5
    return lr