-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 No.116-119 #56118
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/optimizer/optimizer.py
Outdated
... adam.set_lr(lr_list[i]) | ||
... lr = adam.get_lr() | ||
... print("current lr is {}".format(lr)) | ||
Print: |
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.
>>> from paddle.static.quantization \ | ||
... import ImperativeQuantAware |
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.
import 代码风格改一下吧
>>> from paddle.static.quantization import (
... ImperativeQuantAware,
... )
print(q_config) | ||
>>> quanter = FakeQuanterWithAbsMaxObserver(moving_rate=0.9) | ||
>>> q_config = QuantConfig(activation=quanter, weight=quanter) | ||
>>> print(q_config) |
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.
这里输出方便打印么?方便的话最好加一下输出,如果输出随机可以考虑 skip,如果输出太多可以考虑用 ...
或者不写
@SigureMo Done~ |
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/quantization/config.py
Outdated
>>> quanter = FakeQuanterWithAbsMaxObserver(moving_rate=0.9) | ||
>>> q_config = QuantConfig(activation=None, weight=None) | ||
>>> q_config.add_layer_config([model.fc], activation=quanter, weight=quanter) | ||
>>> print(q_config) |
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/quantization/config.py
Outdated
>>> quanter = FakeQuanterWithAbsMaxObserver(moving_rate=0.9) | ||
>>> q_config = QuantConfig(activation=None, weight=None) | ||
>>> q_config.add_name_config([model.fc.full_name()], activation=quanter, weight=quanter) | ||
>>> print(q_config) |
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/quantization/config.py
Outdated
>>> quanter = FakeQuanterWithAbsMaxObserver(moving_rate=0.9) | ||
>>> q_config = QuantConfig(activation=None, weight=None) | ||
>>> q_config.add_type_config([Linear], activation=quanter, weight=quanter) | ||
>>> print(q_config) |
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.
和这里
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.
done
python/paddle/quantization/config.py
Outdated
Global config: | ||
None | ||
Layer prefix config: | ||
{'linear_0': <paddle.quantization.config.SingleLayerConfig object at 0x7fe41a680ee0>} |
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.
这里有内存地址的肯定不能保证输出一致的,可以用 # doctest: +SKIP
跳过输出检查
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.
这里有内存地址的肯定不能保证输出一致的,可以用
# doctest: +SKIP
跳过输出检查
done
code style 需要处理一下 |
>>> arg1_value = "test" | ||
>>> kwarg1_value = 20 | ||
>>> quanter = CustomizedQuanter(arg1_value, kwarg1=kwarg1_value) | ||
>>> q_config = QuantConfig(activation=quanter, weight=quanter) | ||
|
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.
这段代码看起来不能在 xdoctest 环境跑,skip 掉吧
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 🐾
python/paddle/quantization/config.py
Outdated
@@ -155,20 +163,25 @@ def add_name_config( | |||
Examples: | |||
.. code-block:: python |
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.
.. code-block::python 要缩进
python/paddle/quantization/config.py
Outdated
@@ -200,20 +213,25 @@ def add_type_config( | |||
Examples: | |||
.. code-block:: python |
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/quantization/config.py
Outdated
@@ -242,16 +260,16 @@ def add_qat_layer_mapping(self, source: type, target: type): | |||
Examples: | |||
.. code-block:: python |
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/quantization/config.py
Outdated
@@ -274,11 +292,11 @@ def add_customized_leaf(self, layer_type: type): | |||
Examples: | |||
.. code-block:: python |
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/quantization/config.py
Outdated
@@ -381,20 +399,20 @@ def _specify(self, model: Layer): | |||
Examples: | |||
.. code-block:: python |
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.
要缩进
@@ -247,37 +250,38 @@ def quantize(self, model): | |||
Examples: | |||
.. code-block:: python |
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.
要缩进
... input = paddle.randint(low=0, high=5, shape=[5]) | ||
... out = emb(input) | ||
... out.backward() | ||
... print("Learning rate of step{}: {}".format(batch, adam.get_lr())) # 0.01 |
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.
这里要有输出~
... print("Learning rate of step{}: {}".format(batch, adam.get_lr())) # 0.5->0.05... | ||
... adam.step() | ||
... scheduler.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.
这里要有输出~
python/paddle/optimizer/optimizer.py
Outdated
... print("Learning rate of step{}: {}", adam.get_lr()) # 0.5->0.05->0.005... | ||
... out = exe.run(main_prog, feed={'x': np.random.randn(3, 10).astype('float32')}) | ||
... scheduler.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.
要有输出~
>>> # Given codes in ./customized_quanter.py | ||
>>> from paddle.quantization import quanter | ||
>>> from paddle.quantization import BaseQuanter | ||
>>> @quanter("CustomizedQuanter") | ||
>>> class CustomizedQuanterLayer(BaseQuanter): | ||
... def __init__(self, arg1, kwarg1=None): | ||
... pass | ||
|
||
>>> # Used in ./test.py | ||
>>> # from .customized_quanter import CustomizedQuanter | ||
>>> from paddle.quantization import QuantConfig | ||
>>> # doctest: +SKIP | ||
>>> arg1_value = "test" | ||
>>> kwarg1_value = 20 | ||
>>> quanter = CustomizedQuanter(arg1_value, kwarg1=kwarg1_value) | ||
>>> q_config = QuantConfig(activation=quanter, weight=quanter) |
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.
整段 skip 吧~
麻烦再review一下~ @megemini |
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.
Examples 1:
要改一下哈~
python/paddle/optimizer/optimizer.py
Outdated
Learning rate of step{}: {} 0.5 | ||
Learning rate of step{}: {} 0.5 | ||
Learning rate of step{}: {} 0.05 | ||
Learning rate of step{}: {} 0.05 | ||
Learning rate of step{}: {} 0.005000000000000001 | ||
Learning rate of step{}: {} 0.005000000000000001 | ||
Learning rate of step{}: {} 0.0005000000000000001 | ||
Learning rate of step{}: {} 0.0005000000000000001 | ||
Learning rate of step{}: {} 5.000000000000001e-05 | ||
Learning rate of step{}: {} 5.000000000000001e-05 |
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.
print("Learning rate of step{}: {}", adam.get_lr()) -> print("Learning rate of step{}: {}", batch, adam.get_lr())
python/paddle/quantization/config.py
Outdated
Examples: | ||
.. code-block:: python |
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.
.. code-block:: python 要有缩进~
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.
这居然还反向缩进了:joy:,缩退么 [doge]
整段 docstring 的缩进都有问题,不要多余的一个空格
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.
这个是原来的缩进就有问题,我改漏了, 已经改过来了, 实在不好意思,改的时候可能整段的缩进出问题了
>>> # Save quant model for the inference. | ||
>>> imperative_qat.save_quantized_model( | ||
... layer=model, | ||
... model_path="./imperative_model_qat") |
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.
不要写成
Examples:
.. code-block:: python
>>> xxxxx
Examples:
.. code-block:: python
>>> yyyyy
而是写成
Examples:
.. code-block:: python
:name: code-example-1
>>> xxxxx
.. code-block:: python
:name: code-example-2
>>> yyyyy
因为本 API 非公开 API,所以就不用添加 name 了,写成下面即可:
Examples:
.. code-block:: python
>>> xxxxx
.. code-block:: python
>>> yyyyy
简单来说就是删除第二个 Examples:
这一行
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 🐾
PR types
Others
PR changes
Others
Description
修改如下文件的示例代码为新的格式,并通过 xdoctest 检查: