MCPcopy Create free account
hub / github.com/SwinTransformer/Transformer-SSL / set_weight_decay

Function set_weight_decay

optimizer.py:35–49  ·  view source on GitHub ↗
(model, skip_list=(), skip_keywords=())

Source from the content-addressed store, hash-verified

33
34
35def 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
52def check_keywords_in_name(name, keywords=()):

Callers 1

build_optimizerFunction · 0.85

Calls 1

check_keywords_in_nameFunction · 0.85

Tested by

no test coverage detected