diff --git a/python/paddle/fluid/initializer.py b/python/paddle/fluid/initializer.py index 215f6a5330d25e210ff38e0a5a915b707f0ce825..26ed67f6e8ca25d51b37fdb5c85eb8033c642390 100644 --- a/python/paddle/fluid/initializer.py +++ b/python/paddle/fluid/initializer.py @@ -817,12 +817,14 @@ class MSRAInitializer(Initializer): if self._uniform: gain = calculate_gain(self._nonlinearity, self._negative_slope) limit = gain * math.sqrt(3.0 / float(fan_in)) - - out_var = _legacy_C_ops.uniform_random('shape', out_var.shape, - 'min', -limit, 'max', - limit, 'seed', - self._seed, 'dtype', - int(out_dtype)) + if in_dygraph_mode(): + out_var = _C_ops.uniform_random(var.shape, out_dtype, + -limit, limit, self._seed, + _current_expected_place()) + else: + out_var = _legacy_C_ops.uniform_random( + 'shape', out_var.shape, 'min', -limit, 'max', limit, + 'seed', self._seed, 'dtype', int(out_dtype)) else: gain = calculate_gain(self._nonlinearity, self._negative_slope) std = gain / math.sqrt(float(fan_in))