Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
enkilee committed Oct 18, 2023
1 parent 40334ca commit 2494696
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
26 changes: 21 additions & 5 deletions python/paddle/nn/functional/flash_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,22 @@ def flash_attention(
>>> import paddle
>>> paddle.seed(1)
>>> paddle.seed(2023)
>>> q = paddle.rand((1, 128, 2, 16))
>>> output = paddle.nn.functional.flash_attention.flash_attention(q, q, q, 0.9, False, False)
>>> print(output)
(Tensor(shape=[1, 128, 2, 16], dtype=float32, place=Place(cpu), stop_gradient=True,
[[[[0.34992966, 0.34456208, 0.45826620, ..., 0.39883569,
0.42132431, 0.39157745],
[0.76687670, 0.65837246, 0.69117945, ..., 0.82817286,
0.76690865, 0.71485823]],
...,
[[0.71662450, 0.57275224, 0.57053083, ..., 0.48108247,
0.53336465, 0.54540104],
[0.59137970, 0.51350880, 0.50449550, ..., 0.38860250,
0.40526697, 0.60541755]]]]), None)
"""
head_dim = query.shape[3]
sdp_func_name = _select_sdp(head_dim)
Expand Down Expand Up @@ -339,12 +351,16 @@ def flash_attn_unpadded(
Examples:
.. code-block:: python
>>> # doctest: +SKIP("`is_sm8x || is_sm75` check failed at /paddle/third_party/flashattn/csrc/flash_attn/flash_attn.cpp:293")
>>> import paddle
>>> paddle.seed(1)
>>> q = paddle.rand((1, 128, 2, 16))
>>> output = paddle.nn.functional.flash_attention.flash_attn_unpadded(q, q, q, 0.9, False, False)
>>> paddle.seed(2023)
>>> q = paddle.rand((2, 128, 8, 16), dtype='float16')
>>> cu = paddle.arange(0, 384, 128, dtype='int32')
>>> qq = paddle.reshape(q, [256, 8, 16])
>>> output = paddle.nn.functional.flash_attention.flash_attn_unpadded(qq, qq, qq, cu, cu, 128, 128, 0.25, 0.0, False, False)
>>> print(output)
>>> # doctest: -SKIP
"""
if in_dynamic_mode():
(
Expand Down Expand Up @@ -461,7 +477,7 @@ def scaled_dot_product_attention(
Examples:
.. code-block:: python
>>> # doctest: +SKIP()
>>> # doctest: +SKIP((InvalidArgument) flash_attn(): argument (position 5) must be double, but got NoneType (at ../paddle/fluid/pybind/op_function_common.cc:241))
>>> import paddle
>>> q = paddle.rand((1, 128, 2, 16), dtype=paddle.bfloat16)
>>> output = paddle.nn.functional.scaled_dot_product_attention(q, q, q, None, 0.9, False)
Expand Down
30 changes: 12 additions & 18 deletions python/paddle/quantization/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,10 @@ def add_layer_config(
>>> quanter = FakeQuanterWithAbsMaxObserver(moving_rate=0.9)
>>> q_config = QuantConfig(activation=None, weight=None)
>>> q_config.add_layer_config([model.fc], activation=quanter, weight=quanter)
>>> # doctest: +SKIP
>>> print(q_config)
Global config:
None
Layer prefix config:
{'linear_0': <paddle.quantization.config.SingleLayerConfig object at 0x7fe41a680ee0>}
>>> print(q_config.default_qat_layer_mapping)
{<class 'paddle.nn.quant.stub.Stub'>: <class 'paddle.nn.quant.stub.QuanterStub'>,
<class 'paddle.nn.layer.common.Linear'>: <class 'paddle.nn.quant.qat.linear.QuantedLinear'>,
<class 'paddle.nn.layer.conv.Conv2D'>: <class 'paddle.nn.quant.qat.conv.QuantedConv2D'>}
"""
if isinstance(layer, list):
Expand Down Expand Up @@ -176,12 +174,10 @@ def add_name_config(
>>> 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)
>>> # doctest: +SKIP
>>> print(q_config)
Global config:
None
Layer prefix config:
{'linear_0': <paddle.quantization.config.SingleLayerConfig object at 0x7fe41a680fd0>}
>>> print(q_config.default_qat_layer_mapping)
{<class 'paddle.nn.quant.stub.Stub'>: <class 'paddle.nn.quant.stub.QuanterStub'>,
<class 'paddle.nn.layer.common.Linear'>: <class 'paddle.nn.quant.qat.linear.QuantedLinear'>,
<class 'paddle.nn.layer.conv.Conv2D'>: <class 'paddle.nn.quant.qat.conv.QuantedConv2D'>}
"""
if isinstance(layer_name, str):
Expand Down Expand Up @@ -226,12 +222,10 @@ def add_type_config(
>>> quanter = FakeQuanterWithAbsMaxObserver(moving_rate=0.9)
>>> q_config = QuantConfig(activation=None, weight=None)
>>> q_config.add_type_config([Linear], activation=quanter, weight=quanter)
>>> # doctest: +SKIP
>>> print(q_config)
Global config:
None
Layer type config:
{<class 'paddle.nn.layer.common.Linear'>: <paddle.quantization.config.SingleLayerConfig object at 0x7fe41a680a60>}
>>> print(q_config.default_qat_layer_mapping)
{<class 'paddle.nn.quant.stub.Stub'>: <class 'paddle.nn.quant.stub.QuanterStub'>,
<class 'paddle.nn.layer.common.Linear'>: <class 'paddle.nn.quant.qat.linear.QuantedLinear'>,
<class 'paddle.nn.layer.conv.Conv2D'>: <class 'paddle.nn.quant.qat.conv.QuantedConv2D'>}
"""
if isinstance(layer_type, type) and issubclass(
Expand Down
10 changes: 5 additions & 5 deletions python/paddle/quantization/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@ def quanter(class_name):
Examples:
.. code-block:: python
>>> # doctest: +SKIP
>>> # Given codes in ./customized_quanter.py
>>> from paddle.quantization import QuantConfig
>>> 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
>>> arg1_value = "test"
>>> kwarg1_value = 20
>>> quanter = CustomizedQuanter(arg1_value, kwarg1=kwarg1_value)
>>> q_config = QuantConfig(activation=quanter, weight=quanter)
>>> print(q_config)
Global config:
activation: CustomizedQuanter(test,kwarg1=20)
weight: CustomizedQuanter(test,kwarg1=20)
"""

Expand Down
4 changes: 1 addition & 3 deletions python/paddle/tensor/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1958,14 +1958,12 @@ def slogdet(x, name=None):
>>> import paddle
>>> paddle.seed(2023)
>>> x = paddle.randn([3,3,3])
>>> x = paddle.randn([3, 3, 3])
>>> A = paddle.linalg.slogdet(x)
>>> print(A)
>>> # doctest: +SKIP
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[-1. , 1. , 1. ],
[ 0.25681755, -0.25061053, -0.10809582]])
>>> # doctest: -SKIP
"""
if in_dynamic_mode():
Expand Down

0 comments on commit 2494696

Please sign in to comment.