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][task 318-322] reformat example code with google style in paddle/fluid/* and python/paddle/sparse/unary #56748

Merged
merged 22 commits into from
Sep 11, 2023

Conversation

whisky-12
Copy link
Contributor

PR types

Others

PR changes

Others

Description

修改如下文件的示例代码,使其通过 xdoctest 检查:

  • python/paddle/sparse/unary.py
  • paddle/fluid/operators/fused/fused_elemwise_activation_op.cc
  • paddle/fluid/pybind/cuda_streams_py.cc
  • paddle/fluid/pybind/custom_device_py.cc
  • paddle/fluid/pybind/inference_api.cc

预览:

Related links

@sunzhongkai588 @SigureMo @megemini

Comment on lines 986 to 1001
>>> import paddle

>>> format = "coo"
>>> dense_x = paddle.randn((5, 5), dtype='float64')

>>> if format == "coo":
... sparse_x = dense_x.to_sparse_coo(len(dense_x.shape))
>>> else:
... sparse_x = dense_x.to_sparse_csr()

>>> print("sparse.pca_lowrank API only support CUDA 11.x")
>>> U, S, V = None, None, None
>>> # use code blow when your device CUDA version >= 11.0
>>> # U, S, V = paddle.sparse.pca_lowrank(sparse_x)

>>> print(U)
Copy link
Contributor

Choose a reason for hiding this comment

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

这段代码可以在 gpu 下面跑,试一下:

  1. 加个 REQUIRES 和 set_device
  2. 加个 seed,因为有 randn
  3. 使用 U, S, V = paddle.sparse.pca_lowrank(sparse_x) 而不是 U, S, V = None, None, 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.

收到 辛苦review ,已更新代码

Copy link
Contributor Author

Choose a reason for hiding this comment

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

您好 尊敬的 @megemini 先生:
本次对应将U, S, V = paddle.sparse.pca_lowrank(sparse_x) 结果值分别进行打印,根据log显示 CI check失败 ,报错信息如下:
image

        根据目前情况 是否执行 >>> # doctest: +SKIP('random sample') 跳过测试?

Copy link
Contributor

@megemini megemini Sep 1, 2023

Choose a reason for hiding this comment

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

根据目前情况 是否执行 >>> # doctest: +SKIP('random sample') 跳过测试?

先不要跳过 ~

这段示例代码的输出没有改,导致的错误 ~

从日志上看,我在 aistudio 上用 dev 版本的 gpu 环境,测试的结果跟 ci 结果是一样的 ~

自己尝试运行,然后修改一下示例中的结果吧。

@paddle-bot paddle-bot bot added the contributor External developers label Aug 29, 2023
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Aug 31, 2023
@whisky-12 whisky-12 changed the title [xdoctest][task 318-322] reformat example code with google style in a… [xdoctest][task 318-322] reformat example code with google style in audio/* Aug 31, 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.

我在 aistudio 用 dev 版本测试,pca_lowrank 是没问题的,包括随机结果也一致 ~

但是 CI 环境中运行出错了~

@SigureMo 看看咋整? @whisky-12 抽空重新跑一下 CI 试试?

@SigureMo
Copy link
Member

SigureMo commented Sep 5, 2023

@SigureMo 看看咋整? @whisky-12 抽空重新跑一下 CI 试试?

我 rerun 下试试

@whisky-12
Copy link
Contributor Author

我在 aistudio 用 dev 版本测试,pca_lowrank 是没问题的,包括随机结果也一致 ~

但是 CI 环境中运行出错了~

@SigureMo 看看咋整? @whisky-12 抽空重新跑一下 CI 试试?

@SigureMo 看看咋整? @whisky-12 抽空重新跑一下 CI 试试?

我 rerun 下试试

收到,辛苦了 , 我在aistudio也跑了下结果 如下:
image
目前情况是 昨天晚上 和 今天早上 相同的代码 今天是第二次执行CI

@megemini
Copy link
Contributor

megemini commented Sep 5, 2023

收到,辛苦了 , 我在aistudio也跑了下结果 如下:

图挂了 ~ 🫠🫠🫠 你能看到?

@whisky-12
Copy link
Contributor Author

收到,辛苦了 , 我在aistudio也跑了下结果 如下:

图挂了 ~ 🫠🫠🫠 你能看到?

哎嘿,我这边页面图片正常显示呀 ,容我再传一张:

2023-09-05 143833

详细结果见上图 ,辛苦了

@megemini
Copy link
Contributor

megemini commented Sep 6, 2023

github 抽风了,现在我这边头像也看不到了 ~ 🤣🤣🤣

搞不明白了,只能怀疑 ci 里面的包有问题?

@whisky-12
Copy link
Contributor Author

github 抽风了,现在我这边头像也看不到了 ~ 🤣🤣🤣

搞不明白了,只能怀疑 ci 里面的包有问题?

🤣🤣🤣 其实我比较好奇 同样的代码 CI的报错量咋还不一样了呢 ,难搞哦

Copy link
Member

@SigureMo SigureMo Sep 6, 2023

Choose a reason for hiding this comment

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

这个文件里大量示例代码没有修改格式

之前已经合入的其他 PR 也有这个问题,review 时候不可能看每个文件是否全部改完,只能靠自觉

@megemini 有时间看看 .cc 文件目前是不支持嘛?

image

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

Choose a reason for hiding this comment

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

@megemini 有时间看看 .cc 文件目前是不支持嘛?

工具没有限制文件类型,这里是因为,cc 里面文档的书写方式与python不同(cc: DOC...DOC, python: """...""") ~

我把工具里面解析的正则改一下吧 ~

不过,这个应该不影响 CI 里面的检查,CI 里面是直接读取 docstring 的 ~

Copy link
Contributor

Choose a reason for hiding this comment

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

已更新,pull 试一下 ~

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.

2023-09-08 10:37:57 --------------------------------------
2023-09-08 10:37:57 C++ Traceback (most recent call last):
2023-09-08 10:37:57 --------------------------------------
2023-09-08 10:37:57 0   phi::DenseTensor::~DenseTensor()
2023-09-08 10:37:57 1   std::_Sp_counted_deleter<phi::Allocation*, std::function<void (phi::Allocation*)>, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_dispose()
2023-09-08 10:37:57 2   paddle::memory::allocation::StatAllocator::FreeImpl(phi::Allocation*)
2023-09-08 10:37:57 3   paddle::memory::allocation::CPUAllocator::FreeImpl(phi::Allocation*)

日志里面 paddle.sparse.transpose 挂了~ 这是啥意思?回收内存的时候挂了?

Comment on lines 192 to 195
>>> out1 = paddle.sparse.sum(sparse_x) # [1.]
>>> out2 = paddle.sparse.sum(sparse_x, axis=0) # [-1., 2.]
>>> out3 = paddle.sparse.sum(sparse_x, axis=-1) # [-2., 3.]
>>> out4 = paddle.sparse.sum(sparse_x, axis=1, keepdim=True) # [[-2.], [3.]]
Copy link
Contributor

Choose a reason for hiding this comment

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

这里可以用print把输出打印出来~

@SigureMo SigureMo changed the title [xdoctest][task 318-322] reformat example code with google style in audio/* [xdoctest][task 318-322] reformat example code with google style in paddle/fluid/* and python/paddle/sparse/unary Sep 9, 2023
@megemini
Copy link
Contributor

2023-09-10 04:37:32 DOCTEST DEBUG INFO
2023-09-10 04:37:32   XDoc "<modpath?>::paddle.sparse.transpose:1:0", line 7 <- wrt doctest
2023-09-10 04:37:32   File "<fpath?>", line 7, <- wrt source file
2023-09-10 04:37:32 DOCTEST PART BREAKDOWN
2023-09-10 04:37:32 Passed Parts:
2023-09-10 04:37:32     1 >>> import paddle
2023-09-10 04:37:32     3 >>> dense_x = paddle.to_tensor([[-2., 0.], [1., 2.]])
2023-09-10 04:37:32     4 >>> sparse_x = dense_x.to_sparse_coo(1)
2023-09-10 04:37:32     5 >>> out = paddle.sparse.transpose(sparse_x, [1, 0])
2023-09-10 04:37:32 Failed Part:
2023-09-10 04:37:32     6 >>> out
2023-09-10 04:37:32 DOCTEST TRACEBACK
2023-09-10 04:37:32 Differences (unified diff with -expected +actual):
2023-09-10 04:37:32     @@ -1,4 +1,4 @@
2023-09-10 04:37:32      Tensor(shape=[2, 2], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
2023-09-10 04:37:32     -    indices=[[0, 0]],
2023-09-10 04:37:32     -    values=[[-2.,  0.],
2023-09-10 04:37:32     -            [ 1.,  2.]])
2023-09-10 04:37:32     +       indices=[[1139, 65  ]],
2023-09-10 04:37:32     +       values=[[-2.,  0.],
2023-09-10 04:37:32     +               [ 1.,  2.]])
2023-09-10 04:37:32     
2023-09-10 04:37:32 Repr Difference:
2023-09-10 04:37:32     got  = 'Tensor(shape=[2, 2], dtype=paddle.float32, place=Place(cpu), stop_gradient=True, \n       indices=[[1139, 65  ]], \n       values=[[-2.,  0.],\n               [ 1.,  2.]])'
2023-09-10 04:37:32     want = 'Tensor(shape=[2, 2], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,\n    indices=[[0, 0]],\n    values=[[-2.,  0.],\n            [ 1.,  2.]])'
2023-09-10 04:37:32 DOCTEST REPRODUCTION
2023-09-10 04:37:32 CommandLine:
2023-09-10 04:37:32     python -m xdoctest <modpath?> paddle.sparse.transpose:1:0

在 aistudio 上面运行,会卡死~ 还是有点问题 ... ...

In [1]: import paddle
pa
In [2]: paddle.set_device('cpu')
Out[2]: Place(cpu)

In [3]: 

In [3]:             >>> import paddle
   ...:             >>> dense_x = paddle.to_tensor([[-2., 0.], [1., 2.]])
   ...:             >>> sparse_x = dense_x.to_sparse_coo(1)
   ...:             >>> out = paddle.sparse.transpose(sparse_x, [1, 0])
   ...:             >>> out
malloc_consolidate(): invalid chunk size

SigureMo
SigureMo previously approved these changes Sep 10, 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.

LGTMeow 🐾

Tensor(shape=[2, 2], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
indices=[[0, 0]],
values=[[-2., 0.],
[ 1., 2.]])
Copy link
Member

Choose a reason for hiding this comment

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

2023-09-08 10:37:57 --------------------------------------
2023-09-08 10:37:57 C++ Traceback (most recent call last):
2023-09-08 10:37:57 --------------------------------------
2023-09-08 10:37:57 0   phi::DenseTensor::~DenseTensor()
2023-09-08 10:37:57 1   std::_Sp_counted_deleter<phi::Allocation*, std::function<void (phi::Allocation*)>, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_dispose()
2023-09-08 10:37:57 2   paddle::memory::allocation::StatAllocator::FreeImpl(phi::Allocation*)
2023-09-08 10:37:57 3   paddle::memory::allocation::CPUAllocator::FreeImpl(phi::Allocation*)

日志里面 paddle.sparse.transpose 挂了~ 这是啥意思?回收内存的时候挂了?

这个问题有时间 @zrr1999 看一下吧 [doge],这个 PR 我觉得可以先行合入

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 66d7442 into PaddlePaddle:develop Sep 11, 2023
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