diff --git a/doc/paddle/api/alias_api_mapping b/doc/paddle/api/alias_api_mapping index a29a76ae8f8d09c8519a84fa570b9123f0b18712..32b3da9f04c744e4ed30377df24bab706b97396f 100644 --- a/doc/paddle/api/alias_api_mapping +++ b/doc/paddle/api/alias_api_mapping @@ -203,7 +203,7 @@ paddle.nn.layer.loss.L1Loss paddle.nn.L1Loss,paddle.nn.layer.L1Loss paddle.fluid.dygraph.io.TranslatedLayer paddle.jit.TranslatedLayer paddle.nn.functional.conv.conv_transpose2d paddle.nn.functional.conv_transpose2d paddle.tensor.manipulation.split paddle.split,paddle.tensor.split -paddle.fluid.layers.tensor.create_parameter paddle.create_parameter,paddle.framework.create_parameter +paddle.fluid.layers.tensor.create_parameter paddle.static.create_parameter,paddle.framework.create_parameter paddle.nn.layer.activation.Softsign paddle.nn.Softsign paddle.nn.layer.loss.CrossEntropyLoss paddle.nn.CrossEntropyLoss,paddle.nn.layer.CrossEntropyLoss paddle.nn.layer.norm.BatchNorm3d paddle.nn.BatchNorm3d @@ -419,7 +419,7 @@ paddle.fluid.layers.iou_similarity paddle.nn.functional.iou_similarity,paddle.nn paddle.fluid.layers.transpose paddle.transpose,paddle.tensor.transpose,paddle.tensor.linalg.transpose,paddle.tensor.manipulation.transpose paddle.nn.functional.activation.elu paddle.nn.functional.elu paddle.tensor.manipulation.broadcast_to paddle.broadcast_to,paddle.tensor.broadcast_to -paddle.fluid.layers.tensor.create_global_var paddle.create_global_var,paddle.framework.create_global_var +paddle.fluid.layers.tensor.create_global_var paddle.static.create_global_var,paddle.framework.create_global_var paddle.fluid.layers.elementwise_add paddle.elementwise_add,paddle.tensor.elementwise_add,paddle.tensor.math.elementwise_add paddle.fluid.layers.affine_channel paddle.nn.functional.affine_channel,paddle.nn.functional.vision.affine_channel paddle.tensor.creation.full_like paddle.full_like,paddle.tensor.full_like diff --git a/doc/paddle/api/paddle/fluid/executor/scope_guard_cn.rst b/doc/paddle/api/paddle/fluid/executor/scope_guard_cn.rst index 9bb0538f7c3d29be7750383ffe969c64df80f126..11915aac0ad079b93b8bcded86e909496660548e 100644 --- a/doc/paddle/api/paddle/fluid/executor/scope_guard_cn.rst +++ b/doc/paddle/api/paddle/fluid/executor/scope_guard_cn.rst @@ -25,11 +25,11 @@ scope_guard .. code-block:: python - import paddle.fluid as fluid + import paddle import numpy - new_scope = fluid.Scope() - with fluid.scope_guard(new_scope): - fluid.global_scope().var("data").get_tensor().set(numpy.ones((1, 2)), fluid.CPUPlace()) + new_scope = paddle.static.Scope() + with paddle.static.scope_guard(new_scope): + paddle.static.global_scope().var("data").get_tensor().set(numpy.ones((1, 2)), paddle.CPUPlace()) data = numpy.array(new_scope.find_var("data").get_tensor()) print(data) # [[1. 1.]] diff --git a/doc/paddle/api/paddle/fluid/layers/nn/py_func_cn.rst b/doc/paddle/api/paddle/fluid/layers/nn/py_func_cn.rst index b6444f1a5735d9489932739806a67092ce34c73b..b2c06f8c3f8ab5fcfa295cb96e8fcc7a62499b8a 100644 --- a/doc/paddle/api/paddle/fluid/layers/nn/py_func_cn.rst +++ b/doc/paddle/api/paddle/fluid/layers/nn/py_func_cn.rst @@ -9,7 +9,7 @@ py_func -PaddlePaddle Fluid通过py_func在Python端注册OP。py_func的设计原理在于Paddle中的LodTensor与numpy数组可以方便的互相转换,从而可使用Python中的numpy API来自定义一个Python OP。 +PaddlePaddle 通过py_func在Python端注册OP。py_func的设计原理在于Paddle中的LodTensor与numpy数组可以方便的互相转换,从而可使用Python中的numpy API来自定义一个Python OP。 该自定义的Python OP的前向函数是 ``func``, 反向函数是 ``backward_func`` 。 Paddle将在前向部分调用 ``func`` ,并在反向部分调用 ``backward_func`` (如果 ``backward_func`` 不是None)。 ``x`` 为 ``func`` 的输入,必须为LoDTensor类型; ``out`` 为 ``func`` 的输出, 既可以是LoDTensor类型, 也可以是numpy数组。 @@ -34,7 +34,7 @@ PaddlePaddle Fluid通过py_func在Python端注册OP。py_func的设计原理在 .. code-block:: python - import paddle.fluid as fluid + import paddle import six # 自定义的前向函数,可直接输入LoDTenosor @@ -51,36 +51,38 @@ PaddlePaddle Fluid通过py_func在Python端注册OP。py_func的设计原理在 print(x) def create_tmp_var(name, dtype, shape): - return fluid.default_main_program().current_block().create_var( + return paddle.static.default_main_program().current_block().create_var( name=name, dtype=dtype, shape=shape) def simple_net(img, label): hidden = img for idx in six.moves.range(4): - hidden = fluid.layers.fc(hidden, size=200) + hidden = paddle.static.nn.fc(hidden, size=200) new_hidden = create_tmp_var(name='hidden_{}'.format(idx), dtype=hidden.dtype, shape=hidden.shape) # 用户自定义的前向反向计算 - hidden = fluid.layers.py_func(func=tanh, x=hidden, + hidden = paddle.static.nn.py_func(func=tanh, x=hidden, out=new_hidden, backward_func=tanh_grad, skip_vars_in_backward_input=hidden) # 用户自定义的调试函数,打印出输入的LodTensor - fluid.layers.py_func(func=debug_func, x=hidden, out=None) + paddle.static.nn.py_func(func=debug_func, x=hidden, out=None) - prediction = fluid.layers.fc(hidden, size=10, act='softmax') - loss = fluid.layers.cross_entropy(input=prediction, label=label) - return fluid.layers.mean(loss) + prediction = paddle.static.nn.fc(hidden, size=10, act='softmax') + loss = paddle.static.nn.cross_entropy(input=prediction, label=label) + return paddle.mean(loss) **示例代码2**: .. code-block:: python # 该示例展示了如何将LoDTensor转化为numpy数组,并利用numpy API来自定义一个OP - import paddle.fluid as fluid + import paddle import numpy as np + paddle.enable_static() + def element_wise_add(x, y): # 必须先手动将LodTensor转换为numpy数组,否则无法支持numpy的shape操作 x = np.array(x) @@ -97,24 +99,24 @@ PaddlePaddle Fluid通过py_func在Python端注册OP。py_func的设计原理在 return result def create_tmp_var(name, dtype, shape): - return fluid.default_main_program().current_block().create_var( + return paddle.static.default_main_program().current_block().create_var( name=name, dtype=dtype, shape=shape) def py_func_demo(): - start_program = fluid.default_startup_program() - main_program = fluid.default_main_program() + start_program = paddle.static.default_startup_program() + main_program = paddle.static.default_main_program() # 创建前向函数的输入变量 - x = fluid.data(name='x', shape=[2,3], dtype='int32') - y = fluid.data(name='y', shape=[2,3], dtype='int32') + x = paddle.data(name='x', shape=[2,3], dtype='int32') + y = paddle.data(name='y', shape=[2,3], dtype='int32') # 创建前向函数的输出变量,必须指明变量名称name/数据类型dtype/维度shape output = create_tmp_var('output','int32', [3,1]) # 输入多个LodTensor以list[Variable]或tuple(Variable)形式 - fluid.layers.py_func(func=element_wise_add, x=[x,y], out=output) + paddle.static.nn.py_func(func=element_wise_add, x=[x,y], out=output) - exe=fluid.Executor(fluid.CPUPlace()) + exe=paddle.static.Executor(fluid.CPUPlace()) exe.run(start_program) # 给program喂入numpy数组 diff --git a/doc/paddle/api/paddle/fluid/layers/tensor/create_global_var_cn.rst b/doc/paddle/api/paddle/fluid/layers/tensor/create_global_var_cn.rst index 97034b6dc1c6bc60e8be576cb2332deb1f1d77f7..c16fea6cb264026a24bc591c1001253c09a42f42 100644 --- a/doc/paddle/api/paddle/fluid/layers/tensor/create_global_var_cn.rst +++ b/doc/paddle/api/paddle/fluid/layers/tensor/create_global_var_cn.rst @@ -26,9 +26,8 @@ create_global_var .. code-block:: python - import paddle.fluid as fluid - import paddle.fluid.layers as layers - var = layers.create_global_var(shape=[2,3], value=1.0, dtype='float32', + import paddle + var = paddle.static.create_global_var(shape=[2,3], value=1.0, dtype='float32', persistable=True, force_cpu=True, name='new_var') diff --git a/doc/paddle/api/paddle/fluid/layers/tensor/create_parameter_cn.rst b/doc/paddle/api/paddle/fluid/layers/tensor/create_parameter_cn.rst index 3206e5292d3bf4f0150fb8c9ce96243e4d779c6e..f639cd0e4ea36c839115fe974e6ca033ecebf0fe 100644 --- a/doc/paddle/api/paddle/fluid/layers/tensor/create_parameter_cn.rst +++ b/doc/paddle/api/paddle/fluid/layers/tensor/create_parameter_cn.rst @@ -29,9 +29,8 @@ create_parameter .. code-block:: python - import paddle.fluid as fluid - import paddle.fluid.layers as layers - W = layers.create_parameter(shape=[784, 200], dtype='float32') + import paddle + W = paddle.static.create_parameter(shape=[784, 200], dtype='float32') diff --git a/doc/paddle/api/paddle/fluid/param_attr/ParamAttr_cn.rst b/doc/paddle/api/paddle/fluid/param_attr/ParamAttr_cn.rst index 641ed94ab2d0b52e9ef2de4cdd783f61e5df672f..212901778666f0368c5811af76d83f2b10a816cf 100644 --- a/doc/paddle/api/paddle/fluid/param_attr/ParamAttr_cn.rst +++ b/doc/paddle/api/paddle/fluid/param_attr/ParamAttr_cn.rst @@ -34,14 +34,15 @@ ParamAttr .. code-block:: python - import paddle.fluid as fluid + import paddle - w_param_attrs = fluid.ParamAttr(name="fc_weight", - learning_rate=0.5, - regularizer=fluid.regularizer.L2Decay(1.0), - trainable=True) + w_param_attrs = paddle.ParamAttr(name="fc_weight", + learning_rate=0.5, + regularizer=fluid.regularizer.L2Decay(1.0), + trainable=True) print(w_param_attrs.name) # "fc_weight" - x = fluid.layers.data(name='X', shape=[1], dtype='float32') - y_predict = fluid.layers.fc(input=x, size=10, param_attr=w_param_attrs) + paddle.enable_static() + x = paddle.data(name='X', shape=[1], dtype='float32') + y_predict = paddle.static.nn.fc(input=x, size=10, param_attr=w_param_attrs)