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.13】 reg partial_send #60484

Merged
merged 7 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -156,6 +156,7 @@
'c_reduce_min_',
'push_sparse_v2',
'push_sparse_v2_',
'partial_send',
]


Expand Down
10 changes: 10 additions & 0 deletions paddle/fluid/pir/dialect/operator/ir/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,16 @@
kernel:
func: onednn_to_paddle_layout

- op: partial_send
args: (Tensor x, int ring_id = 0, int peer = 0, bool use_calc_stream = false, int num = 1, int id = 0)
output :
infer_meta:
func: PartialSendInferMeta
param: [x, ring_id, peer, use_calc_stream, num, id]
kernel:
func: partial_send
param: [x, ring_id, peer, use_calc_stream, num, id]

- op: sparse_momentum
args: (Tensor param, Tensor grad, Tensor velocity, Tensor index, Tensor learning_rate, Tensor master_param,float mu, Scalar axis=0, bool use_nesterov=false,str regularization_method="", float regularization_coeff=0.0f, bool multi_precision=false, float rescale_grad=1.0f)
output: Tensor(param_out), Tensor(velocity_out), Tensor(master_param_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 @@ -80,7 +80,8 @@ const std::unordered_set<std::string> LegacyOpList = {
paddle::onednn::dialect::MultiGruOp::name(),
#endif
CReduceMinOp::name(),
PushSparseV2Op::name()};
PushSparseV2Op::name(),
PartialSendOp::name()};

enum class AttrType {
UNDEFINED = 0,
Expand Down
1 change: 1 addition & 0 deletions paddle/fluid/primitive/codegen/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"embedding_sparse_grad",
"embedding_grad",
"full",
"partial_send",
]

# prim op with one input and one output, with no attribute
Expand Down
4 changes: 4 additions & 0 deletions paddle/phi/api/yaml/op_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3653,6 +3653,10 @@
outputs :
out : Out

- op: partial_send
inputs :
x : X

- op: read_from_array
inputs:
array : X
Expand Down
28 changes: 28 additions & 0 deletions paddle/phi/infermeta/unary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2917,6 +2917,34 @@ void Pad3dInferMeta(const MetaTensor& x,
out->share_lod(x);
}

void PartialSendInferMeta(const MetaTensor& x,
int ring_id,
int peer,
bool use_calc_stream,
int num,
int id) {
PADDLE_ENFORCE_GE(
peer,
0,
phi::errors::InvalidArgument(
"The peer (%d) for partial_send op must be non-negative.", peer));
PADDLE_ENFORCE_GE(
ring_id,
0,
phi::errors::InvalidArgument(
"The ring_id (%d) for partial_send op must be non-negative.",
ring_id));
PADDLE_ENFORCE_GE(num,
1,
phi::errors::InvalidArgument(
"The num (%d) for partial_send op must >=1", num));
PADDLE_ENFORCE_EQ(
(id >= 0 && id < num),
true,
phi::errors::InvalidArgument(
"The id (%d) for partial_send op must >=0 and <num (%d)", id, num));
}

void PixelShuffleInferMeta(const MetaTensor& x,
int upscale_factor,
const std::string& data_format,
Expand Down
7 changes: 7 additions & 0 deletions paddle/phi/infermeta/unary.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,13 @@ void Pad3dInferMeta(const MetaTensor& x,
MetaTensor* out,
MetaConfig config = MetaConfig());

void PartialSendInferMeta(const MetaTensor& x,
int ring_id,
int peer,
bool use_calc_stream,
int num,
int id);

void PixelShuffleInferMeta(const MetaTensor& x,
int upscale_factor,
const std::string& data_format,
Expand Down
1 change: 1 addition & 0 deletions test/ir/pir/translator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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_distributed_lookup_table_translate)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_partial_send_translator)

if(NOT WITH_DISTRIBUTE)
list(REMOVE_ITEM TEST_INTERP_CASES ${DISTRIBUTED_OP_TRANSLATOR_TEST})
Expand Down
40 changes: 40 additions & 0 deletions test/ir/pir/translator/test_partial_send_translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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 TestPartialSendTranslator(test_op_translator.TestOpTranslator):
def append_op(self):
self.op_type = "partial_send"
x = paddle.ones(shape=(100, 2, 3), dtype='float32')
attrs = {'ring_id': 0, 'root_id': 0, 'use_calc_stream': False}
helper = LayerHelper(self.op_type)
helper.append_op(
type=self.op_type,
inputs={"X": x},
attrs=attrs,
)

def test_translator(self):
self.check()


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