| 1397 | |
| 1398 | |
| 1399 | class AdadeltaOptimizer(Optimizer): |
| 1400 | def __init__( |
| 1401 | self, |
| 1402 | alpha=0.01, |
| 1403 | epsilon=1e-4, |
| 1404 | decay=0.95, |
| 1405 | policy="fixed", |
| 1406 | sparse_dedup_aggregator=None, |
| 1407 | engine="", |
| 1408 | **kwargs |
| 1409 | ): |
| 1410 | """Constructor function to add Adadelta Optimizer |
| 1411 | |
| 1412 | Args: |
| 1413 | alpha: learning rate |
| 1414 | epsilon: attribute of Adadelta to avoid numerical issues |
| 1415 | decay: attribute of Adadelta to decay the squared gradient sum |
| 1416 | policy: specifies how learning rate should be applied, options are |
| 1417 | "fixed", "step", "exp", etc. |
| 1418 | sparse_dedup_aggregator: specifies deduplication strategy for |
| 1419 | gradient slices. Works while using sparse gradients. Options |
| 1420 | include "mean" and "sum". |
| 1421 | engine: the engine used, options include "", "CUDNN", etc. |
| 1422 | """ |
| 1423 | super().__init__() |
| 1424 | self.alpha = alpha |
| 1425 | self.epsilon = epsilon |
| 1426 | self.decay = decay |
| 1427 | self.policy = policy |
| 1428 | self.sparse_dedup_aggregator = sparse_dedup_aggregator |
| 1429 | self.engine = engine |
| 1430 | self.init_kwargs = kwargs |
| 1431 | |
| 1432 | def _run(self, net, param_init_net, param_info): |
| 1433 | param = param_info.blob |
| 1434 | grad = param_info.grad |
| 1435 | |
| 1436 | if self.alpha <= 0: |
| 1437 | return |
| 1438 | |
| 1439 | lr, _ = self.build_lr( |
| 1440 | net, |
| 1441 | param_init_net, |
| 1442 | base_learning_rate=self.alpha, |
| 1443 | policy=self.policy, |
| 1444 | **(self.init_kwargs) |
| 1445 | ) |
| 1446 | |
| 1447 | moment = param_init_net.ConstantFill( |
| 1448 | [param], str(param) + "_squared_moment", value=0.0 |
| 1449 | ) |
| 1450 | |
| 1451 | moment_update = param_init_net.ConstantFill( |
| 1452 | [param], str(param) + "_squared_moment_update", value=0.0 |
| 1453 | ) |
| 1454 | |
| 1455 | self._aux_params.local.append(moment) |
| 1456 | self._aux_params.local.append(moment_update) |
no outgoing calls
no test coverage detected
searching dependent graphs…