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

[Add] Paddle 代码 CI 中引入 xdoctest 检查 #55295

Merged
merged 18 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 29 additions & 25 deletions python/paddle/distribution/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,35 @@ class Beta(exponential_family.ExponentialFamily):

.. code-block:: python

import paddle

# scale input
beta = paddle.distribution.Beta(alpha=0.5, beta=0.5)
print(beta.mean)
# Tensor(shape=[], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
# 0.50000000)
print(beta.variance)
# Tensor(shape=[], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
# 0.12500000)
print(beta.entropy())
# Tensor(shape=[], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
# 0.12500000)

# tensor input with broadcast
beta = paddle.distribution.Beta(alpha=paddle.to_tensor([0.2, 0.4]), beta=0.6)
print(beta.mean)
# Tensor(shape=[2], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
# [0.25000000, 0.40000001])
print(beta.variance)
# Tensor(shape=[2], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
# [0.10416666, 0.12000000])
print(beta.entropy())
# Tensor(shape=[2], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
# [-1.91923141, -0.38095069])
>>> import paddle

>>> # scale input
>>> beta = paddle.distribution.Beta(alpha=0.5, beta=0.5)
>>> print(beta.mean)
Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.50000000])
Copy link
Member

Choose a reason for hiding this comment

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

image

这里是特意用的错误例子还是?0D Tensor 应该就是 shape=[] 的,2.5 应该就已经支持 0D Tensor 了,你那里用的是 2.4 嘛?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

忘了更新 Paddle 了 ...........................................


>>> print(beta.variance)
Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.12500000])

>>> print(beta.entropy())
Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
[-0.24156499])

>>> # tensor input with broadcast
>>> beta = paddle.distribution.Beta(alpha=paddle.to_tensor([0.2, 0.4]), beta=0.6)
>>> print(beta.mean)
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.25000000, 0.40000001])

>>> print(beta.variance)
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.10416666, 0.12000000])

>>> print(beta.entropy())
Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
[-1.91923141, -0.38095081])
"""

def __init__(self, alpha, beta):
Expand Down
1 change: 1 addition & 0 deletions python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ decorator
astor
paddle_bfloat==0.1.7
opt_einsum==3.3.0
xdoctest
Copy link
Member

Choose a reason for hiding this comment

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

xdoctest 的 requirement 看看放在 python 目录下是否合适?

不合适,requirements.txt 会在 setup.py 里用到,作为 paddle 的「依赖项」,用户在安装时候会自动安装

相比于「依赖项」,xdoctest 更类似于「开发依赖项」,不过我们目前是没有一个统一的地方来添加这个的(大多数社区规范是写一个 requirements-dev.txt,但我们没有),我们只有 python/paddle/unittest_py/requirements.txt(即「测试依赖」),但放在里面也是明显不合适的

目前可以添加到流水线中,或许以后可以直接放在 Docker 里

Copy link
Member

Choose a reason for hiding this comment

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

刚和 @luotao1 讨论了一下,这个还是放在 python/paddle/unittest_py/requirements.txt 吧,PR-CI-Static-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.

OK~ 只是 Paddle build 的时候可能也会调用这个代码检查,感觉放哪儿都不太合适~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

刚和 @luotao1 讨论了一下,这个还是放在 python/paddle/unittest_py/requirements.txt 吧,PR-CI-Static-Check 是会自动安装这个的

Paddle/python/unittest_py/requirements.txt 吧?

Copy link
Member

@SigureMo SigureMo Jul 11, 2023

Choose a reason for hiding this comment

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

Loading