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 10 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
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 : 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){ids.size()}
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

- 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 @@ -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
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 : pull_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
18 changes: 18 additions & 0 deletions paddle/phi/infermeta/binary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,24 @@ void MvInferMeta(const MetaTensor& x, const MetaTensor& vec, MetaTensor* out) {
out->share_lod(x);
}

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,
enkilee marked this conversation as resolved.
Show resolved Hide resolved
int paddingid,
bool scalesparsegrad,
const std::vector<std::string>& inputnames,
bool is_distributed,
MetaTensor* out) {
const auto& ids_dims = ids.dims();
auto output_dims = common::vectorize(ids_dims);
output_dims.push_back(ids_dims[1]);
out->set_dims(common::make_ddim(output_dims));
out->share_lod(ids);
}

void PReluInferMeta(const MetaTensor& x,
const MetaTensor& alpha,
const std::string& data_format,
Expand Down
12 changes: 12 additions & 0 deletions paddle/phi/infermeta/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,18 @@ 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,
MetaTensor* out);

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()