(model, skip_list=(), skip_keywords=())
| 33 | |
| 34 | |
| 35 | def set_weight_decay(model, skip_list=(), skip_keywords=()): |
| 36 | has_decay = [] |
| 37 | no_decay = [] |
| 38 | |
| 39 | for name, param in model.named_parameters(): |
| 40 | if not param.requires_grad: |
| 41 | continue # frozen weights |
| 42 | if len(param.shape) == 1 or name.endswith(".bias") or (name in skip_list) or \ |
| 43 | check_keywords_in_name(name, skip_keywords): |
| 44 | no_decay.append(param) |
| 45 | # print(f"{name} has no weight decay") |
| 46 | else: |
| 47 | has_decay.append(param) |
| 48 | return [{'params': has_decay}, |
| 49 | {'params': no_decay, 'weight_decay': 0.}] |
| 50 | |
| 51 | |
| 52 | def check_keywords_in_name(name, keywords=()): |
no test coverage detected