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

Remove reduntant numpy input in Example code (test=document_fix) #47555

Merged
merged 2 commits into from
Nov 3, 2022

Conversation

kevinng77
Copy link
Contributor

@kevinng77 kevinng77 commented Nov 1, 2022

PR types

Others

PR changes

Docs

Describe

本次 PR 针对所有 paddle api 文档中出现的以下问题,进行了统一处理:

  • 示例代码中存在 x = np.functions + paddle.to_tensor(x) 的方式创建函数输入, 如:
         # python/paddle/nn/functional/conv.py
          import numpy as np
          x = np.array([[[4, 8, 1, 9],
            [7, 2, 0, 9],
            [6, 9, 2, 6]]]).astype(np.float32)
          x_var = paddle.to_tensor(x)

处理方式为移除 numpy 输入,统一采用 Paddle API,对于不同 Numpy 方法构建的输入,其对应的修改方式如下:

原 Numpy API 改为 Paddle API
np.random.uniform paddle.uniform
np.arange paddle.arange
np.random.randint paddle.randint
np.random.rand, np.random.random paddle.rand
np.array -

特殊情况 1

对于以下 Paddle API:

Conv1D, Conv1DTranspose, Dropout, Embedding, cond, cholesky, conv1d, conv1d_transpose, softmax_with_cross_entropy, sparse_attention

除了修改 numpy 问题外,也对示例代码样式做了微小调整,包括以备注方式添加(或修改)输出结果, 将 np.random 随机输入改为了自定义的固定输入等。

特殊情况 2

对于以下 Paddle API,由于特殊原因并未修改对应的 Numpy 问题:

  • Paddle/python/paddle/distributed/fleet/recompute/recompute.py line 385:跑不通示例代码,不确定是否是单 GPU 环境的问题。
  • Paddle/python/paddle/distributed/utils/moe_utils.py line 20,150:同上
  • Paddle/python/paddle/sparse/nn/functional/activation.py line 61:原示例代码报错:未找到 paddle.sparse
  • Paddle/python/paddle/sparse/nn/layer/activation.py line 60:原示例代码报错:未找到 paddle.sparse
  • Paddle/python/paddle/fft.py:未找到 np.mgrid 等方法对应的 Paddle API。
  • Paddle/python/paddle/fluid 下所有 Paddle API

@paddle-bot
Copy link

paddle-bot bot commented Nov 1, 2022

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added contributor External developers status: proposed labels Nov 1, 2022
@kevinng77 kevinng77 force-pushed the fix_doc_numpy_input branch 3 times, most recently from f3c7004 to bf29f25 Compare November 2, 2022 02:06
@kevinng77 kevinng77 force-pushed the fix_doc_numpy_input branch from bf29f25 to 08b2d10 Compare November 2, 2022 10:33
Ligoml
Ligoml previously approved these changes Nov 2, 2022
Copy link
Contributor

@Ligoml Ligoml left a comment

Choose a reason for hiding this comment

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

good job!
LGTM

@kevinng77 kevinng77 changed the title Remove reduntant numpy input in Example code Remove reduntant numpy input in Example code (test=document_fix) Nov 2, 2022
@kevinng77
Copy link
Contributor Author

由于第一次 commit 的 PR-CI-Coverage 没有通过,所以额外添加了一次 commit,顺便补充了一个漏网之鱼 python/paddle/nn/layer/common.py 。(该示例代码中采用 import numpy 而非 import numpy as np,所以在第一批 commit 中没有检测到 = =... )

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

@Ligoml Ligoml merged commit a276130 into PaddlePaddle:develop Nov 3, 2022
jzhang533 pushed a commit that referenced this pull request Nov 7, 2022
* #46765

* #47042

* Remove redundant numpy import (#47483)

* #47555

* resolve conflict

* resolve conflict

* resolve conflict

* resolve conflict

* resolve conflict

* for_codestyle

* fix sample code paddle.linalg.multi_dot

Co-authored-by: Kevin吴嘉文 <417333277@qq.com>
@kevinng77 kevinng77 deleted the fix_doc_numpy_input branch November 11, 2022 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants