MCPcopy Create free account
hub / github.com/pytorch/pytorch / WeightDecayBuilder

Class WeightDecayBuilder

caffe2/python/optimizer.py:589–613  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

587
588
589class WeightDecayBuilder(Optimizer):
590 def __init__(self, weight_decay):
591 self.weight_decay = weight_decay
592
593 def _run(self, net, param_init_net, param_info):
594 dev = scope.CurrentDeviceScope()
595 if dev is None:
596 dev = core.DeviceOption(caffe2_pb2.CPU)
597
598 ONE = param_init_net.ConstantFill(
599 [], "ONE_{}_{}".format(dev.device_type, dev.device_id), shape=[1], value=1.0
600 )
601 WD = param_init_net.ConstantFill(
602 [],
603 "wd_{}_{}".format(dev.device_type, dev.device_id),
604 shape=[1],
605 value=self.weight_decay,
606 )
607
608 if isinstance(param_info.grad, core.GradientSlice):
609 raise ValueError("Weight decay does not yet support sparse gradients")
610 else:
611 net.WeightedSum(
612 [param_info.grad, ONE, param_info.blob, WD], param_info.grad
613 )
614
615
616class AdagradOptimizer(Optimizer):

Callers 1

add_weight_decayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…