modify doc for paddle.nn.Layer#27624
modify doc for paddle.nn.Layer#27624phlrain merged 10 commits intoPaddlePaddle:developfrom wanghuancoder:develop_Layer_doc
Conversation
|
Thanks for your contribution! |
|
|
||
| class Layer(core.Layer): | ||
| """ | ||
| :alias_main: paddle.nn.Layer |
There was a problem hiding this comment.
这个是2.0API文档中要求的。说会有自动生成工具。这里让删掉。
| print(layer_list) | ||
| layer_list = list(model.children()) | ||
|
|
||
| print(layer_list) |
| model = fluid.dygraph.Sequential(fc1, fc2) | ||
|
|
||
| layer_list = list(model.children()) | ||
| fc1 = paddle.nn.Linear(10, 3) |
There was a problem hiding this comment.
变量名称最好叫 linear1 毕竟后面的类名是Linear
| 'alpha': 1, | ||
| } | ||
| tmp = self.create_variable(name = "linear_tmp_0", dtype=self._dtype) | ||
| paddle.fluid.default_main_program().current_block().append_op( |
There was a problem hiding this comment.
示例中不要使用append op,对于普通用户来说,他们不需要了解这种用法
| self.weight = self.create_parameter( | ||
| shape=[in_features, out_features], | ||
| is_bias=False) | ||
| self.bias = self.create_parameter( |
There was a problem hiding this comment.
forward中没有使用 bias,bias 可以不写
|
|
||
| Example:: | ||
| .. code-block:: python | ||
|
|
There was a problem hiding this comment.
这个train 可以和下面的eval用同样的MyLayer
| inputs = {'X': [input], 'Y': [self.weight]} | ||
| attrs = { | ||
| 'transpose_X': False, | ||
| 'transpose_Y': False, |
There was a problem hiding this comment.
这个forward里面可以直接写 paddle.matmul( input, self.self.weight), 不用append op
|
|
||
| import paddle | ||
|
|
||
| linear = paddle.nn.Linear(1, 1) |
There was a problem hiding this comment.
这个 add_parameter 建议卸载一个class里面,不建议直接放在class 外面用
| state_dict = emb.state_dict() | ||
| fluid.save_dygraph( state_dict, "paddle_dy") | ||
| state_dict = emb.state_dict() | ||
| paddle.save( state_dict, "paddle_dy") |
There was a problem hiding this comment.
"paddle_dy" 建议改成 "paddle_dy.pdparams"
| def forward(self, input): | ||
| return self._linear(input) | ||
|
|
||
| x = paddle.randn([10, 1], 'float32') |
| If set str, it can be "bool", "float16", "float32", "float64", | ||
| "int8", "int16", "int32", "int64", "uint8" or "uint16". | ||
| Default: ``core.VarDesc.VarType.FP32`` | ||
| Default: "float32" |
There was a problem hiding this comment.
73 行,不需要暴露core.VarDesc.Vartype给用户。
|
|
||
| paddle.disable_static() | ||
|
|
||
|
|
|
|
||
| Returns: | ||
| :ref:`api_guide_Variable_en` : created parameter. | ||
|
|
There was a problem hiding this comment.
- 353行::ref:
api_fluid_ParamAttr现在是:ref:api_paddle_ParamAttr - 354行: core.VarDesc.VarType 不需要暴露, str写了两次
- 359行::ref:
api_fluid_initializer_XavierInitializerand :ref:api_fluid_initializer_ConstantInitializer更新成paddle.nn.initializer下的API
| @@ -326,11 +402,32 @@ def create_variable(self, | |||
| dtype(str or core.VarDesc.VarType, optional): data type of this parameter. | |||
There was a problem hiding this comment.
- core.VarDesc.VarType不暴露给用户
| "int8", "int16", "int32", "int64", "uint8" or "uint16". | ||
| If set None, it will be ``core.VarDesc.VarType.FP32``. Default: None | ||
| If set None, it will be "float32". Default: None | ||
| type(core.VarDesc.VarType, optional): type of the variable. No need to set this parameter. Default: ``core.VarDesc.VarType.LOD_TENSOR`` |
There was a problem hiding this comment.
这个参数可以直接从参数列表中去掉吧?
2.0里暂时没有LODTensor
There was a problem hiding this comment.
done.和红雨商议后,将接口部分的改参数做了删除
| @@ -349,6 +446,15 @@ def parameters(self, include_sublayers=True): | |||
|
|
|||
| Returns: | |||
| list of :ref:`api_guide_Variable_en` : a list of Parameters. | |||
There was a problem hiding this comment.
list of :ref:api_guide_Variable_en :
这个建议先删掉。
|
|
||
| import numpy as np | ||
| import paddle.fluid as fluid | ||
| import paddle |
There was a problem hiding this comment.
641行,应该是non-trainable parameters?
There was a problem hiding this comment.
done。同时将所有Variable改成Tensor
| @@ -585,6 +708,20 @@ def buffers(self, include_sublayers=True): | |||
|
|
|||
| Returns: | |||
| list of :ref:`api_guide_Variable_en` : a list of buffers. | |||
There was a problem hiding this comment.
list of :ref:api_guide_Variable_en : 建议去掉
|
|
||
| import numpy as np | ||
| import paddle.fluid as fluid | ||
| import paddle |
There was a problem hiding this comment.
named_buffer这个API文档里的variable,应该称为tensor 还是 buffer?variable有些不合适。
There was a problem hiding this comment.
done。已将所有Variable改成Tensor
| parameters=linear.parameters()) | ||
| out = linear(a) | ||
| out.backward() | ||
| adam.minimize(out) |
c80b84a
| if type(layer) == nn.Linear: | ||
| print('before init weight:', layer.weight.numpy()) | ||
| new_weight = paddle.fill_constant(layer.weight.shape, layer.weight.dtype, value=0.9) | ||
| new_weight = paddle.fill(layer.weight.shape, layer.weight.dtype, value=0.9) |
There was a problem hiding this comment.
paddle里只有paddle.full没有paddle.fill
| is_bias(bool, optional): if this is a bias parameter. Default: False. | ||
| default_initializer(Initializer, optional): the default initializer for this parameter. | ||
| If set None, default initializer will be set to :ref:`api_fluid_initializer_XavierInitializer` and :ref:`api_fluid_initializer_ConstantInitializer` | ||
| If set None, default initializer will be set to :ref:`_api_paddle_fluid_initializer_Xavier` and :ref:`_api_paddle_fluid_initializer_Constant` |
There was a problem hiding this comment.
经沟通,暂时使用
paddle.nn.initializer.Constant
paddle.nn.initializer.Xavier
PR types
Others
PR changes
Docs
Describe
根据2.0API要求,修改paddle.nn.Layer代码示例
为没有代码示例的函数添加代码示例。forward、backward无实际意义,没有添加代码示例
将构造函数中dtype的默认值改成”float32“
预览图:
