From 1a372bd1a1987c62076dbb77e59d75827c4189ee Mon Sep 17 00:00:00 2001 From: Weilong Wu Date: Wed, 7 Sep 2022 10:40:11 +0800 Subject: [PATCH] [Eager, Performance optimization] polish uniform_random (#45807) --- python/paddle/fluid/initializer.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/initializer.py b/python/paddle/fluid/initializer.py index 215f6a5330d..26ed67f6e8c 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)) -- GitLab