From d0be557f3dcb0ca182af951ab4aea721ef0e466f Mon Sep 17 00:00:00 2001 From: DesmonDay <908660116@qq.com> Date: Wed, 17 Nov 2021 05:32:43 +0000 Subject: [PATCH 1/9] add paddle.incubate.send_recv API doc --- docs/api/paddle/incubate/send_recv_cn.rst | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 docs/api/paddle/incubate/send_recv_cn.rst diff --git a/docs/api/paddle/incubate/send_recv_cn.rst b/docs/api/paddle/incubate/send_recv_cn.rst new file mode 100644 index 00000000000..4b8ba47dc92 --- /dev/null +++ b/docs/api/paddle/incubate/send_recv_cn.rst @@ -0,0 +1,53 @@ +.. _cn_api_incubate_send_recv: + +send_recv +------------------------------- + +.. py:function:: paddle.incubate.send_recv(x, src_index, dst_index, pool_type, name=None) + +此API主要应用于图领域,目的是为了减少在消息传递过程中带来的中间变量显存或内存的损耗。其中,``x``作为输入Tensor,首先利用``src_index``作为索引来gather出在``x``中相应位置的条目,随后再将gather出的结果利用``dst_index``来scatter到对应的输出结果中,其中``pool_type``表示scatter的不同处理方式,包括sum、mean、max、min共计4种处理模式。 + +.. code-block:: text + + X = [[0, 2, 3], + [1, 4, 5], + [2, 6, 7]] + + src_index = [0, 1, 2, 0] + + dst_index = [1, 2, 1, 0] + + pool_type = "sum" + + Then: + + Out = [[0, 2, 3], + [2, 8, 10], + [1, 4, 5]] + +参数 +::::::::: + - x (Tensor) - 输入的 Tensor,数据类型为:float32、float64、int32、int64。 + - src_index (Tensor) - 1-D Tensor,数据类型为:int32、int64。 + - dst_index (Tensor) - 1-D Tensor,数据类型为:int32、int64。注意:``dst_index``的形状应当与``src_index``一致。 + - pool_type (str) - scatter结果的不同处理方式,包括sum、mean、max、min。 + - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref: `api_guide_Name` 。 + +返回 +::::::::: +``Tensor``,维度和数据类型都与 ``x`` 相同,存储运算后的结果。 + + +代码示例 +:::::::::: + +.. code-block:: python + + import paddle + import numpy as np + x = paddle.to_tensor(np.array([[0, 2, 3], [1, 4, 5], [2, 6, 7]]), dtype="float32") + indexes = paddle.to_tensor(np.array([[0, 1], [1, 2], [2, 1], [0, 0]]), dtype="int32") + src_index = indexes[:, 0] + dst_index = indexes[:, 1] + out = paddle.incubate.send_recv(x, src_index, dst_index, pool_type="sum") + # Outputs: [[0., 2., 3.], [2., 8., 10.], [1., 4., 5.]] From dff6826b8285a7ffda0fbb2091f8cb2778f47336 Mon Sep 17 00:00:00 2001 From: DesmonDay <908660116@qq.com> Date: Wed, 17 Nov 2021 06:06:45 +0000 Subject: [PATCH 2/9] add default value of pool_type --- docs/api/paddle/incubate/send_recv_cn.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/paddle/incubate/send_recv_cn.rst b/docs/api/paddle/incubate/send_recv_cn.rst index 4b8ba47dc92..29d4eb1b4c1 100644 --- a/docs/api/paddle/incubate/send_recv_cn.rst +++ b/docs/api/paddle/incubate/send_recv_cn.rst @@ -3,7 +3,7 @@ send_recv ------------------------------- -.. py:function:: paddle.incubate.send_recv(x, src_index, dst_index, pool_type, name=None) +.. py:function:: paddle.incubate.send_recv(x, src_index, dst_index, pool_type=sum, name=None) 此API主要应用于图领域,目的是为了减少在消息传递过程中带来的中间变量显存或内存的损耗。其中,``x``作为输入Tensor,首先利用``src_index``作为索引来gather出在``x``中相应位置的条目,随后再将gather出的结果利用``dst_index``来scatter到对应的输出结果中,其中``pool_type``表示scatter的不同处理方式,包括sum、mean、max、min共计4种处理模式。 @@ -30,7 +30,7 @@ send_recv - x (Tensor) - 输入的 Tensor,数据类型为:float32、float64、int32、int64。 - src_index (Tensor) - 1-D Tensor,数据类型为:int32、int64。 - dst_index (Tensor) - 1-D Tensor,数据类型为:int32、int64。注意:``dst_index``的形状应当与``src_index``一致。 - - pool_type (str) - scatter结果的不同处理方式,包括sum、mean、max、min。 + - pool_type (str) - scatter结果的不同处理方式,包括sum、mean、max、min。 默认值为 sum。 - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref: `api_guide_Name` 。 返回 From d8212ac5cbcdd26e216597173efbc9a3a850b5ce Mon Sep 17 00:00:00 2001 From: DesmonDay <908660116@qq.com> Date: Wed, 17 Nov 2021 06:07:49 +0000 Subject: [PATCH 3/9] fix default value of pool_type --- docs/api/paddle/incubate/send_recv_cn.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/paddle/incubate/send_recv_cn.rst b/docs/api/paddle/incubate/send_recv_cn.rst index 29d4eb1b4c1..2a4362c3476 100644 --- a/docs/api/paddle/incubate/send_recv_cn.rst +++ b/docs/api/paddle/incubate/send_recv_cn.rst @@ -3,7 +3,7 @@ send_recv ------------------------------- -.. py:function:: paddle.incubate.send_recv(x, src_index, dst_index, pool_type=sum, name=None) +.. py:function:: paddle.incubate.send_recv(x, src_index, dst_index, pool_type="sum", name=None) 此API主要应用于图领域,目的是为了减少在消息传递过程中带来的中间变量显存或内存的损耗。其中,``x``作为输入Tensor,首先利用``src_index``作为索引来gather出在``x``中相应位置的条目,随后再将gather出的结果利用``dst_index``来scatter到对应的输出结果中,其中``pool_type``表示scatter的不同处理方式,包括sum、mean、max、min共计4种处理模式。 From a83c5a2f714c64872373f01a86069b3effcd935d Mon Sep 17 00:00:00 2001 From: DesmonDay <908660116@qq.com> Date: Wed, 17 Nov 2021 06:51:40 +0000 Subject: [PATCH 4/9] change import --- docs/api/paddle/incubate/send_recv_cn.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/paddle/incubate/send_recv_cn.rst b/docs/api/paddle/incubate/send_recv_cn.rst index 2a4362c3476..41232969dd1 100644 --- a/docs/api/paddle/incubate/send_recv_cn.rst +++ b/docs/api/paddle/incubate/send_recv_cn.rst @@ -43,8 +43,8 @@ send_recv .. code-block:: python - import paddle import numpy as np + import paddle x = paddle.to_tensor(np.array([[0, 2, 3], [1, 4, 5], [2, 6, 7]]), dtype="float32") indexes = paddle.to_tensor(np.array([[0, 1], [1, 2], [2, 1], [0, 0]]), dtype="int32") src_index = indexes[:, 0] From b92245012629e6d80ea82a5122afbf1246c62777 Mon Sep 17 00:00:00 2001 From: DesmonDay <908660116@qq.com> Date: Wed, 17 Nov 2021 07:33:06 +0000 Subject: [PATCH 5/9] change intro --- docs/api/paddle/incubate/send_recv_cn.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/api/paddle/incubate/send_recv_cn.rst b/docs/api/paddle/incubate/send_recv_cn.rst index 41232969dd1..6c366fb3c85 100644 --- a/docs/api/paddle/incubate/send_recv_cn.rst +++ b/docs/api/paddle/incubate/send_recv_cn.rst @@ -5,7 +5,7 @@ send_recv .. py:function:: paddle.incubate.send_recv(x, src_index, dst_index, pool_type="sum", name=None) -此API主要应用于图领域,目的是为了减少在消息传递过程中带来的中间变量显存或内存的损耗。其中,``x``作为输入Tensor,首先利用``src_index``作为索引来gather出在``x``中相应位置的条目,随后再将gather出的结果利用``dst_index``来scatter到对应的输出结果中,其中``pool_type``表示scatter的不同处理方式,包括sum、mean、max、min共计4种处理模式。 +此API主要应用于图学习领域,目的是为了减少在消息传递过程中带来的中间变量显存或内存的损耗。其中,``x``作为输入Tensor,首先利用``src_index``作为索引来gather出在``x``中相应位置的数据,随后再将gather出的结果利用``dst_index``来scatter到对应的输出结果中,其中``pool_type``表示scatter的不同处理方式,包括sum、mean、max、min共计4种处理模式。 .. code-block:: text @@ -45,6 +45,7 @@ send_recv import numpy as np import paddle + x = paddle.to_tensor(np.array([[0, 2, 3], [1, 4, 5], [2, 6, 7]]), dtype="float32") indexes = paddle.to_tensor(np.array([[0, 1], [1, 2], [2, 1], [0, 0]]), dtype="int32") src_index = indexes[:, 0] From d9041e753b502543a3a7bb13363deaad27e8af5a Mon Sep 17 00:00:00 2001 From: DesmonDay <908660116@qq.com> Date: Wed, 17 Nov 2021 07:43:58 +0000 Subject: [PATCH 6/9] fix bug in api --- docs/api/paddle/incubate/send_recv_cn.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/paddle/incubate/send_recv_cn.rst b/docs/api/paddle/incubate/send_recv_cn.rst index 6c366fb3c85..97f00168bab 100644 --- a/docs/api/paddle/incubate/send_recv_cn.rst +++ b/docs/api/paddle/incubate/send_recv_cn.rst @@ -31,7 +31,7 @@ send_recv - src_index (Tensor) - 1-D Tensor,数据类型为:int32、int64。 - dst_index (Tensor) - 1-D Tensor,数据类型为:int32、int64。注意:``dst_index``的形状应当与``src_index``一致。 - pool_type (str) - scatter结果的不同处理方式,包括sum、mean、max、min。 默认值为 sum。 - - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref: `api_guide_Name` 。 + - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 返回 ::::::::: From 319a5779a379597f8d3c1a75e6a692748e5e6d90 Mon Sep 17 00:00:00 2001 From: DesmonDay <908660116@qq.com> Date: Wed, 17 Nov 2021 09:22:33 +0000 Subject: [PATCH 7/9] fix display bug --- docs/api/paddle/incubate/send_recv_cn.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api/paddle/incubate/send_recv_cn.rst b/docs/api/paddle/incubate/send_recv_cn.rst index 97f00168bab..f998c1df0c4 100644 --- a/docs/api/paddle/incubate/send_recv_cn.rst +++ b/docs/api/paddle/incubate/send_recv_cn.rst @@ -5,7 +5,7 @@ send_recv .. py:function:: paddle.incubate.send_recv(x, src_index, dst_index, pool_type="sum", name=None) -此API主要应用于图学习领域,目的是为了减少在消息传递过程中带来的中间变量显存或内存的损耗。其中,``x``作为输入Tensor,首先利用``src_index``作为索引来gather出在``x``中相应位置的数据,随后再将gather出的结果利用``dst_index``来scatter到对应的输出结果中,其中``pool_type``表示scatter的不同处理方式,包括sum、mean、max、min共计4种处理模式。 +此API主要应用于图学习领域,目的是为了减少在消息传递过程中带来的中间变量显存或内存的损耗。其中, ``x`` 作为输入Tensor,首先利用 ``src_index`` 作为索引来gather出在 ``x`` 中相应位置的数据,随后再将gather出的结果利用 ``dst_index`` 来scatter到对应的输出结果中,其中 ``pool_type`` 表示scatter的不同处理方式,包括sum、mean、max、min共计4种处理模式。 .. code-block:: text @@ -29,13 +29,13 @@ send_recv ::::::::: - x (Tensor) - 输入的 Tensor,数据类型为:float32、float64、int32、int64。 - src_index (Tensor) - 1-D Tensor,数据类型为:int32、int64。 - - dst_index (Tensor) - 1-D Tensor,数据类型为:int32、int64。注意:``dst_index``的形状应当与``src_index``一致。 + - dst_index (Tensor) - 1-D Tensor,数据类型为:int32、int64。注意: ``dst_index`` 的形状应当与 ``src_index`` 一致。 - pool_type (str) - scatter结果的不同处理方式,包括sum、mean、max、min。 默认值为 sum。 - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name` 。 返回 ::::::::: -``Tensor``,维度和数据类型都与 ``x`` 相同,存储运算后的结果。 +``Tensor`` ,维度和数据类型都与 ``x`` 相同,存储运算后的结果。 代码示例 From 3ceb8b40b2201559d88f400c82b77aa33750b61c Mon Sep 17 00:00:00 2001 From: DesmonDay <908660116@qq.com> Date: Wed, 17 Nov 2021 13:35:02 +0000 Subject: [PATCH 8/9] modify wording --- docs/api/paddle/incubate/send_recv_cn.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/paddle/incubate/send_recv_cn.rst b/docs/api/paddle/incubate/send_recv_cn.rst index f998c1df0c4..712b61e3fa2 100644 --- a/docs/api/paddle/incubate/send_recv_cn.rst +++ b/docs/api/paddle/incubate/send_recv_cn.rst @@ -5,7 +5,7 @@ send_recv .. py:function:: paddle.incubate.send_recv(x, src_index, dst_index, pool_type="sum", name=None) -此API主要应用于图学习领域,目的是为了减少在消息传递过程中带来的中间变量显存或内存的损耗。其中, ``x`` 作为输入Tensor,首先利用 ``src_index`` 作为索引来gather出在 ``x`` 中相应位置的数据,随后再将gather出的结果利用 ``dst_index`` 来scatter到对应的输出结果中,其中 ``pool_type`` 表示scatter的不同处理方式,包括sum、mean、max、min共计4种处理模式。 +此API主要应用于图学习领域,目的是为了减少在消息传递过程中带来的中间变量显存或内存的损耗。其中, ``x`` 作为输入Tensor,首先利用 ``src_index`` 作为索引来gather出在 ``x`` 中相应位置的数据,随后再将gather出的结果利用 ``dst_index`` 来更新到对应的输出结果中,其中 ``pool_type`` 表示不同的更新方式,包括sum、mean、max、min共计4种处理模式。 .. code-block:: text From dc18987b4e38de763dfa617d6993728c2e4b849f Mon Sep 17 00:00:00 2001 From: DesmonDay <908660116@qq.com> Date: Tue, 23 Nov 2021 03:09:40 +0000 Subject: [PATCH 9/9] mv send_recv to graph_send_recv --- .../{send_recv_cn.rst => graph_send_recv_cn.rst} | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) rename docs/api/paddle/incubate/{send_recv_cn.rst => graph_send_recv_cn.rst} (79%) diff --git a/docs/api/paddle/incubate/send_recv_cn.rst b/docs/api/paddle/incubate/graph_send_recv_cn.rst similarity index 79% rename from docs/api/paddle/incubate/send_recv_cn.rst rename to docs/api/paddle/incubate/graph_send_recv_cn.rst index 712b61e3fa2..22940d94ddb 100644 --- a/docs/api/paddle/incubate/send_recv_cn.rst +++ b/docs/api/paddle/incubate/graph_send_recv_cn.rst @@ -1,9 +1,9 @@ -.. _cn_api_incubate_send_recv: +.. _cn_api_incubate_graph_send_recv: -send_recv +graph_send_recv ------------------------------- -.. py:function:: paddle.incubate.send_recv(x, src_index, dst_index, pool_type="sum", name=None) +.. py:function:: paddle.incubate.graph_send_recv(x, src_index, dst_index, pool_type="sum", name=None) 此API主要应用于图学习领域,目的是为了减少在消息传递过程中带来的中间变量显存或内存的损耗。其中, ``x`` 作为输入Tensor,首先利用 ``src_index`` 作为索引来gather出在 ``x`` 中相应位置的数据,随后再将gather出的结果利用 ``dst_index`` 来更新到对应的输出结果中,其中 ``pool_type`` 表示不同的更新方式,包括sum、mean、max、min共计4种处理模式。 @@ -43,12 +43,11 @@ send_recv .. code-block:: python - import numpy as np import paddle - x = paddle.to_tensor(np.array([[0, 2, 3], [1, 4, 5], [2, 6, 7]]), dtype="float32") - indexes = paddle.to_tensor(np.array([[0, 1], [1, 2], [2, 1], [0, 0]]), dtype="int32") + x = paddle.to_tensor([[0, 2, 3], [1, 4, 5], [2, 6, 7]], dtype="float32") + indexes = paddle.to_tensor([[0, 1], [1, 2], [2, 1], [0, 0]], dtype="int32") src_index = indexes[:, 0] dst_index = indexes[:, 1] - out = paddle.incubate.send_recv(x, src_index, dst_index, pool_type="sum") + out = paddle.incubate.graph_send_recv(x, src_index, dst_index, pool_type="sum") # Outputs: [[0., 2., 3.], [2., 8., 10.], [1., 4., 5.]]