-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/amp/auto_cast.py
Outdated
>>> data = paddle.to_tensor(data) | ||
>>> with paddle.amp.amp_guard(): | ||
... conv = conv2d(data) | ||
... assert conv.dtype == paddle.float16 |
There was a problem hiding this comment.
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 就不能用了???
>>> 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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
重复了
python/paddle/amp/debugging.py
Outdated
... 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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分缩进有问题,应该不是 MyLayer 的一部分
python/paddle/amp/debugging.py
Outdated
... # 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]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用 >>>
python/paddle/amp/debugging.py
Outdated
>>> # <------------------------------------------------------- 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 ------------------------------------------------------> |
There was a problem hiding this comment.
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 上的也不一样,需要检查一下 ~
python/paddle/amp/debugging.py
Outdated
>>> 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 ------------------------------------------------------> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
python/paddle/amp/debugging.py
Outdated
... # 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上~
python/paddle/amp/debugging.py
Outdated
>>> from paddle.base import core | ||
>>> try: | ||
... import xlsxwriter as xlw | ||
>>> except ImportError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
复合语句,用 ...
python/paddle/amp/debugging.py
Outdated
... subprocess.check_call( | ||
... ['python', '-m', 'pip', 'install', 'xlsxwriter==3.0.9'] | ||
... ) | ||
... import xlsxwriter as xlw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
缩进有问题 ~
python/paddle/profiler/profiler.py
Outdated
>>> 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class 里面不要留空行 ~ 空行使 class 截断,导致运行检查错误。
python/paddle/sparse/binary.py
Outdated
[[ 0., -1., 0., 0.], | ||
[ 0., 2., -6., 0.], | ||
[ 6., 8., 4., 8.]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
输出是 Tensor
python/paddle/sparse/binary.py
Outdated
[[ 0., -1., 0., 4.], | ||
[ 0., -2., 0., 0.], | ||
[ 2., 2., -4., -8.]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
输出是 Tensor
python/paddle/sparse/binary.py
Outdated
[[ 0., 0., 0., -4.], | ||
[ 0., 0., 9., 0.], | ||
[ 8., 15., 0., 0.]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
输出是 Tensor
python/paddle/sparse/binary.py
Outdated
[[ nan , -inf. , nan , -1. ], | ||
[ nan , 0. , 1. , nan ], | ||
[ 2. , 1.66666663, 0. , 0. ]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
输出是 Tensor
python/paddle/sparse/binary.py
Outdated
>>> paddle.sparse.is_same_shape(x, y) | ||
>>> #True | ||
>>> paddle.sparse.is_same_shape(x, z) | ||
>>> #False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> #True
-> True
标题不对吧,不是 audio 吧 |
辛苦各位对PR问题的指摘,以上NG最近两天修复 ,以上 再次感谢 辛苦了! |
33e1d98
to
d34b4ea
Compare
@whisky-12 这个 PR 为什么 close 了呢? |
喔,知道了,误 force push 了 |
PR 咋没了 我这边准备提交代码呢 |
因为你 force push 了无额外 commit 的分支,导致自动 close 非必要不要 force push |
哦 那个这个PR还能重新open嘛 |
非空就可以 reopen 了 |
感谢 以后谨慎更新了 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTMeow 🐾
…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]>
…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]>
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