Пример #1
0
    def __init__(self,
                 params,
                 initial_accum=0.1,
                 learning_rate=0.001,
                 lr_power=-0.5,
                 l1=0.0,
                 l2=0.0,
                 use_locking=False,
                 loss_scale=1.0,
                 weight_decay=0.0):
        super(FTRL, self).__init__(learning_rate, params)

        _check_param(initial_accum, learning_rate, lr_power, l1, l2,
                     use_locking, loss_scale, weight_decay, self.cls_name)
        self.moments = self.parameters.clone(prefix="moments",
                                             init=initial_accum)
        self.linear = self.parameters.clone(prefix="linear", init='zeros')
        self.l1 = l1
        self.l2 = l2
        self.lr_power = lr_power
        self.reciprocal_scale = 1.0 / loss_scale
        self.weight_decay = weight_decay
        self.decay_tf = tuple((lambda: True)() for x in self.parameters)
        self.hyper_map = C.HyperMap()
        self.opt = P.ApplyFtrl(use_locking=use_locking)
        self.one = Tensor(1, mstype.int32)
Пример #2
0
 def __init__(self,
              params,
              initial_accum=0.1,
              learning_rate=0.001,
              lr_power=-0.5,
              l1=0.0,
              l2=0.0,
              use_locking=False,
              loss_scale=1.0,
              weight_decay=0.0):
     super(FTRL, self).__init__(learning_rate,
                                params,
                                loss_scale=loss_scale)
     if self.is_group:
         raise RuntimeError(
             f"The {self.cls_name} optimizer cannot support group setting.")
     _check_param(initial_accum, lr_power, l1, l2, use_locking,
                  weight_decay, self.cls_name)
     self.moments = self.parameters.clone(prefix="moments",
                                          init=initial_accum)
     self.linear = self.parameters.clone(prefix="linear", init='zeros')
     self.l1 = l1
     self.l2 = l2
     self.lr_power = lr_power
     self.weight_decay = weight_decay
     self.decay_tf = tuple((lambda: True)() for x in self.parameters)
     self.hyper_map = C.HyperMap()
     self.opt = P.ApplyFtrl(use_locking=use_locking)
     self.sparse_opt = P.SparseApplyFtrl(learning_rate,
                                         l1,
                                         l2,
                                         lr_power,
                                         use_locking=use_locking)
Пример #3
0
 def __init__(self, params, initial_accum=0.1, learning_rate=0.001, lr_power=-0.5, l1=0.0, l2=0.0,
              use_locking=False, loss_scale=1.0, weight_decay=0.0):
     super(FTRL, self).__init__(learning_rate, params, weight_decay, loss_scale=loss_scale)
     if self.dynamic_lr or self.is_group_lr:
         raise ValueError('Dynamic learning rate or group learning rate is currently not supported.')
     _check_param(initial_accum, lr_power, l1, l2, use_locking, self.cls_name)
     self.moments = self.parameters.clone(prefix="moments", init=initial_accum)
     self.linear = self.parameters.clone(prefix="linear", init='zeros')
     self.l1 = l1
     self.l2 = l2
     self.lr = learning_rate
     self.lr_power = lr_power
     if not self.is_group:
         self.decay_flags = tuple((lambda: True)() for x in self.parameters)
     self.hyper_map = C.HyperMap()
     self.opt = P.ApplyFtrl(use_locking=use_locking)
     self.use_locking = use_locking
     self.sparse_opt = P.SparseApplyFtrl(learning_rate, l1, l2, lr_power, use_locking=use_locking)
     self._ps_pull = P.Pull()
     self._ps_push = P.Push("Ftrl", [0, 1, 2])
     self._ps_push.add_prim_attr("init_accum", initial_accum)
     self._ps_push.add_prim_attr("lr", learning_rate)
     self._ps_push.add_prim_attr("l1", l1)
     self._ps_push.add_prim_attr("l2", l2)
     self._ps_push.add_prim_attr("lr_power", lr_power)
Пример #4
0
 def __init__(self):
     super(ApplyFtrlNet, self).__init__()
     self.apply_ftrl = P.ApplyFtrl()
     self.lr = 0.001
     self.l1 = 0.0
     self.l2 = 0.0
     self.lr_power = -0.5
     self.var = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="var")
     self.accum = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="accum")
     self.linear = Parameter(Tensor(np.random.rand(3, 3).astype(np.float32)), name="linear")
Пример #5
0
     'block': P.ReduceProd(),
     'desc_const': [0],
     'desc_inputs': [[3, 2]],
     'desc_bprop': [[2]]}),
 ('ReduceProd_1', {
     'block': P.ReduceProd(keep_dims=True),
     'desc_const': [0],
     'desc_inputs': [[3, 2]],
     'desc_bprop': [[1, 2]]}),
 ('CumProd', {
     'block': P.CumProd(),
     'desc_const': [0],
     'desc_inputs': [[3, 2]],
     'desc_bprop': [[3, 2]]}),
 ('ApplyFtrl', {
     'block': P.ApplyFtrl(),
     'desc_const': [0.001, 0.0, 0.0, -0.5],
     'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3]],
     'desc_bprop': [3, 3],
     'skip': ['backward']}),
 ('ApplyRMSProp', {
     'block': P.ApplyRMSProp(),
     'desc_const': [0.9, 0.0, 1e-10, 0.001],
     'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3]],
     'desc_bprop': [3, 3],
     'skip': ['backward']}),
 ('ApplyCenteredRMSProp', {
     'block': P.ApplyCenteredRMSProp(),
     'desc_const': [0.9, 0.0, 1e-10, 0.001],
     'desc_inputs': [[3, 3], [3, 3], [3, 3], [3, 3], [3, 3]],
     'desc_bprop': [3, 3],
Пример #6
0
 def __init__(self, var, accum, linear):
     super(ApplyFtrlNet, self).__init__()
     self.apply_ftrl = P.ApplyFtrl()
     self.var = Parameter(var, name="var")
     self.accum = Parameter(accum, name="accum")
     self.linear = Parameter(linear, name="linear")