提交 4ce64a64 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!45 fix issue

Merge pull request !45 from zheng-huanhuan/master
...@@ -17,6 +17,7 @@ Noise Mechanisms. ...@@ -17,6 +17,7 @@ Noise Mechanisms.
from mindspore import Tensor from mindspore import Tensor
from mindspore.nn import Cell from mindspore.nn import Cell
from mindspore.ops import operations as P from mindspore.ops import operations as P
from mindspore.ops import functional as F
from mindspore.common.parameter import Parameter from mindspore.common.parameter import Parameter
from mindspore.common import dtype as mstype from mindspore.common import dtype as mstype
...@@ -202,7 +203,6 @@ class AdaGaussianRandom(Mechanisms): ...@@ -202,7 +203,6 @@ class AdaGaussianRandom(Mechanisms):
initial_noise_multiplier = Tensor(initial_noise_multiplier, mstype.float32) initial_noise_multiplier = Tensor(initial_noise_multiplier, mstype.float32)
self._initial_noise_multiplier = Parameter(initial_noise_multiplier, self._initial_noise_multiplier = Parameter(initial_noise_multiplier,
name='initial_noise_multiplier') name='initial_noise_multiplier')
self._stddev = P.Mul()(self._norm_bound, self._initial_noise_multiplier)
self._noise_multiplier = Parameter(initial_noise_multiplier, self._noise_multiplier = Parameter(initial_noise_multiplier,
name='noise_multiplier') name='noise_multiplier')
mean = check_param_type('mean', mean, float) mean = check_param_type('mean', mean, float)
...@@ -222,24 +222,7 @@ class AdaGaussianRandom(Mechanisms): ...@@ -222,24 +222,7 @@ class AdaGaussianRandom(Mechanisms):
self._dtype = mstype.float32 self._dtype = mstype.float32
self._normal = P.Normal(seed=seed) self._normal = P.Normal(seed=seed)
self._assign = P.Assign() self._assign = P.Assign()
self._one = Tensor(1, self._dtype)
def _update_multiplier(self):
""" Update multiplier. """
if self._decay_policy == 'Time':
temp = self._div(self._initial_noise_multiplier,
self._noise_multiplier)
temp = self._add(temp, self._noise_decay_rate)
self._noise_multiplier = self._assign(self._noise_multiplier,
self._div(self._initial_noise_multiplier, temp))
else:
one = Tensor(1, self._dtype)
temp = self._sub(one, self._noise_decay_rate)
self._noise_multiplier = self._assign(self._noise_multiplier, self._mul(temp, self._noise_multiplier))
return self._noise_multiplier
def _update_stddev(self):
self._stddev = self._assign(self._stddev, self._mul(self._noise_multiplier, self._norm_bound))
return self._stddev
def construct(self, gradients): def construct(self, gradients):
""" """
...@@ -252,9 +235,15 @@ class AdaGaussianRandom(Mechanisms): ...@@ -252,9 +235,15 @@ class AdaGaussianRandom(Mechanisms):
Tensor, generated noise with shape like given gradients. Tensor, generated noise with shape like given gradients.
""" """
shape = P.Shape()(gradients) shape = P.Shape()(gradients)
noise = self._normal(shape, self._mean, self._stddev) noise = self._normal(shape, self._mean, self._mul(self._noise_multiplier, self._norm_bound))
# pylint: disable=unused-variable
mt = self._update_multiplier() if self._decay_policy == 'Time':
# pylint: disable=unused-variable temp = self._div(self._initial_noise_multiplier,
std = self._update_stddev() self._noise_multiplier)
return noise temp = self._add(temp, self._noise_decay_rate)
multiplier = self._assign(self._noise_multiplier, self._div(self._initial_noise_multiplier, temp))
else:
temp = self._sub(self._one, self._noise_decay_rate)
multiplier = self._assign(self._noise_multiplier, self._mul(temp, self._noise_multiplier))
return F.depend(noise, multiplier)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册