Skip to content

Commit 40aeba6

Browse files
authored
[Distributed] fix matmul error for Distribute-stable ci (#74989)
* trigger ci * fix matmul with #74945 * disable matmul sinking into c++ * use Decorator to alias * add unit test * comments
1 parent 78d7550 commit 40aeba6

File tree

8 files changed

+578
-269
lines changed

8 files changed

+578
-269
lines changed

paddle/fluid/pir/dialect/op_generator/python_c_gen.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,3 +894,5 @@ def ParseArguments():
894894
python_c_def_h_file,
895895
python_c_def_cc_file,
896896
)
897+
898+
#

paddle/phi/ops/yaml/python_api_info.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
args_alias :
99
use_default_mapping : True
1010

11-
- op : matmul
12-
name : [paddle.matmul,paddle.Tensor.matmul]
13-
args_alias :
14-
use_default_mapping : True
11+
# - op : matmul
12+
# name : [paddle.matmul,paddle.Tensor.matmul]
13+
# args_alias :
14+
# use_default_mapping : True
1515
- op : multiply
1616
name : [paddle.multiply,paddle.Tensor.multiply]
1717
args_alias :

python/paddle/_paddle_docs.py

Lines changed: 105 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -522,111 +522,111 @@ def argmin(
522522
""",
523523
)
524524

525-
add_doc_and_signature(
526-
"matmul",
527-
"""
528-
Applies matrix multiplication to two tensors. `matmul` follows
529-
the complete broadcast rules,
530-
and its behavior is consistent with `np.matmul`.
531-
532-
Currently, the input tensors' number of dimensions can be any, `matmul` can be used to
533-
achieve the `dot`, `matmul` and `batchmatmul`.
534-
535-
The actual behavior depends on the shapes of :math:`x`, :math:`y` and the
536-
flag values of :attr:`transpose_x`, :attr:`transpose_y`. Specifically:
537-
538-
- If a transpose flag is specified, the last two dimensions of the tensor
539-
are transposed. If the tensor is ndim-1 of shape, the transpose is invalid. If the tensor
540-
is ndim-1 of shape :math:`[D]`, then for :math:`x` it is treated as :math:`[1, D]`, whereas
541-
for :math:`y` it is the opposite: It is treated as :math:`[D, 1]`.
542-
543-
The multiplication behavior depends on the dimensions of `x` and `y`. Specifically:
544-
545-
- If both tensors are 1-dimensional, the dot product result is obtained.
546-
547-
- If both tensors are 2-dimensional, the matrix-matrix product is obtained.
548-
549-
- If the `x` is 1-dimensional and the `y` is 2-dimensional,
550-
a `1` is prepended to its dimension in order to conduct the matrix multiply.
551-
After the matrix multiply, the prepended dimension is removed.
552-
553-
- If the `x` is 2-dimensional and `y` is 1-dimensional,
554-
the matrix-vector product is obtained.
555-
556-
- If both arguments are at least 1-dimensional and at least one argument
557-
is N-dimensional (where N > 2), then a batched matrix multiply is obtained.
558-
If the first argument is 1-dimensional, a 1 is prepended to its dimension
559-
in order to conduct the batched matrix multiply and removed after.
560-
If the second argument is 1-dimensional, a 1 is appended to its
561-
dimension for the purpose of the batched matrix multiple and removed after.
562-
The non-matrix (exclude the last two dimensions) dimensions are
563-
broadcasted according the broadcast rule.
564-
For example, if input is a (j, 1, n, m) tensor and the other is a (k, m, p) tensor,
565-
out will be a (j, k, n, p) tensor.
566-
567-
Args:
568-
x (Tensor): The input tensor which is a Tensor.
569-
y (Tensor): The input tensor which is a Tensor.
570-
transpose_x (bool, optional): Whether to transpose :math:`x` before multiplication. Default is False.
571-
transpose_y (bool, optional): Whether to transpose :math:`y` before multiplication. Default is False.
572-
name (str|None, optional): If set None, the layer will be named automatically. For more information, please refer to :ref:`api_guide_Name`. Default is None.
573-
out (Tensor, optional): The output tensor. If set, the result will be stored in this tensor. Default is None.
574-
575-
Returns:
576-
Tensor: The output Tensor.
577-
578-
Examples:
579-
580-
.. code-block:: python
581-
582-
>>> import paddle
583-
584-
>>> # vector * vector
585-
>>> x = paddle.rand([10])
586-
>>> y = paddle.rand([10])
587-
>>> z = paddle.matmul(x, y)
588-
>>> print(z.shape)
589-
[]
590-
591-
>>> # matrix * vector
592-
>>> x = paddle.rand([10, 5])
593-
>>> y = paddle.rand([5])
594-
>>> z = paddle.matmul(x, y)
595-
>>> print(z.shape)
596-
[10]
597-
598-
>>> # batched matrix * broadcasted vector
599-
>>> x = paddle.rand([10, 5, 2])
600-
>>> y = paddle.rand([2])
601-
>>> z = paddle.matmul(x, y)
602-
>>> print(z.shape)
603-
[10, 5]
604-
605-
>>> # batched matrix * batched matrix
606-
>>> x = paddle.rand([10, 5, 2])
607-
>>> y = paddle.rand([10, 2, 5])
608-
>>> z = paddle.matmul(x, y)
609-
>>> print(z.shape)
610-
[10, 5, 5]
611-
612-
>>> # batched matrix * broadcasted matrix
613-
>>> x = paddle.rand([10, 1, 5, 2])
614-
>>> y = paddle.rand([1, 3, 2, 5])
615-
>>> z = paddle.matmul(x, y)
616-
>>> print(z.shape)
617-
[10, 3, 5, 5]
618-
619-
""",
620-
""" def matmul(
621-
x: Tensor,
622-
y: Tensor,
623-
transpose_x: bool = False,
624-
transpose_y: bool = False,
625-
name: str | None = None,
626-
*,
627-
out: Tensor | None = None,
628-
) -> Tensor""",
629-
)
525+
# add_doc_and_signature(
526+
# "matmul",
527+
# """
528+
# Applies matrix multiplication to two tensors. `matmul` follows
529+
# the complete broadcast rules,
530+
# and its behavior is consistent with `np.matmul`.
531+
532+
# Currently, the input tensors' number of dimensions can be any, `matmul` can be used to
533+
# achieve the `dot`, `matmul` and `batchmatmul`.
534+
535+
# The actual behavior depends on the shapes of :math:`x`, :math:`y` and the
536+
# flag values of :attr:`transpose_x`, :attr:`transpose_y`. Specifically:
537+
538+
# - If a transpose flag is specified, the last two dimensions of the tensor
539+
# are transposed. If the tensor is ndim-1 of shape, the transpose is invalid. If the tensor
540+
# is ndim-1 of shape :math:`[D]`, then for :math:`x` it is treated as :math:`[1, D]`, whereas
541+
# for :math:`y` it is the opposite: It is treated as :math:`[D, 1]`.
542+
543+
# The multiplication behavior depends on the dimensions of `x` and `y`. Specifically:
544+
545+
# - If both tensors are 1-dimensional, the dot product result is obtained.
546+
547+
# - If both tensors are 2-dimensional, the matrix-matrix product is obtained.
548+
549+
# - If the `x` is 1-dimensional and the `y` is 2-dimensional,
550+
# a `1` is prepended to its dimension in order to conduct the matrix multiply.
551+
# After the matrix multiply, the prepended dimension is removed.
552+
553+
# - If the `x` is 2-dimensional and `y` is 1-dimensional,
554+
# the matrix-vector product is obtained.
555+
556+
# - If both arguments are at least 1-dimensional and at least one argument
557+
# is N-dimensional (where N > 2), then a batched matrix multiply is obtained.
558+
# If the first argument is 1-dimensional, a 1 is prepended to its dimension
559+
# in order to conduct the batched matrix multiply and removed after.
560+
# If the second argument is 1-dimensional, a 1 is appended to its
561+
# dimension for the purpose of the batched matrix multiple and removed after.
562+
# The non-matrix (exclude the last two dimensions) dimensions are
563+
# broadcasted according the broadcast rule.
564+
# For example, if input is a (j, 1, n, m) tensor and the other is a (k, m, p) tensor,
565+
# out will be a (j, k, n, p) tensor.
566+
567+
# Args:
568+
# x (Tensor): The input tensor which is a Tensor.
569+
# y (Tensor): The input tensor which is a Tensor.
570+
# transpose_x (bool, optional): Whether to transpose :math:`x` before multiplication. Default is False.
571+
# transpose_y (bool, optional): Whether to transpose :math:`y` before multiplication. Default is False.
572+
# name (str|None, optional): If set None, the layer will be named automatically. For more information, please refer to :ref:`api_guide_Name`. Default is None.
573+
# out (Tensor, optional): The output tensor. If set, the result will be stored in this tensor. Default is None.
574+
575+
# Returns:
576+
# Tensor: The output Tensor.
577+
578+
# Examples:
579+
580+
# .. code-block:: python
581+
582+
# >>> import paddle
583+
584+
# >>> # vector * vector
585+
# >>> x = paddle.rand([10])
586+
# >>> y = paddle.rand([10])
587+
# >>> z = paddle.matmul(x, y)
588+
# >>> print(z.shape)
589+
# []
590+
591+
# >>> # matrix * vector
592+
# >>> x = paddle.rand([10, 5])
593+
# >>> y = paddle.rand([5])
594+
# >>> z = paddle.matmul(x, y)
595+
# >>> print(z.shape)
596+
# [10]
597+
598+
# >>> # batched matrix * broadcasted vector
599+
# >>> x = paddle.rand([10, 5, 2])
600+
# >>> y = paddle.rand([2])
601+
# >>> z = paddle.matmul(x, y)
602+
# >>> print(z.shape)
603+
# [10, 5]
604+
605+
# >>> # batched matrix * batched matrix
606+
# >>> x = paddle.rand([10, 5, 2])
607+
# >>> y = paddle.rand([10, 2, 5])
608+
# >>> z = paddle.matmul(x, y)
609+
# >>> print(z.shape)
610+
# [10, 5, 5]
611+
612+
# >>> # batched matrix * broadcasted matrix
613+
# >>> x = paddle.rand([10, 1, 5, 2])
614+
# >>> y = paddle.rand([1, 3, 2, 5])
615+
# >>> z = paddle.matmul(x, y)
616+
# >>> print(z.shape)
617+
# [10, 3, 5, 5]
618+
619+
# """,
620+
# """ def matmul(
621+
# x: Tensor,
622+
# y: Tensor,
623+
# transpose_x: bool = False,
624+
# transpose_y: bool = False,
625+
# name: str | None = None,
626+
# *,
627+
# out: Tensor | None = None,
628+
# ) -> Tensor""",
629+
# )
630630
add_doc_and_signature(
631631
"multiply",
632632
"""

0 commit comments

Comments
 (0)