File size: 619 Bytes
c94c8c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def no_decay_param_group(parameters, lr):
    no_decay = ['bias', 'LayerNorm.bias', 'LayerNorm.weight']
    decay_params = []
    no_decay_params = []
    for n, p in parameters:
        if p.requires_grad == False:
            continue
        if not any(nd in n for nd in no_decay):
            decay_params.append(p)
        else:
            no_decay_params.append(p)
            
    optimizer_grouped_parameters = [
        {'params': decay_params,
         'weight_decay': 0.01, 'lr': lr},
        {'params': no_decay_params,
         'weight_decay': 0.0, 'lr': lr}
    ]
    return optimizer_grouped_parameters