| 587 | |
| 588 | |
| 589 | class 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 | |
| 616 | class AdagradOptimizer(Optimizer): |
no outgoing calls
no test coverage detected
searching dependent graphs…