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 171-180] reformat example code with google style in audio/* #57111

Merged
merged 12 commits into from
Sep 18, 2023

Conversation

whisky-12
Copy link
Contributor

PR types

Others

PR changes

Others

Description

之前 #56159 提交代码时 只修改了对应行号出的代码 ,导致文件中其他代码的修改遗漏 ,本次PR进行补充
修改如下文件的示例代码,使其通过 xdoctest 检查:

  • python/paddle/amp/auto_cast.py
  • python/paddle/amp/debugging.py
  • python/paddle/amp/grad_scaler.py
  • python/paddle/device/__init__.py
  • python/paddle/device/cuda/__init__.py
  • python/paddle/profiler/profiler.py
  • python/paddle/profiler/utils.py
  • python/paddle/sparse/binary.py
  • python/paddle/sparse/creation.py

预览:

Related links

@sunzhongkai588 @SigureMo @megemini

@paddle-bot
Copy link

paddle-bot bot commented Sep 8, 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 the contributor External developers label Sep 8, 2023
@whisky-12 whisky-12 changed the title [Doctest]fix No.171-180, test=docs_preview [xdoctest][task 171-180] reformat example code with google style in audio/* Sep 8, 2023
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Sep 8, 2023
>>> data = paddle.to_tensor(data)
>>> with paddle.amp.amp_guard():
... conv = conv2d(data)
... assert conv.dtype == paddle.float16
Copy link
Contributor

Choose a reason for hiding this comment

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

这里在 aistudio 里面会报错,但是,如果不使用 conv2d 的 bias,就可以:

            >>> import numpy as np
            >>> import paddle
            >>> paddle.seed(2023)
            >>> data = np.random.uniform(-1, 1, [10, 3, 32, 32]).astype('float32')
            >>> conv2d = paddle.nn.Conv2D(3, 2, 3, bias_attr=False)
            >>> data = paddle.to_tensor(data)
            >>> with paddle.amp.amp_guard():
            ...     conv = conv2d(data)
            ...     assert conv.dtype == paddle.float16

或者需要先转换:

            >>> import numpy as np
            >>> import paddle
            >>> paddle.seed(2023)
            >>> data = np.random.uniform(-1, 1, [10, 3, 32, 32]).astype('float32')
            >>> conv2d = paddle.nn.Conv2D(3, 2, 3)
            >>> conv2d = paddle.amp.amp_decorate(models=conv2d, level='O2')
            >>> data = paddle.to_tensor(data)
            >>> with paddle.amp.amp_guard():
            ...     conv = conv2d(data)
            ...     assert conv.dtype == paddle.float16

@SigureMo 为什么用了 bias,float16 就不能用了???

Comment on lines 162 to 164
>>> paddle.device.set_device('gpu')

# required: gpu
paddle.set_device("gpu")
tensor = paddle.randn([512, 512, 512], "float")
del tensor
paddle.device.cuda.empty_cache()
>>> paddle.set_device("gpu")
Copy link
Contributor

Choose a reason for hiding this comment

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

重复了

Comment on lines 92 to 99
... dtype = 'float32'
... x = paddle.rand([10, 2, 2], dtype=dtype)
... model = MyLayer(dtype)
... x[0] = float(0)
... loss = model(x)
... adam = paddle.optimizer.Adam(parameters=model.parameters())
... loss.backward()
... adam.step()
Copy link
Contributor

Choose a reason for hiding this comment

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

这部分缩进有问题,应该不是 MyLayer 的一部分

... # out_data = func(self, *modified_args, **kwargs)
... # File "test.py", line 10, in forward
... # return 1/x * self._w+ self._b
... #RuntimeError: (PreconditionNotMet) There are NAN or INF (num_nan=0, num_inf=4, num_zero=0) in [device=gpu:0, op=divide, tensor=, dtype=fp32].
Copy link
Contributor

Choose a reason for hiding this comment

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

>>>

Comment on lines 483 to 489
>>> # <------------------------------------------------------- op list -------------------------------------------------------->
>>> # <--------------- Op Name ---------------- | -- FP16 Calls --- | -- BF16 Calls --- | --- FP32 Calls--- | -- Other Calls -->
>>> # conv2d | 1 | 0 | 0 | 0
>>> # elementwise_add | 1 | 0 | 0 | 0
>>> # reshape2 | 1 | 0 | 0 | 0
>>> # transfer_dtype | 0 | 0 | 3 | 0
>>> # <----------------------------------------------------- op count: 4 ------------------------------------------------------>
Copy link
Contributor

Choose a reason for hiding this comment

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

amp 在 cpu 和 gpu 行为不同,CI 默认用 cpu,这里最好 set_device('gpu'),并且加 doctest requires~

另外,这里的输出,与我在 aistudio 上的也不一样,需要检查一下 ~

Comment on lines 510 to 528
>>> import paddle

>>> conv = paddle.nn.Conv2D(3, 2, 3)
>>> paddle.seed(2023)
>>> x = paddle.rand([10, 3, 32, 32])

>>> paddle.amp.debugging.enable_operator_stats_collection()
>>> # AMP list including conv2d, elementwise_add, reshape2, cast (transfer_dtype)
>>> with paddle.amp.auto_cast(enable=True, level='O2'):
... out = conv(x)
>>> # Print to the standard output.
>>> paddle.amp.debugging.disable_operator_stats_collection()
>>> # <------------------------------------------------------- op list -------------------------------------------------------->
>>> # <--------------- Op Name ---------------- | -- FP16 Calls --- | -- BF16 Calls --- | --- FP32 Calls--- | -- Other Calls -->
>>> # conv2d | 1 | 0 | 0 | 0
>>> # elementwise_add | 1 | 0 | 0 | 0
>>> # reshape2 | 1 | 0 | 0 | 0
>>> # transfer_dtype | 0 | 0 | 3 | 0
>>> # <----------------------------------------------------- op count: 4 ------------------------------------------------------>
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

... # AMP list including conv2d, elementwise_add, reshape2, cast (transfer_dtype)
... with paddle.amp.auto_cast(enable=True, level='O2'):
... out = conv(x)
>>> # Print to the standard output.
Copy link
Contributor

Choose a reason for hiding this comment

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

同上~

>>> from paddle.base import core
>>> try:
... import xlsxwriter as xlw
>>> except ImportError:
Copy link
Contributor

Choose a reason for hiding this comment

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

复合语句,用 ...

... subprocess.check_call(
... ['python', '-m', 'pip', 'install', 'xlsxwriter==3.0.9']
... )
... import xlsxwriter as xlw
Copy link
Contributor

Choose a reason for hiding this comment

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

缩进有问题 ~

Comment on lines 431 to 445
>>> class RandomDataset(paddle.io.Dataset):
... def __init__(self, num_samples):
... self.num_samples = num_samples

... def __getitem__(self, idx):
... image = paddle.rand(shape=[100], dtype='float32')
... label = paddle.randint(0, 10, shape=[1], dtype='int64')
... return image, label

... def __len__(self):
... return self.num_samples

>>> class SimpleNet(paddle.nn.Layer):
... def __init__(self):
... super().__init__()
... self.fc = paddle.nn.Linear(100, 10)

... def forward(self, image, label=None):
... return self.fc(image)
Copy link
Contributor

Choose a reason for hiding this comment

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

class 里面不要留空行 ~ 空行使 class 截断,导致运行检查错误。

Comment on lines 264 to 266
[[ 0., -1., 0., 0.],
[ 0., 2., -6., 0.],
[ 6., 8., 4., 8.]]
Copy link
Contributor

Choose a reason for hiding this comment

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

输出是 Tensor

Comment on lines 317 to 319
[[ 0., -1., 0., 4.],
[ 0., -2., 0., 0.],
[ 2., 2., -4., -8.]]
Copy link
Contributor

Choose a reason for hiding this comment

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

输出是 Tensor

Comment on lines 359 to 361
[[ 0., 0., 0., -4.],
[ 0., 0., 9., 0.],
[ 8., 15., 0., 0.]]
Copy link
Contributor

Choose a reason for hiding this comment

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

输出是 Tensor

Comment on lines 404 to 406
[[ nan , -inf. , nan , -1. ],
[ nan , 0. , 1. , nan ],
[ 2. , 1.66666663, 0. , 0. ]]
Copy link
Contributor

Choose a reason for hiding this comment

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

输出是 Tensor

Comment on lines 445 to 448
>>> paddle.sparse.is_same_shape(x, y)
>>> #True
>>> paddle.sparse.is_same_shape(x, z)
>>> #False
Copy link
Contributor

Choose a reason for hiding this comment

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

>>> #True -> True

@SigureMo
Copy link
Member

SigureMo commented Sep 9, 2023

标题不对吧,不是 audio 吧

@whisky-12
Copy link
Contributor Author

辛苦各位对PR问题的指摘,以上NG最近两天修复 ,以上 再次感谢 辛苦了!

@SigureMo
Copy link
Member

@whisky-12 这个 PR 为什么 close 了呢?

@SigureMo
Copy link
Member

喔,知道了,误 force push 了

@whisky-12
Copy link
Contributor Author

PR 咋没了 我这边准备提交代码呢

@SigureMo
Copy link
Member

SigureMo commented Sep 15, 2023

因为你 force push 了无额外 commit 的分支,导致自动 close

非必要不要 force push

@whisky-12
Copy link
Contributor Author

哦 那个这个PR还能重新open嘛

@SigureMo
Copy link
Member

image

@whisky-12
Copy link
Contributor Author

上午那时 是想 将这条支线的代码和最新的develop保持一致 ,然后就在更新了下仓库
image

@whisky-12
Copy link
Contributor Author

目前提交完代码 ,提示需要新建PR
image

@SigureMo SigureMo reopened this Sep 15, 2023
@SigureMo
Copy link
Member

非空就可以 reopen 了

@whisky-12
Copy link
Contributor Author

非空就可以 reopen 了

感谢 以后谨慎更新了

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 db13081 into PaddlePaddle:develop Sep 18, 2023
Frida-a pushed a commit to Frida-a/Paddle that referenced this pull request Oct 14, 2023
…udio/* (PaddlePaddle#57111)

* [Doctest]fix No.171-180, test=docs_preview

* [Doctest]fix No.171-180, test=docs_preview

* fix python/paddle/amp/auto_cast.py

* fix python/paddle/amp/debugging.py

* fix python/paddle/amp/grad_scaler.py

* fix python/paddle/device/__init__.py

* fix python/paddle/profiler/utils.py

* fix python/paddle/sparse/binary.py

* fix python/paddle/sparse/creation.py

* fix ci error;

* remove prompt before output

* skip some output

---------

Co-authored-by: SigureMo <[email protected]>
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
…udio/* (PaddlePaddle#57111)

* [Doctest]fix No.171-180, test=docs_preview

* [Doctest]fix No.171-180, test=docs_preview

* fix python/paddle/amp/auto_cast.py

* fix python/paddle/amp/debugging.py

* fix python/paddle/amp/grad_scaler.py

* fix python/paddle/device/__init__.py

* fix python/paddle/profiler/utils.py

* fix python/paddle/sparse/binary.py

* fix python/paddle/sparse/creation.py

* fix ci error;

* remove prompt before output

* skip some output

---------

Co-authored-by: SigureMo <[email protected]>
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.

5 participants