-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[2.0 API] add paddle.nn.functional.linear and fix paddle.nn.Linear #26480
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
Conversation
Thanks for your contribution! |
7092ba4
to
a9dc5bf
Compare
import numpy as np | ||
import paddle.fluid.core as core | ||
from op_test import OpTest | ||
from scipy.special import expit, erf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expit, erf没用到吧?
btw: 现在有去掉scipy依赖的计划。
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alias这两行可以删掉的。
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable -> Tensor (下同)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no fluid
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用paddle.disable_static开启动态图
python/paddle/nn/layer/common.py
Outdated
""" | ||
:alias_main: paddle.nn.Linear | ||
:alias: paddle.nn.Linear,paddle.nn.layer.Linear,paddle.nn.layer.common.Linear | ||
:old_api: paddle.fluid.dygraph.Linear |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要这三行
There was a problem hiding this comment.
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
更新一下示例代码,开启动态图的方式,和不用fluid。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
36a0ba5
to
7a3944a
Compare
@lanxianghit @jzhang533 may need your approval for api change for PR-CI-CPU-Py2, Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this 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
@@ -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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方改为softmax应该没有问题,原来默认就是softmax,调用的地方也没有修改默认值,所以我认为这里这么改没问题。
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个会执行到吗?单测框架应该是执行所有test开头的case。这里可以开发机上check下。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可能有些冗余,后续跟文档一起修复,谢谢。
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文档后续单独提个PR修复
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个还是先改了吧,当前CI也没跑完。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok,已改。
e12eebc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
Others
PR changes
APIs
Describe
add paddle.nn.functional.linear and fix paddle.nn.Linear