未验证 提交 b39f5f62 编写于 作者: C Candy2Tang 提交者: GitHub

[xdoctest][task 121] Reformat example code with google style in...

[xdoctest][task 121] Reformat example code with google style in python/paddle/quantization/ptq.py (#56232)

* [xdoctest][task 121] test=docs_preview

* test=document_fix

* fix indent

---------
Co-authored-by: NSigureMo <sigure.qaq@gmail.com>
上级 6e2d4321
......@@ -53,18 +53,61 @@ class PTQ(Quantization):
Return: The prepared model for post-training quantization.
Examples:
.. code-block:: python
from paddle.quantization import PTQ, QuantConfig
from paddle.quantization.observers import AbsmaxObserver
from paddle.vision.models import LeNet
.. code-block:: python
observer = AbsmaxObserver()
q_config = QuantConfig(activation=observer, weight=observer)
ptq = PTQ(q_config)
model = LeNet()
model.eval()
quant_model = ptq.quantize(model)
print(quant_model)
>>> from paddle.quantization import PTQ, QuantConfig
>>> from paddle.quantization.observers import AbsmaxObserver
>>> from paddle.vision.models import LeNet
>>> observer = AbsmaxObserver()
>>> q_config = QuantConfig(activation=observer, weight=observer)
>>> ptq = PTQ(q_config)
>>> model = LeNet()
>>> model.eval()
>>> quant_model = ptq.quantize(model)
>>> print(quant_model)
LeNet(
(features): Sequential(
(0): QuantedConv2D(
(weight_quanter): AbsmaxObserverLayer()
(activation_quanter): AbsmaxObserverLayer()
)
(1): ObserveWrapper(
(_observer): AbsmaxObserverLayer()
(_observed): ReLU()
)
(2): ObserveWrapper(
(_observer): AbsmaxObserverLayer()
(_observed): MaxPool2D(kernel_size=2, stride=2, padding=0)
)
(3): QuantedConv2D(
(weight_quanter): AbsmaxObserverLayer()
(activation_quanter): AbsmaxObserverLayer()
)
(4): ObserveWrapper(
(_observer): AbsmaxObserverLayer()
(_observed): ReLU()
)
(5): ObserveWrapper(
(_observer): AbsmaxObserverLayer()
(_observed): MaxPool2D(kernel_size=2, stride=2, padding=0)
)
)
(fc): Sequential(
(0): QuantedLinear(
(weight_quanter): AbsmaxObserverLayer()
(activation_quanter): AbsmaxObserverLayer()
)
(1): QuantedLinear(
(weight_quanter): AbsmaxObserverLayer()
(activation_quanter): AbsmaxObserverLayer()
)
(2): QuantedLinear(
(weight_quanter): AbsmaxObserverLayer()
(activation_quanter): AbsmaxObserverLayer()
)
)
)
"""
_model = model
if not inplace:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册