def func(self, place): # the shape of input variable should be clearly specified, not inlcude -1. shape = [2, 3, 4, 5] eps = 0.005 dtype = np.float64 x = layers.data('x', shape, False, dtype) y = layers.data('y', shape, False, dtype) x.persistable = True y.persistable = True out = layers.elementwise_mul(x, y) x_arr = np.random.uniform(-1, 1, shape).astype(dtype) y_arr = np.random.uniform(-1, 1, shape).astype(dtype) gradient_checker.triple_grad_check([x, y], out, x_init=[x_arr, y_arr], place=place, eps=eps) fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": True}) gradient_checker.triple_grad_check_for_dygraph(self.multiply_wrapper, [x, y], out, x_init=[x_arr, y_arr], place=place) fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": False})
def func(self, place): shape = [2, 3, 7, 9] eps = 0.0005 dtype = np.float64 x = layers.data('x', shape, False, dtype=dtype) x.persistable = True y = layers.sigmoid(x) x_arr = np.random.random(shape).astype(dtype) x_arr[np.abs(x_arr) < 0.005] = 0.002 gradient_checker.triple_grad_check( [x], y, x_init=x_arr, place=place, eps=eps)
def func(self, place): shape = [2, 3, 7, 9] eps = 0.0005 dtype = np.float64 x = layers.data('x', shape, False, dtype=dtype) x.persistable = True y = layers.tanh(x) x_arr = np.random.random(shape).astype(dtype) x_arr[np.abs(x_arr) < 0.005] = 0.002 gradient_checker.triple_grad_check( [x], y, x_init=x_arr, place=place, eps=eps) fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": True}) gradient_checker.triple_grad_check_for_dygraph( self.tanh_wrapper, [x], y, x_init=x_arr, place=place) fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": False})
def func(self, place): # the shape of input variable should be clearly specified, not inlcude -1. shape = [2, 3, 4, 5] eps = 0.005 dtype = np.float64 x = layers.data('x', shape, False, dtype) y = layers.data('y', shape[:-1], False, dtype) x.persistable = True y.persistable = True out = layers.elementwise_add(x, y, axis=0) x_arr = np.random.uniform(-1, 1, shape).astype(dtype) y_arr = np.random.uniform(-1, 1, shape[:-1]).astype(dtype) gradient_checker.triple_grad_check([x, y], out, x_init=[x_arr, y_arr], place=place, eps=eps)
def func(self, place): eps = 0.005 dtype = np.float64 typename = "float64" x = paddle.static.create_parameter(dtype=typename, shape=self.x_shape, name='x') y = paddle.static.create_parameter(dtype=typename, shape=self.y_shape, name='y') out = paddle.matmul(x, y, self.transpose_x, self.transpose_y, name='out') np.random.seed(2021) x_arr = np.random.uniform(-1, 1, self.x_shape).astype(dtype) y_arr = np.random.uniform(-1, 1, self.y_shape).astype(dtype) gradient_checker.triple_grad_check([x, y], out, x_init=[x_arr, y_arr], place=place, eps=eps)