MCPcopy Create free account
hub / github.com/AnswerDotAI/ModernBERT / param_groups_weight_decay

Function param_groups_weight_decay

main.py:97–110  ·  view source on GitHub ↗
(model: nn.Module, weight_decay=1e-5, no_weight_decay_list=())

Source from the content-addressed store, hash-verified

95# from timm: https://github.com/huggingface/pytorch-image-models/blob/main/timm/optim/optim_factory.py
96# Copyright 2019 Ross Wightman, Apache-2.0 License
97def param_groups_weight_decay(model: nn.Module, weight_decay=1e-5, no_weight_decay_list=()):
98 no_weight_decay_list = set(no_weight_decay_list)
99 decay = []
100 no_decay = []
101 for name, param in model.named_parameters():
102 if not param.requires_grad:
103 continue
104
105 if param.ndim <= 1 or name.endswith(".bias") or name in no_weight_decay_list:
106 no_decay.append(param)
107 else:
108 decay.append(param)
109
110 return [{"params": no_decay, "weight_decay": 0.0}, {"params": decay, "weight_decay": weight_decay}]
111
112
113def log_config(cfg: DictConfig):

Callers 2

build_optimizerFunction · 0.90
build_optimizerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected