From 96bdbf09699c359c9539807bf566309e83746a5e Mon Sep 17 00:00:00 2001 From: enkilee Date: Mon, 25 Mar 2024 11:04:20 +0800 Subject: [PATCH 01/16] fix --- .../pir/dialect/op_generator/ops_api_gen.py | 2 ++ paddle/fluid/pir/dialect/operator/ir/ops.yaml | 12 ++++++++ .../fluid/pir/dialect/operator/utils/utils.cc | 1 + paddle/phi/api/yaml/op_compat.yaml | 4 +++ paddle/phi/infermeta/binary.cc | 29 +++++++++++++++++++ paddle/phi/infermeta/binary.h | 7 +++++ 6 files changed, 55 insertions(+) diff --git a/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py b/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py index ea942648685ed..0f3afbad0a18c 100644 --- a/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py +++ b/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py @@ -194,6 +194,8 @@ 'nop_', 'limit_by_capacity', 'global_scatter', + 'pull_box_sparse', + 'pull_box_sparse_', ] diff --git a/paddle/fluid/pir/dialect/operator/ir/ops.yaml b/paddle/fluid/pir/dialect/operator/ir/ops.yaml index de64ca2f98a95..32880f83add4b 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ops.yaml +++ b/paddle/fluid/pir/dialect/operator/ir/ops.yaml @@ -1303,6 +1303,18 @@ func : prune_gate_by_capacity data_type : gate_idx +- op : pull_box_sparse + args : (Tensor w, Tensor[] ids, bool is_sparse = false, bool is_distributed = false, int size = 1) + output : Tensor[](out){ids.size()} + infer_meta : + func : PullBoxSparseInferMeta + param : [ids, w, is_sparse, is_distributed, size] + kernel : + func : pull_box_sparse + param : [ids, w, is_sparse, is_distributed, size] + data_type : ids + optional : w + - op : push_sparse_v2 args : (Tensor[] ids, Tensor[] w, Tensor[] out_grad_in, int embeddingdim = 11, int tableid = 0, str accessorclass = "", str ctrlabelname = "", int paddingid = 0, bool scalesparsegrad = true, str[] inputnames = {}, bool is_distributed = true) output : Tensor[](out_grad_out){out_grad_in.size()} diff --git a/paddle/fluid/pir/dialect/operator/utils/utils.cc b/paddle/fluid/pir/dialect/operator/utils/utils.cc index 85aa330faa73a..9ede98af721f0 100644 --- a/paddle/fluid/pir/dialect/operator/utils/utils.cc +++ b/paddle/fluid/pir/dialect/operator/utils/utils.cc @@ -103,6 +103,7 @@ const std::unordered_set LegacyOpList = { CReduceMinOp::name(), CReduceProdOp::name(), CScatterOp::name(), + PullBoxSparseOp::name(), PushSparseV2Op::name(), PartialSendOp::name(), PartialRecvOp::name()}; diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 0c3f7488362eb..5ea2110998710 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -2641,6 +2641,10 @@ outputs : out : Out +- op : pull_box_sparse + inputs : + { w : W, ids: Ids} + - op : push_sparse_v2 inputs : { x : Ids, W : w} diff --git a/paddle/phi/infermeta/binary.cc b/paddle/phi/infermeta/binary.cc index 97edce9ad7953..e70a2a967fb6d 100644 --- a/paddle/phi/infermeta/binary.cc +++ b/paddle/phi/infermeta/binary.cc @@ -2893,6 +2893,35 @@ void PruneGateByCapacityInferMeta(const MetaTensor& gate_idx, new_gate_idx->set_dtype(gate_idx.dtype()); } +void PullBoxSparseInferMeta(const std::vector& ids, + const MetaTensor& w, + bool is_sparse, + bool is_distributed, + int size, + std::vector out) { + auto hidden_size = static_cast(size); + auto all_ids_dim = ids[0]->dims(); + const size_t n_ids = ids.size(); + std::vector outs_dims; + outs_dims.resize(n_ids); + for (size_t i = 0; i < n_ids; ++i) { + MetaTensor* output = out[i]; + auto ids_dims = ids[i]->dims(); + int ids_rank = ids[i].size(); + PADDLE_ENFORCE_EQ(ids_dims[ids_rank - 1], + 1, + platform::errors::InvalidArgument( + "Shape error in %lu id, the last dimension of the " + "'Ids' tensor must be 1.", + i)); + auto out_dim = + common::vectorize(common::slice_ddim(ids_dims, 0, ids_rank - 1)); + out_dim.push_back(hidden_size); + output->set_dims(common::make_ddim(out_dim)); + output->share_lod(*ids[i]); + } +} + void RepeatInterleaveWithTensorIndexInferMeta(const MetaTensor& x, const MetaTensor& repeats, int dim, diff --git a/paddle/phi/infermeta/binary.h b/paddle/phi/infermeta/binary.h index 77bc925197013..234dae40d68f9 100644 --- a/paddle/phi/infermeta/binary.h +++ b/paddle/phi/infermeta/binary.h @@ -469,6 +469,13 @@ void PReluInferMeta(const MetaTensor& x, MetaTensor* out, MetaConfig config = MetaConfig()); +void PullBoxSparseInferMeta(const std::vector& ids, + const MetaTensor& w, + bool is_sparse, + bool is_distributed, + int size, + std::vector out); + void RepeatInterleaveWithTensorIndexInferMeta(const MetaTensor& x, const MetaTensor& repeats, int dim, From 321d9321aebb7caae9aa09e1bc1414e45b04a3c7 Mon Sep 17 00:00:00 2001 From: enkilee Date: Mon, 25 Mar 2024 15:12:11 +0800 Subject: [PATCH 02/16] fix --- paddle/phi/infermeta/binary.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/phi/infermeta/binary.cc b/paddle/phi/infermeta/binary.cc index e70a2a967fb6d..ea9688b6fabf1 100644 --- a/paddle/phi/infermeta/binary.cc +++ b/paddle/phi/infermeta/binary.cc @@ -2909,8 +2909,8 @@ void PullBoxSparseInferMeta(const std::vector& ids, auto ids_dims = ids[i]->dims(); int ids_rank = ids[i].size(); PADDLE_ENFORCE_EQ(ids_dims[ids_rank - 1], - 1, - platform::errors::InvalidArgument( + 1UL, + phi::errors::InvalidArgument( "Shape error in %lu id, the last dimension of the " "'Ids' tensor must be 1.", i)); From 43b1dd1b0e467cee8b15d774525a7a5d346e4502 Mon Sep 17 00:00:00 2001 From: enkilee Date: Mon, 25 Mar 2024 15:57:51 +0800 Subject: [PATCH 03/16] fix --- paddle/phi/infermeta/binary.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/paddle/phi/infermeta/binary.cc b/paddle/phi/infermeta/binary.cc index ea9688b6fabf1..3cf4c4f7e25da 100644 --- a/paddle/phi/infermeta/binary.cc +++ b/paddle/phi/infermeta/binary.cc @@ -2902,12 +2902,10 @@ void PullBoxSparseInferMeta(const std::vector& ids, auto hidden_size = static_cast(size); auto all_ids_dim = ids[0]->dims(); const size_t n_ids = ids.size(); - std::vector outs_dims; - outs_dims.resize(n_ids); for (size_t i = 0; i < n_ids; ++i) { MetaTensor* output = out[i]; auto ids_dims = ids[i]->dims(); - int ids_rank = ids[i].size(); + int ids_rank = ids_dims.size(); PADDLE_ENFORCE_EQ(ids_dims[ids_rank - 1], 1UL, phi::errors::InvalidArgument( From 29930836eefb8d2f3208d585716161b375290434 Mon Sep 17 00:00:00 2001 From: enkilee Date: Mon, 25 Mar 2024 17:03:01 +0800 Subject: [PATCH 04/16] fix --- paddle/phi/infermeta/binary.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/paddle/phi/infermeta/binary.cc b/paddle/phi/infermeta/binary.cc index 3cf4c4f7e25da..e781d8b4ef2c3 100644 --- a/paddle/phi/infermeta/binary.cc +++ b/paddle/phi/infermeta/binary.cc @@ -2900,7 +2900,6 @@ void PullBoxSparseInferMeta(const std::vector& ids, int size, std::vector out) { auto hidden_size = static_cast(size); - auto all_ids_dim = ids[0]->dims(); const size_t n_ids = ids.size(); for (size_t i = 0; i < n_ids; ++i) { MetaTensor* output = out[i]; From 2e7182afaa9c362f18a0a66b7f306f47c9821936 Mon Sep 17 00:00:00 2001 From: enkilee Date: Tue, 26 Mar 2024 09:20:08 +0800 Subject: [PATCH 05/16] fix --- paddle/phi/api/yaml/op_compat.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 5ea2110998710..d052357d39873 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -2644,6 +2644,12 @@ - op : pull_box_sparse inputs : { w : W, ids: Ids} + outputs : + out : Out + attrs : + sparse : is_sparse + extra : + attrs : [bool is_sparse = false, bool is_distributed = false, int size = 1] - op : push_sparse_v2 inputs : From 5ec6c54c6085799e16c97b7b00f03ac91bdb3fff Mon Sep 17 00:00:00 2001 From: enkilee Date: Tue, 26 Mar 2024 10:15:17 +0800 Subject: [PATCH 06/16] fix --- paddle/fluid/pir/dialect/operator/ir/ops.yaml | 3 --- paddle/phi/infermeta/binary.cc | 4 ++-- paddle/phi/infermeta/binary.h | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/pir/dialect/operator/ir/ops.yaml b/paddle/fluid/pir/dialect/operator/ir/ops.yaml index 32880f83add4b..d20b99a5cd5ab 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ops.yaml +++ b/paddle/fluid/pir/dialect/operator/ir/ops.yaml @@ -1308,12 +1308,9 @@ output : Tensor[](out){ids.size()} infer_meta : func : PullBoxSparseInferMeta - param : [ids, w, is_sparse, is_distributed, size] kernel : func : pull_box_sparse - param : [ids, w, is_sparse, is_distributed, size] data_type : ids - optional : w - op : push_sparse_v2 args : (Tensor[] ids, Tensor[] w, Tensor[] out_grad_in, int embeddingdim = 11, int tableid = 0, str accessorclass = "", str ctrlabelname = "", int paddingid = 0, bool scalesparsegrad = true, str[] inputnames = {}, bool is_distributed = true) diff --git a/paddle/phi/infermeta/binary.cc b/paddle/phi/infermeta/binary.cc index e781d8b4ef2c3..38563b24e0f59 100644 --- a/paddle/phi/infermeta/binary.cc +++ b/paddle/phi/infermeta/binary.cc @@ -2893,8 +2893,8 @@ void PruneGateByCapacityInferMeta(const MetaTensor& gate_idx, new_gate_idx->set_dtype(gate_idx.dtype()); } -void PullBoxSparseInferMeta(const std::vector& ids, - const MetaTensor& w, +void PullBoxSparseInferMeta(const MetaTensor& w, + const std::vector& ids, bool is_sparse, bool is_distributed, int size, diff --git a/paddle/phi/infermeta/binary.h b/paddle/phi/infermeta/binary.h index 234dae40d68f9..99f3bae68d931 100644 --- a/paddle/phi/infermeta/binary.h +++ b/paddle/phi/infermeta/binary.h @@ -469,8 +469,8 @@ void PReluInferMeta(const MetaTensor& x, MetaTensor* out, MetaConfig config = MetaConfig()); -void PullBoxSparseInferMeta(const std::vector& ids, - const MetaTensor& w, +void PullBoxSparseInferMeta(const MetaTensor& w, + const std::vector& ids, bool is_sparse, bool is_distributed, int size, From 476c1cf58c1beaf15eb62659fc46a7dab786d088 Mon Sep 17 00:00:00 2001 From: enkilee Date: Tue, 26 Mar 2024 13:33:09 +0800 Subject: [PATCH 07/16] add test --- test/ir/pir/translator/CMakeLists.txt | 1 + .../test_pull_box_sparse_translator.py | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/ir/pir/translator/test_pull_box_sparse_translator.py diff --git a/test/ir/pir/translator/CMakeLists.txt b/test/ir/pir/translator/CMakeLists.txt index 04db2d4748ead..19f638b585f31 100644 --- a/test/ir/pir/translator/CMakeLists.txt +++ b/test/ir/pir/translator/CMakeLists.txt @@ -25,6 +25,7 @@ list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_partial_send_translator) list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_partial_recv_translator) list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_prune_gate_by_capacity_translator) +list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_pull_box_sparse_translator) list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_random_routing_translator) list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_limit_by_capacity_translator) list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_global_scatter_translator) diff --git a/test/ir/pir/translator/test_pull_box_sparse_translator.py b/test/ir/pir/translator/test_pull_box_sparse_translator.py new file mode 100644 index 0000000000000..9551d65bf6b01 --- /dev/null +++ b/test/ir/pir/translator/test_pull_box_sparse_translator.py @@ -0,0 +1,47 @@ +# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +import test_op_translator + +import paddle +from paddle.base.layer_helper import LayerHelper + + +class TestPullBoxSparseOpTranslator(test_op_translator.TestOpTranslator): + def append_op(self): + self.op_type = "pull_box_sparse" + ids = paddle.ones(shape=(1, 1), dtype='float32') + w = paddle.ones(shape=(1, 1), dtype='float32') + out = paddle.ones(shape=(1, 1), dtype='float32') + attrs = { + 'is_sparse': False, + 'is_distributed': False, + 'size': 1, + } + helper = LayerHelper(self.op_type) + helper.append_op( + type=self.op_type, + inputs={"W": w, "Ids": [ids]}, + outputs={"Out": [out]}, + attrs=attrs, + ) + + def test_translator(self): + self.check() + + +if __name__ == "__main__": + unittest.main() From 3330aeb31fa53513447ab737942bac54d6ba875c Mon Sep 17 00:00:00 2001 From: enkilee Date: Fri, 29 Mar 2024 11:43:40 +0800 Subject: [PATCH 08/16] add --- paddle/fluid/ir_adaptor/translator/op_compat_gen.py | 3 +++ paddle/fluid/pir/dialect/op_generator/ops_api_gen.py | 2 ++ paddle/fluid/pir/dialect/operator/ir/ops.yaml | 11 +++++++++++ paddle/fluid/pir/dialect/operator/utils/utils.cc | 1 + paddle/phi/api/yaml/op_compat.yaml | 10 ++++++++++ 5 files changed, 27 insertions(+) diff --git a/paddle/fluid/ir_adaptor/translator/op_compat_gen.py b/paddle/fluid/ir_adaptor/translator/op_compat_gen.py index 6d151b48cea19..7e15af37509d7 100644 --- a/paddle/fluid/ir_adaptor/translator/op_compat_gen.py +++ b/paddle/fluid/ir_adaptor/translator/op_compat_gen.py @@ -168,6 +168,9 @@ def insert_new_mutable_attributes( op_arg_name_mappings['push_sparse_v2'].update( {"out_grad_in": "Out@GRAD", "out_grad_out": "Out@GRAD"} ) + op_arg_name_mappings['push_box_sparse'].update( + {"out_grad_in": "Out@GRAD", "out_grad_out": "Out@GRAD"} + ) op_name_normalizer_template = env.get_template("op_compat_info.cc.j2") with open(output_source_file, 'wt') as f: diff --git a/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py b/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py index 7c974205dabaf..1ff8858bad9ea 100644 --- a/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py +++ b/paddle/fluid/pir/dialect/op_generator/ops_api_gen.py @@ -197,6 +197,8 @@ 'global_scatter', 'pull_box_sparse', 'pull_box_sparse_', + 'push_box_sparse', + 'push_box_sparse_', ] diff --git a/paddle/fluid/pir/dialect/operator/ir/ops.yaml b/paddle/fluid/pir/dialect/operator/ir/ops.yaml index 93b094f3c86f8..bb44d1da65d0e 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ops.yaml +++ b/paddle/fluid/pir/dialect/operator/ir/ops.yaml @@ -1314,6 +1314,17 @@ func : pull_box_sparse data_type : ids +- op : push_box_sparse + args : (Tensor[] ids, Tensor[] out_grad_in, bool is_sparse = false, bool is_distributed = false, int size = 1) + output : Tensor[](out_grad_out){out_grad_in.size()} + infer_meta : + func : UnchangedMultiInferMeta + param : [out_grad_in] + kernel : + func : push_box_sparse + data_type : out_grad_in + inplace : (out_grad_in -> out_grad_out) + - op : push_dense args : (Tensor[] ids, int table_id = -1, float scale_data_norm = -1.0f, str[] input_names = {}) output : diff --git a/paddle/fluid/pir/dialect/operator/utils/utils.cc b/paddle/fluid/pir/dialect/operator/utils/utils.cc index c0cabf0c9507e..2a4f66cce1f7c 100644 --- a/paddle/fluid/pir/dialect/operator/utils/utils.cc +++ b/paddle/fluid/pir/dialect/operator/utils/utils.cc @@ -105,6 +105,7 @@ const std::unordered_set LegacyOpList = { CReduceProdOp::name(), CScatterOp::name(), PullBoxSparseOp::name(), + PushBoxSparseOp::name(), PushSparseV2Op::name(), PartialSendOp::name(), PartialRecvOp::name()}; diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index b229665a47feb..4f0cc2c0efc7b 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -2651,6 +2651,16 @@ extra : attrs : [bool is_sparse = false, bool is_distributed = false, int size = 1] +- op : push_box_sparse + inputs : + ids: Ids + outputs : + out : Out + attrs : + sparse : is_sparse + extra : + attrs : [bool is_sparse = false, bool is_distributed = false, int size = 1] + - op : push_dense inputs : ids : Ids From 577947484d0c1e37c3bb7ead3988a0e435e5fc57 Mon Sep 17 00:00:00 2001 From: enkilee Date: Tue, 9 Apr 2024 08:58:13 +0800 Subject: [PATCH 09/16] fix --- paddle/phi/api/yaml/op_compat.yaml | 2 -- .../test_pull_box_sparse_translator.py | 20 ++++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 4f0cc2c0efc7b..dab829f8e56dd 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -2658,8 +2658,6 @@ out : Out attrs : sparse : is_sparse - extra : - attrs : [bool is_sparse = false, bool is_distributed = false, int size = 1] - op : push_dense inputs : diff --git a/test/ir/pir/translator/test_pull_box_sparse_translator.py b/test/ir/pir/translator/test_pull_box_sparse_translator.py index 9551d65bf6b01..f41a7177b780a 100644 --- a/test/ir/pir/translator/test_pull_box_sparse_translator.py +++ b/test/ir/pir/translator/test_pull_box_sparse_translator.py @@ -20,9 +20,12 @@ from paddle.base.layer_helper import LayerHelper -class TestPullBoxSparseOpTranslator(test_op_translator.TestOpTranslator): +class TestPullBoxSparseOpTranslator( + test_op_translator.TestOpWithBackwardTranslator +): def append_op(self): - self.op_type = "pull_box_sparse" + self.forward_op_type = "pull_box_sparse" + self.backward_op_type = "push_box_sparse" ids = paddle.ones(shape=(1, 1), dtype='float32') w = paddle.ones(shape=(1, 1), dtype='float32') out = paddle.ones(shape=(1, 1), dtype='float32') @@ -31,13 +34,20 @@ def append_op(self): 'is_distributed': False, 'size': 1, } - helper = LayerHelper(self.op_type) - helper.append_op( - type=self.op_type, + forward_helper = LayerHelper(self.forward_op_type) + forward_helper.append_op( + type=self.forward_op_type, inputs={"W": w, "Ids": [ids]}, outputs={"Out": [out]}, attrs=attrs, ) + backward_helper = LayerHelper(self.backward_op_type) + backward_helper.append_op( + type=self.backward_op_type, + inputs={"Ids": [ids]}, + outputs={"Out": [out]}, + attrs=attrs, + ) def test_translator(self): self.check() From 3ec0d6d6b481cb84609bcf06cad1c0aae4bedd0f Mon Sep 17 00:00:00 2001 From: enkilee Date: Mon, 15 Apr 2024 10:19:51 +0800 Subject: [PATCH 10/16] fix --- test/ir/pir/translator/test_pull_box_sparse_translator.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/ir/pir/translator/test_pull_box_sparse_translator.py b/test/ir/pir/translator/test_pull_box_sparse_translator.py index f41a7177b780a..2bcbc12a2ec73 100644 --- a/test/ir/pir/translator/test_pull_box_sparse_translator.py +++ b/test/ir/pir/translator/test_pull_box_sparse_translator.py @@ -41,13 +41,6 @@ def append_op(self): outputs={"Out": [out]}, attrs=attrs, ) - backward_helper = LayerHelper(self.backward_op_type) - backward_helper.append_op( - type=self.backward_op_type, - inputs={"Ids": [ids]}, - outputs={"Out": [out]}, - attrs=attrs, - ) def test_translator(self): self.check() From d279e81bc401ac92a6338214426f664dabcb6fbf Mon Sep 17 00:00:00 2001 From: enkilee Date: Mon, 22 Apr 2024 08:43:14 +0800 Subject: [PATCH 11/16] add out --- test/ir/pir/translator/test_pull_box_sparse_translator.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/ir/pir/translator/test_pull_box_sparse_translator.py b/test/ir/pir/translator/test_pull_box_sparse_translator.py index 2bcbc12a2ec73..f691892adc4f4 100644 --- a/test/ir/pir/translator/test_pull_box_sparse_translator.py +++ b/test/ir/pir/translator/test_pull_box_sparse_translator.py @@ -41,6 +41,7 @@ def append_op(self): outputs={"Out": [out]}, attrs=attrs, ) + return out def test_translator(self): self.check() From 1b54136de8c63f51a6c19daa63674e687e01a00d Mon Sep 17 00:00:00 2001 From: enkilee Date: Thu, 25 Apr 2024 15:46:39 +0800 Subject: [PATCH 12/16] fix --- paddle/fluid/pir/dialect/operator/ir/ops.yaml | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/paddle/fluid/pir/dialect/operator/ir/ops.yaml b/paddle/fluid/pir/dialect/operator/ir/ops.yaml index 41670430383c7..ef1278943e19b 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ops.yaml +++ b/paddle/fluid/pir/dialect/operator/ir/ops.yaml @@ -1360,17 +1360,6 @@ func : pull_box_sparse data_type : ids -- op : push_box_sparse - args : (Tensor[] ids, Tensor[] out_grad_in, bool is_sparse = false, bool is_distributed = false, int size = 1) - output : Tensor[](out_grad_out){out_grad_in.size()} - infer_meta : - func : UnchangedMultiInferMeta - param : [out_grad_in] - kernel : - func : push_box_sparse - data_type : out_grad_in - inplace : (out_grad_in -> out_grad_out) - - op : pull_gpups_sparse args : (Tensor w, Tensor[] ids, int[] size={}, bool is_sparse=false, bool is_distributed=false) output : Tensor[](out){ids.size()} @@ -1382,6 +1371,17 @@ optional : w backward: push_gpups_sparse +- op : push_box_sparse + args : (Tensor[] ids, Tensor[] out_grad_in, bool is_sparse = false, bool is_distributed = false, int size = 1) + output : Tensor[](out_grad_out){out_grad_in.size()} + infer_meta : + func : UnchangedMultiInferMeta + param : [out_grad_in] + kernel : + func : push_box_sparse + data_type : out_grad_in + inplace : (out_grad_in -> out_grad_out) + - op : push_dense args : (Tensor[] ids, int table_id = -1, float scale_data_norm = -1.0f, str[] input_names = {}) output : From 4f019220611d22fcce9e38298759bb18f48394f1 Mon Sep 17 00:00:00 2001 From: enkilee Date: Thu, 25 Apr 2024 16:53:59 +0800 Subject: [PATCH 13/16] codestyle --- paddle/phi/api/yaml/op_compat.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index c4e8c42b5d652..7c07bc271e7da 100755 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -2681,20 +2681,20 @@ extra : attrs : [bool is_sparse = false, bool is_distributed = false, int size = 1] -- op : push_box_sparse +- op : pull_gpups_sparse + backward : push_gpups_sparse inputs : - ids: Ids + {w : W, ids : Ids} outputs : out : Out - attrs : - sparse : is_sparse -- op : pull_gpups_sparse - backward : push_gpups_sparse +- op : push_box_sparse inputs : - {w : W, ids : Ids} + ids: Ids outputs : out : Out + attrs : + sparse : is_sparse - op : push_dense inputs : From 2d2ab35743ea7d2375afac17e09da203423d319c Mon Sep 17 00:00:00 2001 From: enkilee Date: Sun, 28 Apr 2024 08:40:52 +0800 Subject: [PATCH 14/16] fix --- paddle/fluid/pir/dialect/operator/ir/ops.yaml | 11 ----------- .../fluid/pir/dialect/operator/ir/ops_backward.yaml | 11 +++++++++++ paddle/phi/infermeta/binary.cc | 1 + 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/paddle/fluid/pir/dialect/operator/ir/ops.yaml b/paddle/fluid/pir/dialect/operator/ir/ops.yaml index ef1278943e19b..2670b6d3c876d 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ops.yaml +++ b/paddle/fluid/pir/dialect/operator/ir/ops.yaml @@ -1371,17 +1371,6 @@ optional : w backward: push_gpups_sparse -- op : push_box_sparse - args : (Tensor[] ids, Tensor[] out_grad_in, bool is_sparse = false, bool is_distributed = false, int size = 1) - output : Tensor[](out_grad_out){out_grad_in.size()} - infer_meta : - func : UnchangedMultiInferMeta - param : [out_grad_in] - kernel : - func : push_box_sparse - data_type : out_grad_in - inplace : (out_grad_in -> out_grad_out) - - op : push_dense args : (Tensor[] ids, int table_id = -1, float scale_data_norm = -1.0f, str[] input_names = {}) output : diff --git a/paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml b/paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml index f407cf00c504f..9906fe6d0752d 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml +++ b/paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml @@ -1041,3 +1041,14 @@ kernel: func: unpool_grad data_type: x + +- op : push_box_sparse + args : (Tensor[] ids, Tensor[] out_grad_in, bool is_sparse = false, bool is_distributed = false, int size = 1) + output : Tensor[](out_grad_out){out_grad_in.size()} + infer_meta : + func : UnchangedMultiInferMeta + param : [out_grad_in] + kernel : + func : push_box_sparse + data_type : out_grad_in + inplace : (out_grad_in -> out_grad_out) diff --git a/paddle/phi/infermeta/binary.cc b/paddle/phi/infermeta/binary.cc index 28168eacae7d6..977cf943bf17c 100644 --- a/paddle/phi/infermeta/binary.cc +++ b/paddle/phi/infermeta/binary.cc @@ -2973,6 +2973,7 @@ void PullBoxSparseInferMeta(const MetaTensor& w, out_dim.push_back(hidden_size); output->set_dims(common::make_ddim(out_dim)); output->share_lod(*ids[i]); + output->set_dtype(w.dtype()); } } From 61984d4eeee5550d3ca5ba56246c52dd7f755eb8 Mon Sep 17 00:00:00 2001 From: enkilee Date: Sun, 28 Apr 2024 09:08:49 +0800 Subject: [PATCH 15/16] fix backward --- .../pir/dialect/operator/ir/ops_backward.yaml | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml b/paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml index 9906fe6d0752d..1b3b24153b34a 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml +++ b/paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml @@ -659,6 +659,18 @@ func : prod_grad composite: prod_grad(x, out, out_grad, dims, keep_dim, reduce_all, x_grad) +- backward_op : push_box_sparse + forward : pull_box_sparse (Tensor w, Tensor[] ids, bool is_sparse = false, bool is_distributed = false, int size = 1) -> Tensor[](out){ids.size()} + args : (Tensor[] ids, Tensor[] out_grad_in, bool is_sparse = false, bool is_distributed = false, int size = 1) + output : Tensor[](out_grad_out){out_grad_in.size()} + infer_meta : + func : UnchangedMultiInferMeta + param : [out_grad_in] + kernel : + func : push_box_sparse + data_type : out_grad_in + inplace : (out_grad_in -> out_grad_out) + - backward_op : rank_attention_grad forward : rank_attention (Tensor x, Tensor rank_offset, Tensor rank_param, int max_rank = 3, int max_size = 0) -> Tensor(input_help), Tensor(out), Tensor(ins_rank) args : (Tensor x, Tensor rank_offset, Tensor rank_param, Tensor input_help, Tensor ins_rank, Tensor out_grad, int max_rank = 3, int max_size = 0) @@ -1041,14 +1053,3 @@ kernel: func: unpool_grad data_type: x - -- op : push_box_sparse - args : (Tensor[] ids, Tensor[] out_grad_in, bool is_sparse = false, bool is_distributed = false, int size = 1) - output : Tensor[](out_grad_out){out_grad_in.size()} - infer_meta : - func : UnchangedMultiInferMeta - param : [out_grad_in] - kernel : - func : push_box_sparse - data_type : out_grad_in - inplace : (out_grad_in -> out_grad_out) From 699f5d9db0fd2b31256c5ff894b59d62da33e83b Mon Sep 17 00:00:00 2001 From: enkilee Date: Tue, 30 Apr 2024 16:11:52 +0800 Subject: [PATCH 16/16] merge --- test/ir/pir/translator/CMakeLists.txt | 47 --------------------------- 1 file changed, 47 deletions(-) delete mode 100644 test/ir/pir/translator/CMakeLists.txt diff --git a/test/ir/pir/translator/CMakeLists.txt b/test/ir/pir/translator/CMakeLists.txt deleted file mode 100644 index e4b19f0a78f79..0000000000000 --- a/test/ir/pir/translator/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -file( - GLOB TEST_INTERP_CASES - RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" - "test_*.py") -string(REPLACE ".py" "" TEST_INTERP_CASES "${TEST_INTERP_CASES}") - -set(DISTRIBUTED_OP_TRANSLATOR_TEST test_all_reduce_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_barrier_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_reduce_min_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_allreduce_min_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_allreduce_prod_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_reduce_max_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_reduce_prod_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_scatter_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_split_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_distributed_fused_lamb_init) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_distributed_fused_lamb) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST - test_distributed_lookup_table_translate) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST - test_distributed_push_sparse_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_dgc_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_nop_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_partial_allgather_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_partial_send_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_push_dense_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_partial_recv_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST - test_prune_gate_by_capacity_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_pull_box_sparse_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_pull_gpups_sparse_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_pull_sparse_v2_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_random_routing_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_limit_by_capacity_translator) -list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_global_scatter_translator) - -if(NOT WITH_DISTRIBUTE) - list(REMOVE_ITEM TEST_INTERP_CASES ${DISTRIBUTED_OP_TRANSLATOR_TEST}) -endif() - -if(NOT WITH_DGC) - list(REMOVE_ITEM TEST_INTERP_CASES test_dgc_translator) -endif() - -foreach(target ${TEST_INTERP_CASES}) - py_test_modules(${target} MODULES ${target}) -endforeach()