コード例 #1
0
    def _resource_apply_dense(self, grad, var, apply_state=None):
        var_device, var_dtype = var.device, var.dtype.base_dtype
        coefficients = ((apply_state or {}).get((var_device, var_dtype))
                        or self._fallback_apply_state(var_device, var_dtype))

        acc = self.get_slot(var, 'accumulator')
        return training_ops.resource_apply_adagrad_v2(
            var.handle,
            acc.handle,
            coefficients['lr_t'],
            coefficients['epsilon'],
            grad,
            use_locking=self._use_locking)
コード例 #2
0
    def _resource_apply_dense(self, grad, var, constraint, apply_state=None):
        var_device, var_dtype = var.device, var.dtype.base_dtype
        coefficients = ((apply_state or {}).get((var_device, var_dtype))
                        or self._fallback_apply_state(var_device, var_dtype))

        acc = self.get_slot(var, 'accumulator')
        var_update = training_ops.resource_apply_adagrad_v2(
            var.handle,
            acc.handle,
            coefficients['lr_t'],
            coefficients['epsilon'],
            grad,
            use_locking=self._use_locking)

        project_var, was_projected = constraint.euclidean_project(var)
        return state_ops.assign(var, project_var)
コード例 #3
0
    def _resource_apply_dense(self, grad, var, apply_state=None):
        var_device, var_dtype = var.device, var.dtype.base_dtype
        coefficients = ((apply_state or {}).get((var_device, var_dtype))
                        or self._fallback_apply_state(var_device, var_dtype))

        acc = self.get_slot(var, 'accumulator')
        if compat.forward_compatible(2019, 8, 20):
            return training_ops.resource_apply_adagrad_v2(
                var.handle,
                acc.handle,
                coefficients['lr_t'],
                coefficients['epsilon'],
                grad,
                use_locking=self._use_locking)

        acc_t = state_ops.assign_add(acc,
                                     math_ops.square(grad),
                                     use_locking=self._use_locking)
        var_update = state_ops.assign_sub(
            var, coefficients['lr_t'] * grad /
            (math_ops.sqrt(acc_t) + coefficients['epsilon']))
        return var_update