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.3】 reg c_allreduce_min #60584

Merged
merged 7 commits into from
Jan 24, 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
2 changes: 2 additions & 0 deletions paddle/fluid/pir/dialect/op_generator/ops_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
'add_n_with_kernel',
'c_allgather',
'c_allreduce_max',
'c_allreduce_min',
'c_allreduce_min_',
Comment on lines +116 to +117
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些算子名单可以考虑优化下,多处黑白名单不利于长期维护

Copy link
Contributor

@kangguangli kangguangli Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两处的用途不一样,名单也不完全重合,第二类主要是针对struct kernel,我觉得可能可以优化,之后研究下。

'c_allreduce_sum',
'c_allreduce_prod',
'c_allreduce_prod_',
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 @@ -166,6 +166,16 @@
func : c_allreduce_max
inplace : (x -> out)

- op : c_allreduce_min
args : (Tensor x, int ring_id, bool use_calc_stream, bool use_model_parallel)
output : Tensor(out)
infer_meta :
func : AllReduceInferMeta
param : [x]
kernel :
func : c_allreduce_min
inplace : (x -> out)

- op : c_allreduce_prod
args : (Tensor x, int ring_id, bool use_calc_stream, bool use_model_parallel)
output : Tensor(out)
Expand Down
1 change: 1 addition & 0 deletions paddle/fluid/pir/dialect/operator/utils/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const std::unordered_set<std::string> LegacyOpList = {
CReduceSumOp::name(),
CReduceSum_Op::name(),
CAllreduceMax_Op::name(),
CAllreduceMin_Op::name(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么没有CAllreduceMinOp::name()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enkilee 这里可以提个补充PR,这个PR我先合入吧

CAllgatherOp::name(),
CSoftmaxWithCrossEntropyOp::name(),
CSoftmaxWithCrossEntropyGradOp::name(),
Expand Down
10 changes: 10 additions & 0 deletions paddle/phi/api/yaml/legacy_ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@
func : c_allreduce_max
inplace : (x -> out)

- op : c_allreduce_min
args : (Tensor x, int ring_id, bool use_calc_stream, bool use_model_parallel)
output : Tensor(out)
infer_meta :
func : AllReduceInferMeta
param : [x]
kernel :
func : c_allreduce_min
inplace : (x -> out)

- op : c_allreduce_prod
args : (Tensor x, int ring_id, bool use_calc_stream, bool use_model_parallel)
output : Tensor(out)
Expand Down
6 changes: 6 additions & 0 deletions paddle/phi/api/yaml/op_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3426,6 +3426,12 @@
outputs :
out: Out

- op: c_allreduce_min
inputs :
x : X
outputs :
out: Out

- op: c_allreduce_prod
inputs :
x : X
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 @@ -5,6 +5,7 @@ file(
string(REPLACE ".py" "" TEST_INTERP_CASES "${TEST_INTERP_CASES}")

set(DISTRIBUTED_OP_TRANSLATOR_TEST test_c_reduce_min_translator)
enkilee marked this conversation as resolved.
Show resolved Hide resolved
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_allreduce_min_translator)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_allreduce_prod_translator)

if(NOT WITH_DISTRIBUTE)
Expand Down
46 changes: 46 additions & 0 deletions test/ir/pir/translator/test_c_allreduce_min_translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) 2024 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 TestCAllReduceMinOpTranslator(test_op_translator.TestOpTranslator):
def append_op(self):
self.op_type = "c_allreduce_min"
x = paddle.ones(shape=(100, 2, 3), dtype='float32')
y = paddle.ones(shape=(100, 2, 3), dtype='float32')
attrs = {
'ring_id': 0,
'use_calc_stream': False,
'use_model_parallel': False,
}
helper = LayerHelper(self.op_type)
helper.append_op(
type=self.op_type,
inputs={"X": x},
outputs={"Out": y},
attrs=attrs,
)

def test_translator(self):
self.check()


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