Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【PIR Dist Op Reg No.1】 reg push_sparse_v2 #60473

Merged
merged 30 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions paddle/fluid/ir_adaptor/translator/op_compat_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ def insert_new_mutable_attributes(
"atol_tensor": "TolTensor",
"out": "Out",
}
op_arg_name_mappings['push_sparse_v2'].update(
{"out_grad_in": "Out@GRAD", "out_grad_out": "Out@GRAD"}
)

op_name_normailzer_template = env.get_template("op_compat_info.cc.j2")
with open(output_source_file, 'wt') as f:
Expand Down
1 change: 1 addition & 0 deletions paddle/fluid/pir/dialect/op_generator/ops_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
'uniform_random_batch_size_like',
'c_reduce_min',
'c_reduce_min_',
'push_sparse_v2',
enkilee marked this conversation as resolved.
Show resolved Hide resolved
]


Expand Down
11 changes: 11 additions & 0 deletions paddle/fluid/pir/dialect/operator/ir/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,17 @@
func : prod
backward : prod_grad

- 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()}
infer_meta :
func : UnchangedInferMeta
enkilee marked this conversation as resolved.
Show resolved Hide resolved
param : [out_grad_in]
kernel :
func : push_sparse_v2
data_type : out_grad_in
inplace: (out_grad_in -> out_grad_out)

- op : randint
args : (int low, int high, IntArray shape, DataType dtype=DataType::INT64, Place place={})
output : Tensor(out)
Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/pir/dialect/operator/utils/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const std::unordered_set<std::string> LegacyOpList = {
SoftReluGradOp::name(),
NceOp::name(),
NceGradOp::name(),
CReduceMinOp::name()};
CReduceMinOp::name(),
PushSparseV2Op::name()};

const std::unordered_set<std::string> OneDNNLegacyOpList = {};
enum class AttrType {
Expand Down
8 changes: 8 additions & 0 deletions paddle/phi/api/yaml/op_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2441,6 +2441,14 @@
outputs :
out : Out

- op : push_sparse_v2
inputs :
{ x : Ids, W : w}
outputs :
out : Out
extra :
attrs : [int embeddingdim = 11, int tableid = 0, str accessorclass = "", str ctrlabelname = "", int paddingid = 0, bool scalesparsegrad = true, 'str[] inputnames = {}', bool is_distributed = true]

- op : put_along_axis
backward : put_along_axis_grad
inputs :
Expand Down
3 changes: 2 additions & 1 deletion test/ir/pir/translator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ file(
"test_*.py")
string(REPLACE ".py" "" TEST_INTERP_CASES "${TEST_INTERP_CASES}")

set(DISTRIBUTED_OP_TRANSLATOR_TEST test_c_reduce_min_translator)
set(DISTRIBUTED_OP_TRANSLATION_TEST test_c_reduce_min_translate)
list(APPEND DISTRIBUTED_OP_TRANSLATION_TEST test_push_sparse_v2_translate)
enkilee marked this conversation as resolved.
Show resolved Hide resolved

if(NOT WITH_DISTRIBUTE)
list(REMOVE_ITEM TEST_INTERP_CASES ${DISTRIBUTED_OP_TRANSLATOR_TEST})
Expand Down
52 changes: 52 additions & 0 deletions test/ir/pir/translator/test_push_sparse_v2_translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) 2023 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 TestPushSparseV2OpTranslator(test_op_translator.TestOpTranslator):
def append_op(self):
self.op_type = "push_sparse_v2"
ids = paddle.ones(shape=(100, 2, 3), dtype='float32')
w = paddle.ones(shape=(100, 2, 3), dtype='float32')
out = paddle.ones(shape=(100, 2, 3), dtype='float32')
attrs = {
'embeddingdim': 11,
'tableid': 0,
'accessorclass': "",
'ctrlabelname': "",
'paddingid': 0,
'scalesparsegrad': True,
'inputnames': [],
'is_distributed': True,
}
helper = LayerHelper(self.op_type)
helper.append_op(
type=self.op_type,
inputs={"Ids": ids, "W": w},
outputs={"Out": out},
attrs=attrs,
)

def test_translator(self):
self.check()


if __name__ == "__main__":
unittest.main()