def group_weight_decay(net, decay_factor, skip_list):
    """Set up weight decay groups.

    skip_list is a list of module names to not apply decay to.

    """
    decay, no_decay = [], []
    for name, param in net.named_parameters():
        if not param.requires_grad:
            continue
        if any([pattern in name for pattern in skip_list]):
            no_decay.append(param)
        else:
            decay.append(param)
    return [{'params': no_decay, 'weight_decay': 0.0},
            {'params': decay, 'weight_decay': decay_factor}]