Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0 API] add paddle.nn.functional.linear and fix paddle.nn.Linear #26480

Merged
merged 5 commits into from
Aug 28, 2020

Conversation

donproc
Copy link
Contributor

@donproc donproc commented Aug 20, 2020

PR types

Others

PR changes

APIs

Describe

add paddle.nn.functional.linear and fix paddle.nn.Linear

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@donproc donproc force-pushed the Linear branch 3 times, most recently from 7092ba4 to a9dc5bf Compare August 20, 2020 07:27
import numpy as np
import paddle.fluid.core as core
from op_test import OpTest
from scipy.special import expit, erf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expit, erf没用到吧?
btw: 现在有去掉scipy依赖的计划。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -686,3 +690,87 @@ def cosine_similarity(x1, x2, dim=1, eps=1e-8):
n12 = sqrt(clamp(w1 * w2, min=eps * eps))
cos_sim = w12 / n12
return cos_sim


def linear(input, weight, bias=None, name=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参数规范应该是用x。
paddle.nn.functional.linear(x,weight,bias=None,name=None)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""

:alias_main: paddle.nn.functional.linear
:alias: paddle.nn.functional.linear,paddle.nn.functional.common.linear
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alias这两行可以删掉的。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

If ``bias`` is not None, a bias will be added to the output.

Args:
input(Variable): Input tensor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable -> Tensor (下同)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


import numpy as np
import paddle
import paddle.fluid as fluid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no fluid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

weight = np.ones((2,2), dtype=np.float32)
bias = np.ones((2), dtype=np.float32)
place = fluid.CPUPlace()
with paddle.fluid.dygraph.guard(place):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用paddle.disable_static开启动态图

"""
:alias_main: paddle.nn.Linear
:alias: paddle.nn.Linear,paddle.nn.layer.Linear,paddle.nn.layer.common.Linear
:old_api: paddle.fluid.dygraph.Linear
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要这三行

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


Examples:
.. code-block:: python

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

更新一下示例代码,开启动态图的方式,和不用fluid。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@donproc donproc force-pushed the Linear branch 5 times, most recently from 36a0ba5 to 7a3944a Compare August 26, 2020 11:20
@PaddlePaddle PaddlePaddle locked as resolved and limited conversation to collaborators Aug 26, 2020
@PaddlePaddle PaddlePaddle unlocked this conversation Aug 26, 2020
@donproc
Copy link
Contributor Author

donproc commented Aug 26, 2020

@lanxianghit @jzhang533 may need your approval for api change for PR-CI-CPU-Py2, Thanks.

jzhang533
jzhang533 previously approved these changes Aug 27, 2020
Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

LielinJiang
LielinJiang previously approved these changes Aug 27, 2020
Copy link
Contributor

@LielinJiang LielinJiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG for hapi change

zhupengyang
zhupengyang previously approved these changes Aug 27, 2020
@@ -40,9 +40,8 @@ def __init__(self, num_classes=10, classifier_activation='softmax'):
if num_classes > 0:
self.fc = nn.Sequential(
nn.Linear(400, 120),
nn.Linear(120, 84),
nn.Linear(
84, 10, act=classifier_activation))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方改为softmax应该没有问题,原来默认就是softmax,调用的地方也没有修改默认值,所以我认为这里这么改没问题。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

np.testing.assert_array_almost_equal(res_f, res_nn)
np.testing.assert_array_almost_equal(res_nn, res_np)

def runTest(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个会执行到吗?单测框架应该是执行所有test开头的case。这里可以开发机上check下。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可能有些冗余,后续跟文档一起修复,谢谢。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新的commit删除了

x(Tensor): Input tensor.
weight(Tensor): Weight tensor.
bias(Tensor|None): Bias tensor, if it is set to None, no bias will be added to the output units.
name(str|None): For detailed information, please refer to :ref:`api_guide_Name`. Default: None.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • x:Input tensor, it's data type is ... 需要将输入的dtype描述加上,weight也是
  • bias(Tensor|None) -> bias(Tensor|None, optional)
  • name(str|None) -> name(str|None, optional)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文档后续单独提个PR修复

Copy link
Contributor

@Xreki Xreki Aug 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个还是先改了吧,当前CI也没跑完。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,已改。

Copy link
Contributor

@Xreki Xreki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@TCChenlong TCChenlong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Xreki Xreki merged commit edf5f31 into PaddlePaddle:develop Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants