From 2494696ae4dc815f568f92ffdd9ae326259adfbc Mon Sep 17 00:00:00 2001 From: enkilee Date: Wed, 18 Oct 2023 09:23:12 +0000 Subject: [PATCH 1/5] fix --- .../paddle/nn/functional/flash_attention.py | 26 ++++++++++++---- python/paddle/quantization/config.py | 30 ++++++++----------- python/paddle/quantization/factory.py | 10 +++---- python/paddle/tensor/linalg.py | 4 +-- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/python/paddle/nn/functional/flash_attention.py b/python/paddle/nn/functional/flash_attention.py index 11b85df5d1377..c9d1c4bf4da3c 100644 --- a/python/paddle/nn/functional/flash_attention.py +++ b/python/paddle/nn/functional/flash_attention.py @@ -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) @@ -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(): ( @@ -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) diff --git a/python/paddle/quantization/config.py b/python/paddle/quantization/config.py index 28feb8c6b087f..81a09190c605c 100644 --- a/python/paddle/quantization/config.py +++ b/python/paddle/quantization/config.py @@ -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': } + >>> print(q_config.default_qat_layer_mapping) + {: , + : , + : } """ if isinstance(layer, list): @@ -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': } + >>> print(q_config.default_qat_layer_mapping) + {: , + : , + : } """ if isinstance(layer_name, str): @@ -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: - {: } + >>> print(q_config.default_qat_layer_mapping) + {: , + : , + : } """ if isinstance(layer_type, type) and issubclass( diff --git a/python/paddle/quantization/factory.py b/python/paddle/quantization/factory.py index b0ef906220186..14d00f1034e6f 100644 --- a/python/paddle/quantization/factory.py +++ b/python/paddle/quantization/factory.py @@ -83,8 +83,7 @@ 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") @@ -92,13 +91,14 @@ def quanter(class_name): ... 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) """ diff --git a/python/paddle/tensor/linalg.py b/python/paddle/tensor/linalg.py index 97172e39b5492..8983e4e5fd05b 100644 --- a/python/paddle/tensor/linalg.py +++ b/python/paddle/tensor/linalg.py @@ -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(): From f3e0a537734e8d9e56c36c837fdb3a23a55558c8 Mon Sep 17 00:00:00 2001 From: enkilee Date: Mon, 23 Oct 2023 09:03:26 +0000 Subject: [PATCH 2/5] undo mkldnn --- python/paddle/quantization/config.py | 30 ++++++++++++++++----------- python/paddle/quantization/factory.py | 10 ++++----- python/paddle/tensor/linalg.py | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/python/paddle/quantization/config.py b/python/paddle/quantization/config.py index 81a09190c605c..bafc24488f089 100644 --- a/python/paddle/quantization/config.py +++ b/python/paddle/quantization/config.py @@ -127,10 +127,12 @@ 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) - >>> print(q_config.default_qat_layer_mapping) - {: , - : , - : } + >>> # doctest: +SKIP('random memory address') + >>> print(q_config) + Global config: + None + Layer prefix config: + {'linear_0': } """ if isinstance(layer, list): @@ -174,10 +176,12 @@ 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) - >>> print(q_config.default_qat_layer_mapping) - {: , - : , - : } + >>> # doctest: +SKIP('random memory address') + >>> print(q_config) + Global config: + None + Layer prefix config: + {'linear_0': } """ if isinstance(layer_name, str): @@ -222,10 +226,12 @@ 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) - >>> print(q_config.default_qat_layer_mapping) - {: , - : , - : } + >>> # doctest: +SKIP('random memory address') + >>> print(q_config) + Global config: + None + Layer type config: + {: } """ if isinstance(layer_type, type) and issubclass( diff --git a/python/paddle/quantization/factory.py b/python/paddle/quantization/factory.py index 14d00f1034e6f..eb8916460975c 100644 --- a/python/paddle/quantization/factory.py +++ b/python/paddle/quantization/factory.py @@ -83,7 +83,8 @@ def quanter(class_name): Examples: .. code-block:: python - >>> from paddle.quantization import QuantConfig + >>> # doctest: +SKIP('need 2 file to run example') + >>> # Given codes in ./customized_quanter.py >>> from paddle.quantization import quanter >>> from paddle.quantization import BaseQuanter >>> @quanter("CustomizedQuanter") @@ -91,14 +92,13 @@ def quanter(class_name): ... 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) """ diff --git a/python/paddle/tensor/linalg.py b/python/paddle/tensor/linalg.py index 8983e4e5fd05b..79631ae0e7a60 100644 --- a/python/paddle/tensor/linalg.py +++ b/python/paddle/tensor/linalg.py @@ -1958,7 +1958,7 @@ 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) Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True, From 0b073c4bdbbd4b6204b7d2ced93a9570777b0352 Mon Sep 17 00:00:00 2001 From: enkilee Date: Mon, 23 Oct 2023 09:23:04 +0000 Subject: [PATCH 3/5] fix --- python/paddle/nn/functional/flash_attention.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/python/paddle/nn/functional/flash_attention.py b/python/paddle/nn/functional/flash_attention.py index c9d1c4bf4da3c..6c635851145c8 100644 --- a/python/paddle/nn/functional/flash_attention.py +++ b/python/paddle/nn/functional/flash_attention.py @@ -351,16 +351,13 @@ 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(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(): ( @@ -477,7 +474,7 @@ def scaled_dot_product_attention( Examples: .. code-block:: python - >>> # doctest: +SKIP((InvalidArgument) flash_attn(): argument (position 5) must be double, but got NoneType (at ../paddle/fluid/pybind/op_function_common.cc:241)) + >>> # doctest: +SKIP('bfloat need V100 compile') >>> 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) From 85713fc24f5eb6fdb75b4408c680d1f63de05a72 Mon Sep 17 00:00:00 2001 From: SigureMo Date: Tue, 24 Oct 2023 00:32:12 +0800 Subject: [PATCH 4/5] fix sys msg --- python/paddle/tensor/linalg.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/paddle/tensor/linalg.py b/python/paddle/tensor/linalg.py index 79631ae0e7a60..373938f6c40cd 100644 --- a/python/paddle/tensor/linalg.py +++ b/python/paddle/tensor/linalg.py @@ -2799,10 +2799,12 @@ def eigh(x, UPLO='L', name=None): property. For more information, please refer to :ref:`api_guide_Name`. Returns: + 2-element tuple containing + - out_value(Tensor): A Tensor with shape [*, N] and data type of float32 and float64. - The eigenvalues of eigh op. + The eigenvalues of eigh op. - out_vector(Tensor): A Tensor with shape [*, N, N] and data type of float32,float64, - complex64 and complex128. The eigenvectors of eigh op. + complex64 and complex128. The eigenvectors of eigh op. Examples: .. code-block:: python From 47a1501b27750e5e638df309046c6962956abf3e Mon Sep 17 00:00:00 2001 From: SigureMo Date: Tue, 24 Oct 2023 10:13:36 +0800 Subject: [PATCH 5/5] fix another sys msg --- python/paddle/tensor/linalg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/paddle/tensor/linalg.py b/python/paddle/tensor/linalg.py index 373938f6c40cd..b2f71722d0361 100644 --- a/python/paddle/tensor/linalg.py +++ b/python/paddle/tensor/linalg.py @@ -2801,9 +2801,9 @@ def eigh(x, UPLO='L', name=None): Returns: 2-element tuple containing - - out_value(Tensor): A Tensor with shape [*, N] and data type of float32 and float64. + - out_value(Tensor): A Tensor with shape :math:`[*, N]` and data type of float32 and float64. The eigenvalues of eigh op. - - out_vector(Tensor): A Tensor with shape [*, N, N] and data type of float32,float64, + - out_vector(Tensor): A Tensor with shape :math:`[*, N, N]` and data type of float32, float64, complex64 and complex128. The eigenvectors of eigh op. Examples: