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 4 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
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 @@ -139,6 +139,7 @@
'uniform_random_batch_size_like',
'c_reduce_min',
'c_reduce_min_',
'pull_sparse_v2',
enkilee marked this conversation as resolved.
Show resolved Hide resolved
]


Expand Down
12 changes: 12 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,18 @@
func : prod
backward : prod_grad

- op : pull_sparse_v2
args : (Tensor[] ids, Tensor[] w, 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)
enkilee marked this conversation as resolved.
Show resolved Hide resolved
infer_meta :
func : PullSparseV2InferMeta
param : [ids, w, embeddingdim, tableid, accessorclass, ctrlabelname, paddingid, scalesparsegrad, inputnames, is_distributed]
kernel :
func : pull_sparse_v2
param : [ids, w, embeddingdim, tableid, accessorclass, ctrlabelname, paddingid, scalesparsegrad, inputnames, is_distributed]
data_type : ids
backward : pull_sparse_v2_grad
enkilee marked this conversation as resolved.
Show resolved Hide resolved

- op : randint
args : (int low, int high, IntArray shape, DataType dtype=DataType::INT64, Place place={})
output : Tensor(out)
Expand Down
10 changes: 10 additions & 0 deletions paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,16 @@
func : prod_grad
composite: prod_grad(x, out, out_grad, dims, keep_dim, reduce_all, x_grad)

- backward_op : pull_sparse_v2_grad
enkilee marked this conversation as resolved.
Show resolved Hide resolved
forward : (Tensor[] ids, Tensor[] w, int embeddingdim = 11, int tableid = 0, str accessorclass = "", str ctrlabelname = "", int paddingid = 0, bool scalesparsegrad = true, str[] inputnames = {}, bool is_distributed = true) -> Tensor[](out)
enkilee marked this conversation as resolved.
Show resolved Hide resolved
args : (Tensor[] ids, Tensor out, Tensor out_grad, int embeddingdim = 11, int tableid = 0, str accessorclass = "", str ctrlabelname = "", int paddingid =0, bool scalesparsegrad = true, str[] inputnames = {}, bool is_distributed = true)
output : Tensor[](ids_grad)
infer_meta :
func : PullSparseV2InferMeta
param : [ids, w, embeddingdim, tableid, accessorclass, ctrlabelname, paddingid, scalesparsegrad, inputnames, is_distributed]
kernel :
func : pull_sparse_v2_grad

- backward_op : repeat_interleave_grad
forward : repeat_interleave(Tensor x, int repeats, int axis) -> Tensor(out)
args : (Tensor x, Tensor out_grad, int repeats, int axis)
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 @@ -59,7 +59,8 @@ const std::unordered_set<std::string> LegacyOpList = {
RowConvGradOp::name(),
SoftReluOp::name(),
SoftReluGradOp::name(),
CReduceMinOp::name()};
CReduceMinOp::name(),
PullSparseV2Op::name()};

const std::unordered_set<std::string> OneDNNLegacyOpList = {};
enum class AttrType {
Expand Down
10 changes: 10 additions & 0 deletions paddle/phi/api/yaml/backward.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,16 @@
data_type : x
optional : boxes_num

- backward_op : pull_sparse_v2_grad
forward : (Tensor[] ids, Tensor[] w, int embeddingdim = 11, int tableid = 0, str accessorclass = "", str ctrlabelname = "", int paddingid = 0, bool scalesparsegrad = true, str[] inputnames = {}, bool is_distributed = true) -> Tensor[](out)
enkilee marked this conversation as resolved.
Show resolved Hide resolved
args : (Tensor[] ids, Tensor out, Tensor out_grad, int embeddingdim, int tableid, str accessorclass, str ctrlabelname, int paddingid, bool scalesparsegrad , str[] inputnames, bool is_distributed)
output : Tensor[](ids_grad)
infer_meta :
func : PullSparseV2InferMeta
param : [ids, w, embeddingdim, tableid, accessorclass, ctrlabelname, paddingid, scalesparsegrad, inputnames, is_distributed]
kernel :
func : pull_sparse_v2_grad

- backward_op : put_along_axis_grad
forward : put_along_axis (Tensor arr, Tensor indices, Tensor values, int axis, str reduce = "assign", bool include_self = true) -> Tensor(out)
args : (Tensor arr, Tensor indices, Tensor values, Tensor out, Tensor out_grad, int axis, str reduce, bool include_self)
Expand Down
9 changes: 9 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,15 @@
outputs :
out : Out

- op : pull_sparse_v2
backward : pull_sparse_v2_grad
enkilee marked this conversation as resolved.
Show resolved Hide resolved
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
12 changes: 12 additions & 0 deletions paddle/phi/api/yaml/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,18 @@
optional : boxes_num
backward : psroi_pool_grad

- op : pull_sparse_v2
args : (Tensor[] ids, Tensor[] w, 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)
infer_meta :
func : PullSparseV2InferMeta
param : [ids, w, embeddingdim, tableid, accessorclass, ctrlabelname, paddingid, scalesparsegrad, inputnames, is_distributed]
kernel :
func : pull_sparse_v2
param : [ids, w, embeddingdim, tableid, accessorclass, ctrlabelname, paddingid, scalesparsegrad, inputnames, is_distributed]
data_type : ids
backward : pull_sparse_v2_grad

- op : put_along_axis
args : (Tensor arr, Tensor indices, Tensor values, int axis, str reduce = "assign", bool include_self = true)
output : Tensor(out)
Expand Down
11 changes: 11 additions & 0 deletions paddle/phi/infermeta/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,17 @@ void PriorBoxInferMeta(const MetaTensor& input,
MetaTensor* out,
MetaTensor* var);

void PullSparseV2InferMeta(const MetaTensor& ids,
enkilee marked this conversation as resolved.
Show resolved Hide resolved
const MetaTensor& w,
int embeddingdim,
int tableid,
const std::string accessorclass,
const std::string ctrlabelname,
int paddingid,
bool scalesparsegrad,
const std::vector<std::string>& inputnames,
bool is_distributed);

void SearchsortedInferMeta(const MetaTensor& sorted_sequence,
const MetaTensor& value,
bool out_int32,
Expand Down
52 changes: 52 additions & 0 deletions test/ir/pir/translator/test_pull_sparse_v2_translate.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_transcriber

import paddle
from paddle.base.layer_helper import LayerHelper


class TestPullSparseV2OpTranscriber(test_op_transcriber.TestOpTranscriber):
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()