-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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.24】 reg distributed_lookup_table #60911
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -374,6 +374,15 @@ | |||||
data_type : fpn_rois | ||||||
optional : rois_num, multi_level_rois_num | ||||||
|
||||||
- op : distributed_lookup_table | ||||||
args : (Tensor[] ids, Tensor w, int table_id = 0, bool is_distributed = false, str lookup_table_version = "lookup_table", int64_t padding_idx = -1, int dtype = 5, bool is_test = false) | ||||||
output : Tensor[](outputs){ids.size()} | ||||||
infer_meta : | ||||||
func : DistributeLookupTableInferMeta | ||||||
kernel : | ||||||
func : distributed_lookup_table | ||||||
data_type : ids | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
这里需要和DistributedLookupTableOp::GetExpectedKernelType 保持一致 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 谢谢,已修改~ |
||||||
|
||||||
- op : divide | ||||||
args : (Tensor x, Tensor y) | ||||||
output : Tensor(out) | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1097,6 +1097,49 @@ void DistInferMeta(const MetaTensor& x, | |||||
out->set_dtype(x.dtype()); | ||||||
} | ||||||
|
||||||
void DistributeLookupTableInferMeta( | ||||||
const std::vector<const phi::MetaTensor*>& ids, | ||||||
const MetaTensor& w, | ||||||
int table_id, | ||||||
bool is_distributed, | ||||||
const std::string& lookup_table_version, | ||||||
int64_t padding_idx, | ||||||
int dtype, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
bool is_test, | ||||||
std::vector<MetaTensor*> outputs) { | ||||||
auto table_dims = w.dims(); | ||||||
|
||||||
PADDLE_ENFORCE_EQ(w.dims().size(), | ||||||
2, | ||||||
errors::InvalidArgument( | ||||||
"Only 2 dimensions of the 'Embedding' is supported.")); | ||||||
|
||||||
for (auto& id : ids) { | ||||||
PADDLE_ENFORCE_EQ(id->dims().size(), | ||||||
2, | ||||||
errors::InvalidArgument( | ||||||
"The dimension of the 'Ids' tensor must be 2.")); | ||||||
} | ||||||
|
||||||
// for fluid.embedding | ||||||
for (size_t i = 0; i < ids.size(); ++i) { | ||||||
MetaTensor* output = outputs[i]; | ||||||
auto id_dims = ids[i]->dims(); | ||||||
if (lookup_table_version == "lookup_table") { | ||||||
output->set_dims(common::make_ddim({id_dims[0], table_dims[1]})); | ||||||
output->share_lod(*ids[i]); | ||||||
output->set_dtype(w.dtype()); | ||||||
} else if (lookup_table_version == "lookup_table_v2") { | ||||||
output->set_dims( | ||||||
common::make_ddim({static_cast<int64_t>(id_dims[0]), | ||||||
static_cast<int64_t>(id_dims[1]), | ||||||
static_cast<int64_t>(table_dims[1])})); | ||||||
output->share_lod(*ids[i]); | ||||||
output->set_dtype(w.dtype()); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
void DistributeFpnProposalsInferMeta( | ||||||
const MetaTensor& fpn_rois, | ||||||
const MetaTensor& rois_num, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2023 -> 2024 |
||
# | ||
# 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 TestDistributedLookupTableOpTranslator( | ||
test_op_translator.TestOpTranslator | ||
): | ||
def append_op(self): | ||
self.op_type = "distributed_lookup_table" | ||
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 = { | ||
'table_id': 0, | ||
'is_distributed': False, | ||
'lookup_table_version': 'lookup_table', | ||
'padding_idx': -1, | ||
'dtype': 5, | ||
'is_test': False, | ||
} | ||
helper = LayerHelper(self.op_type) | ||
helper.append_op( | ||
type=self.op_type, | ||
inputs={"Ids": [ids], "W": w}, | ||
outputs={"Outputs": [out]}, | ||
attrs=attrs, | ||
) | ||
|
||
def test_translator(self): | ||
self.check() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.