Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

lr rate of bias when training on multi gpus #19

Open
algorithmsummer opened this issue Nov 23, 2020 · 0 comments
Open

lr rate of bias when training on multi gpus #19

algorithmsummer opened this issue Nov 23, 2020 · 0 comments

Comments

@algorithmsummer
Copy link

Hi, should lr rate of bias be multiplied the num of gpus in the following codes ?

def make_optimizer(cfg, model, num_gpus=1):
    params = []
    for key, value in model.named_parameters():
        if not value.requires_grad:
            continue
        lr = cfg.SOLVER.BASE_LR * num_gpus
        # linear scaling rule
        weight_decay = cfg.SOLVER.WEIGHT_DECAY
        if "bias" in key:
            lr = cfg.SOLVER.BASE_LR * cfg.SOLVER.BIAS_LR_FACTOR
            weight_decay = cfg.SOLVER.WEIGHT_DECAY_BIAS
        params += [{"params": [value], "lr": lr, "weight_decay": weight_decay}]
    if cfg.SOLVER.OPTIMIZER_NAME == 'SGD':
        optimizer = getattr(torch.optim, cfg.SOLVER.OPTIMIZER_NAME)(params, momentum=cfg.SOLVER.MOMENTUM)
    else:
        optimizer = getattr(torch.optim, cfg.SOLVER.OPTIMIZER_NAME)(params)
    return optimizer
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant