Example #1
0
 def __init__(self, params, accum=0.1, learning_rate=0.001, l1=0.0, l2=0.0,
              use_locking=False, loss_scale=1.0, weight_decay=0.0):
     super(ProximalAdagrad, self).__init__(learning_rate, params, weight_decay, loss_scale)
     _check_param_value(accum, l1, l2, use_locking, self.cls_name)
     self.accum = self.parameters.clone(prefix="accum", init=accum)
     self.l1 = Tensor(l1, mstype.float32)
     self.l2 = Tensor(l2, mstype.float32)
     self.hyper_map = C.HyperMap()
     self.opt = P.ApplyProximalAdagrad(use_locking=use_locking)
     self.sparse_opt = P.FusedSparseProximalAdagrad(use_locking=use_locking)
 def __init__(self):
     super(Net, self).__init__()
     self.fused_sparse_proximal_adagrad = P.FusedSparseProximalAdagrad()
     self.var = Parameter(Tensor(np.ones([3, 3]).astype(np.float32)),
                          name="var")
     self.accum = Parameter(Tensor(np.ones([3, 3]).astype(np.float32)),
                            name="accum")
     self.lr = 0.01
     self.l1 = 0.0
     self.l2 = 0.0
Example #3
0
    def target(self, value):
        """If the input value is set to "CPU", the parameters will be updated on the host using the Fused
           optimizer operation."""
        if not isinstance(value, str):
            raise TypeError("The value must be str type, but got value type is {}".format(type(value)))

        if value not in ('CPU', 'Ascend', 'GPU'):
            raise ValueError("The value must be 'CPU', 'Ascend' or 'GPU', but got value {}".format(value))

        if value == 'CPU':
            self.sparse_opt = P.FusedSparseProximalAdagrad(self.use_locking).add_prim_attr("primitive_target", "CPU")
        else:
            self.sparse_opt = P.SparseApplyProximalAdagrad(self.use_locking)

        self._target = value
Example #4
0
 def __init__(self, var, accum):
     super(FusedSparseProximalAdagradNet, self).__init__()
     self.fused_sparse_proximal_adagrad = P.FusedSparseProximalAdagrad()
     self.var = Parameter(var, name="var")
     self.accum = Parameter(accum, name="accum")