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

[xdoctest] reformat example code with google style in No. 250-260 #56541

Merged
merged 15 commits into from
Sep 6, 2023

Conversation

enkilee
Copy link
Contributor

@enkilee enkilee commented Aug 22, 2023

PR types

Others

PR changes

Others

Description

250 | 1364 | python/paddle/incubate/distributed/fleet/parameter_server/pslib/init.py | @enkilee |  
251 | 233 | python/paddle/incubate/distributed/models/moe/grad_clip.py | @enkilee |  
252 | 500 | python/paddle/incubate/distributed/models/moe/moe_layer.py | @enkilee |  
253 | 1659 | python/paddle/incubate/layers/nn.py | @enkilee |  
254 | 3599 | python/paddle/tensor/linalg.py | @enkilee |  
255 | 1150 | python/paddle/tensor/logic.py | @enkilee |  
256 | 116 | python/paddle/incubate/nn/functional/fused_dropout_add.py | @enkilee |  
257 | 75 | python/paddle/incubate/nn/functional/fused_ec_moe.py | @enkilee |  
258 | 166 | python/paddle/incubate/nn/functional/fused_gate_attention.py | @enkilee |  
259 | 161 | python/paddle/incubate/nn/functional/fused_matmul_bias.py | @enkilee |  
260 | 49 | python/paddle/incubate/nn/functional/fused_rotary_position_embedding.py | @enkilee


预览:

en: http://preview-paddle-pr-56541.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/en/api/paddle/abs_en.html
zh: http://preview-paddle-pr-56541.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/abs_cn.html

关联 PR:
#55629
#55295

@sunzhongkai588 @SigureMo @megemini

@paddle-bot
Copy link

paddle-bot bot commented Aug 22, 2023

你的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 Aug 22, 2023
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Aug 22, 2023
@SigureMo
Copy link
Member

以后这种有特别大的文件注意拆成不同的 PR,比如这里的 Tensor 相关就不合适和分布式放在一起,较小的 PR 一般零碎时间就可以 review 了,这种大 PR 可能必须要找完整的时间(可能至少半小时)才能 review

PR 拆分也要合适,不是说每个文件一个 PR,这种需要自行根据「量」进行判断

@enkilee
Copy link
Contributor Author

enkilee commented Aug 23, 2023

收到

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

还有俩 tensor 的没看……

以后非必要这个任务不要改非示例代码部分了,typo 可以改,改参数、格式什么的,review 难度瞬间增大几十倍

@enkilee
Copy link
Contributor Author

enkilee commented Aug 24, 2023

好的,主要是改示例代码时看到参数和单词那些错的,就一起改了。。

Copy link
Contributor

@megemini megemini left a comment

Choose a reason for hiding this comment

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

pslib 用 .. code-block:: text 应该没啥问题 ~ 解析时候是匹配 python ~

fluid 的一些接口有点问题 ~

python/paddle/incubate/distributed/models/moe/grad_clip.py Outdated Show resolved Hide resolved
python/paddle/incubate/layers/nn.py Outdated Show resolved Hide resolved
Comment on lines 1341 to 1398
.. code-block:: python

>>> # doctest: +REQUIRES(env:GPU)
>>> import paddle
>>> paddle.enable_static()

>>> def build_program(main_program, startup_program):
... with paddle.program_guard(main_program, startup_program):
... x = paddle.static.data(name='x', shape=[-1, 1, 28, 28], dtype='float32')
... y = paddle.static.data(name="y", shape=[-1, 1], dtype='int64')
... conv1_1 = paddle.static.nn.conv2d(
... input=x,
... filter_size=3,
... num_filters=32,
... stride=1,
... padding=1,
... act=None,
... bias_attr=False,
... data_format='NHWC')
... conv1_2 = paddle.static.nn.conv2d(
... input=x,
... filter_size=3,
... num_filters=32,
... stride=1,
... padding=1,
... act=None,
... bias_attr=False,
... data_format='NHWC')
... bn = paddle.static.nn.batch_norm(
... input=conv1_1,
... act=None,
... data_layout='NHWC')
... fused_bn_add_act = paddle.incubate.layers.fused_bn_add_act(conv1_2, bn)
... prediction = paddle.static.nn.fc(x=fused_bn_add_act, size=10, activation='softmax')
... loss = paddle.nn.functional.cross_entropy(
... input=prediction, label=y,
... reduction='none', use_softmax=False
... )
... loss = paddle.mean(loss)
... sgd = paddle.optimizer.SGD(learning_rate=0.001)
... sgd = paddle.static.amp.decorate(
... sgd, use_dynamic_loss_scaling=True, init_loss_scaling=128.0)
... sgd.minimize(loss)
...
... return x, y, loss

>>> iters = 5
>>> batch_size = 16
>>> support_gpu = paddle.is_compiled_with_cuda()
>>> if support_gpu:
... main_program = paddle.Program()
... startup_program = paddle.Program()
... place = paddle.CUDAPlace(0)
... x, y, loss = build_program(main_program, startup_program)
...
... feeder = paddle.DataFeeder(feed_list=[x, y], place=place)
... train_reader = paddle.batch(
... paddle.dataset.mnist.train(), batch_size=batch_size)
Copy link
Contributor

Choose a reason for hiding this comment

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

这一段里面 fluid 相关的修改有点问题 ~

比如

  • paddle.Program -> paddle.static.Program
  • paddle.DataFeeder
  • paddle.program_guard

python/paddle/incubate/layers/nn.py Show resolved Hide resolved
python/paddle/incubate/layers/nn.py Outdated Show resolved Hide resolved
python/paddle/incubate/nn/functional/fused_matmul_bias.py Outdated Show resolved Hide resolved
python/paddle/incubate/nn/functional/fused_matmul_bias.py Outdated Show resolved Hide resolved
python/paddle/incubate/nn/functional/fused_matmul_bias.py Outdated Show resolved Hide resolved
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

每看一次都想说一次,以后千万不要改示例代码以外的东西……

python/paddle/tensor/linalg.py Outdated Show resolved Hide resolved
python/paddle/tensor/linalg.py Outdated Show resolved Hide resolved
python/paddle/tensor/linalg.py Outdated Show resolved Hide resolved
@luotao1
Copy link
Contributor

luotao1 commented Aug 31, 2023

需要解决下冲突

@enkilee
Copy link
Contributor Author

enkilee commented Aug 31, 2023

每看一次都想说一次,以后千万不要改示例代码以外的东西……

我错了。。。 以后不会出现这种情况了

@SigureMo
Copy link
Member

SigureMo commented Sep 1, 2023

又冲突了

@SigureMo
Copy link
Member

SigureMo commented Sep 1, 2023

image

@megemini 话说现在这种空的是正常的么,我看代码里好像是会在下面输出 CPU 和 GPU 各自的信息:

summary_check_problems $[${example_code_gpu} + ${example_code}] "${example_info_gpu}\n${example_info}"

现在好像是 CPU 和 GPU 其中一个失败了,但是报错信息不是很明显

@megemini
Copy link
Contributor

megemini commented Sep 1, 2023

现在好像是 CPU 和 GPU 其中一个失败了,但是报错信息不是很明显

确实是!日志前面翻一下,是 GPU 环境运行出错了 ~

不过,具体要怎么改,我这边吃不准。

  • 目前 PR-CI-Static-Check 是调用 paddle_build.sh 脚本,运行 exec_samplecode_test 来进行检查。
  • exec_samplecode_test 在多个命令里面被调用,具体怎么调用的,CI 流水线里面的配置我也不清楚 ~
  • 这里面 build_and_check build_and_check_cpu build_and_check_gpu 用了 set +e,导致前面出错也不会退出。

个人感觉 paddle_build.sh 里面对于代码检查的东西挺多,不知道是不是有些历史遗留的东西没清理 ~

@SigureMo
Copy link
Member

SigureMo commented Sep 2, 2023

exec_samplecode_test 在多个命令里面被调用,具体怎么调用的,CI 流水线里面的配置我也不清楚 ~

https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/dev_guides/git_guides/paddle_ci_manual_cn.html#pr-ci-static-check 可以找到一部分描述,但是我不太清楚「编译脚本」、「测试脚本」代表什么,从名字上看这两条命令明明只是差了环境而已,两个应该都是「编译 + 测试脚本」

我看了下流水线配置,应该只执行了 bash -x paddle/scripts/paddle_build.sh build_and_check_gpu,没看到 build_and_check_cpu

个人感觉 paddle_build.sh 里面对于代码检查的东西挺多,不知道是不是有些历史遗留的东西没清理 ~

应该是这样的……

@megemini
Copy link
Contributor

megemini commented Sep 3, 2023

@megemini 话说现在这种空的是正常的么,我看代码里好像是会在下面输出 CPU 和 GPU 各自的信息:

刚又看了 paddle_build.sh 脚本,之前是会最后打印一些信息,不过是用 grep 一段特定日志定位的,导致现在输出没有了:

function summary_check_problems() {
    set +x
    local example_code=$1
    local example_info=$2
    if [ $example_code -ne 0 ];then
        echo "==============================================================================="
        echo "*****Example code error***** Please fix the error listed in the information:"
        echo "==============================================================================="
        echo "$example_info" | grep "API check -- Example Code" -A $(echo "$example_info" | wc -l)
        exit $example_code
    fi
    set -x
}

这里我也改一下吧 ~

@SigureMo
Copy link
Member

SigureMo commented Sep 4, 2023

@enkilee 日志里 GPU 报错的 case 需要修正下哈

@enkilee
Copy link
Contributor Author

enkilee commented Sep 5, 2023

2023-09-05 15:37:19
2023-09-05 15:37:19 File "<doctest:<modpath?>::paddle.incubate.nn.functional.fused_dropout_add:1:0>", line rel: 8, abs: 8, in
2023-09-05 15:37:19 >>> out = fused_dropout_add(x, y, p=0.5)
2023-09-05 15:37:19
2023-09-05 15:37:19 File "/usr/local/lib/python3.10/dist-packages/paddle/incubate/nn/functional/fused_dropout_add.py", line 89, in fused_dropout_add
2023-09-05 15:37:19 out, seed_offset = _C_ops.fused_dropout_add(
2023-09-05 15:37:19
2023-09-05 15:37:19 RuntimeError:
2023-09-05 15:37:19
2023-09-05 15:37:19 --------------------------------------
2023-09-05 15:37:19 C++ Traceback (most recent call last):
2023-09-05 15:37:19 --------------------------------------
2023-09-05 15:37:19 0 paddle::pybind::eager_api_fused_dropout_add(_object*, _object*, _object*)
2023-09-05 15:37:19 1 fused_dropout_add_ad_func(paddle::Tensor const&, paddle::Tensor const&, paddle::optionalpaddle::Tensor const&, paddle::experimental::ScalarBasepaddle::Tensor, bool, std::string, int, bool)
2023-09-05 15:37:19 2 paddle::experimental::fused_dropout_add(paddle::Tensor const&, paddle::Tensor const&, paddle::optionalpaddle::Tensor const&, paddle::experimental::ScalarBasepaddle::Tensor const&, bool, std::string const&, int, bool)
2023-09-05 15:37:19 3 phi::KernelFactory::SelectKernelOrThrowError(std::string const&, phi::KernelKey const&, bool) const
2023-09-05 15:37:19 4 phi::enforce::EnforceNotMet::EnforceNotMet(phi::ErrorSummary const&, char const*, int)
2023-09-05 15:37:19 5 phi::enforce::GetCurrentTraceBackStringabi:cxx11
2023-09-05 15:37:19
2023-09-05 15:37:19 ----------------------
2023-09-05 15:37:19 Error Message Summary:
2023-09-05 15:37:19 ----------------------
2023-09-05 15:37:19 NotFoundError: The kernel with key (CPU, Undefined(AnyLayout), float32) of kernel fused_dropout_add is not registered. Selected wrong Backend CPU. Paddle support following Backends: GPU.
2023-09-05 15:37:19 [Hint: Expected kernel_iter == iter->second.end() && kernel_key.backend() == Backend::CPU != true, but received kernel_iter == iter->second.end() && kernel_key.backend() == Backend::CPU:1 == true:1.] (at /paddle/paddle/phi/core/kernel_factory.cc:263)

2023-09-05 15:37:19 RuntimeError:
2023-09-05 15:37:19
2023-09-05 15:37:19 --------------------------------------
2023-09-05 15:37:19 C++ Traceback (most recent call last):
2023-09-05 15:37:19 --------------------------------------
2023-09-05 15:37:19 0 moe_dygraph_function(paddle::Tensor const&, paddle::Tensor const&, paddle::Tensor const&, paddle::Tensor const&, paddle::Tensor const&, paddle::Tensor const&, paddle::framework::AttributeMap const&)
2023-09-05 15:37:19 1 paddle::imperative::Tracer::TraceOp(std::string const&, paddle::imperative::NameTensorMap const&, paddle::imperative::NameTensorMap const&, paddle::framework::AttributeMap&, phi::Place const&, paddle::framework::AttributeMap*, bool, std::map<std::string, std::string, std::less<std::string >, std::allocator<std::pair<std::string const, std::string > > > const&)
2023-09-05 15:37:19 2 void paddle::imperative::Tracer::TraceOpImplegr::EagerVariable(std::string const&, paddle::imperative::details::NameVarMapTraitegr::EagerVariable::Type const&, paddle::imperative::details::NameVarMapTraitegr::EagerVariable::Type const&, paddle::framework::AttributeMap&, phi::Place const&, bool, std::map<std::string, std::string, std::less<std::string >, std::allocator<std::pair<std::string const, std::string > > > const&, paddle::framework::AttributeMap*, bool)
2023-09-05 15:37:19 3 paddle::imperative::PreparedOp::Prepare(paddle::imperative::NameTensorMap const&, paddle::imperative::NameTensorMap const&, paddle::framework::OperatorWithKernel const&, phi::Place const&, paddle::framework::AttributeMap const&, paddle::framework::AttributeMap const&)
2023-09-05 15:37:19 4 paddle::imperative::PreparedOp paddle::imperative::PrepareImplegr::EagerVariable(paddle::imperative::details::NameVarMapTraitegr::EagerVariable::Type const&, paddle::imperative::details::NameVarMapTraitegr::EagerVariable::Type const&, paddle::framework::OperatorWithKernel const&, phi::Place const&, paddle::framework::AttributeMap const&, paddle::framework::AttributeMap const&, phi::KernelFactory const&, phi::OpUtilsMap const&, phi::DefaultKernelSignatureMap const&)
2023-09-05 15:37:19 5 phi::enforce::EnforceNotMet::EnforceNotMet(phi::ErrorSummary const&, char const*, int)
2023-09-05 15:37:19 6 phi::enforce::GetCurrentTraceBackStringabi:cxx11
2023-09-05 15:37:19
2023-09-05 15:37:19 ----------------------
2023-09-05 15:37:19 Error Message Summary:
2023-09-05 15:37:19 ----------------------
2023-09-05 15:37:19 NotFoundError: There are no kernels which are registered in the moe operator.
2023-09-05 15:37:19 [Hint: Expected kernels_iter != all_op_kernels.end(), but received kernels_iter == all_op_kernels.end().] (at /paddle/paddle/fluid/imperative/prepared_operator.cc:374)
2023-09-05 15:37:19 [operator < moe > error]

@megemini
Copy link
Contributor

megemini commented Sep 5, 2023

@enkilee 设置一下 device 吧 ~

            >>> # doctest: +REQUIRES(env:GPU)
            >>> import paddle
            >>> paddle.set_device('gpu')
            >>> paddle.seed(2023)
            >>> from paddle.incubate.nn.functional import fused_dropout_add
            >>> x = paddle.randn([4, 10], dtype="float32")
            >>> y = paddle.randn([4, 10], dtype="float32")
            >>> out = fused_dropout_add(x, y, p=0.5)
            >>> print(out)

@enkilee
Copy link
Contributor Author

enkilee commented Sep 5, 2023

实在抱歉,忘了。

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

emmmm,还有些小问题最好解决下 已解决

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

@luotao1 luotao1 merged commit 4dbe441 into PaddlePaddle:develop Sep 6, 2023
BeingGod pushed a commit to BeingGod/Paddle that referenced this pull request Sep 9, 2023
…ddlePaddle#56541)

* test=docs_preview

* test=docs_preview

* test=docs_preview

* test=docs_preview

* test=docs_preview

* test=docs_preview

* fix

* test=docs_preview

* test=docs_preview

* fix

* move stmts under imports

---------

Co-authored-by: SigureMo <[email protected]>
@enkilee enkilee deleted the xdoctest-250-260 branch December 19, 2023 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants