Skip to content
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: 1 addition & 1 deletion paddle/fluid/operators/collective/c_scatter_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CScatterOpMaker : public framework::OpProtoAndCheckerMaker {
.SetDefault(0);
AddAttr<int>("root", "(int default 0) root id for broadcasting.")
.SetDefault(0);
AddAttr<int>("nranks", "(int default 1) number of ranks.").SetDefault(0);
AddAttr<int>("nranks", "(int default 0) number of ranks.").SetDefault(0);
AddAttr<bool>(
"use_calc_stream",
"(bool default false) eject CUDA operations to calculation stream.")
Expand Down
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 @@ -173,6 +173,7 @@
'c_reduce_min_',
'c_reduce_prod',
'c_reduce_prod_',
'c_scatter',
'push_sparse_v2',
'push_sparse_v2_',
'partial_send',
Expand Down
9 changes: 9 additions & 0 deletions paddle/fluid/pir/dialect/operator/ir/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@
func : reduce_scatter
param: [x, nranks]

- op : c_scatter
args : (Tensor x, int ring_id = 0, int root = 0, int nranks = 0, bool use_calc_stream = false)
output : Tensor(out)
infer_meta :
func : CScatterInferMeta
param : [x, nranks]
kernel :
func : c_scatter

- op : c_split
args : (Tensor x, int rank = 0, int nranks = 1, int ring_id = 0, bool use_calc_stream = false, bool use_model_parallel = true)
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 @@ -94,6 +94,7 @@ const std::unordered_set<std::string> LegacyOpList = {
CReduceMaxOp::name(),
CReduceMinOp::name(),
CReduceProdOp::name(),
CScatterOp::name(),
PushSparseV2Op::name(),
PartialSendOp::name(),
PartialRecvOp::name()};
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 @@ -3615,6 +3615,12 @@
outputs :
out: Out

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

- op: c_sync_calc_stream
inputs :
x : X
Expand Down
8 changes: 8 additions & 0 deletions paddle/phi/infermeta/unary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,14 @@ void CropInferMeta(const MetaTensor& x,
out->set_dtype(x.dtype());
}

void CScatterInferMeta(const MetaTensor& x, int nranks, MetaTensor* out) {
auto dim = x.dims();
dim[0] = dim[0] / nranks;
if (dim[0] < 0) dim[0] = -1;
out->set_dims(dim);
out->set_dtype(x.dtype());
}

void CSplitInferMeta(const MetaTensor& x, int nranks, MetaTensor* out) {
phi::DDim dim = x.dims();
dim[dim.size() - 1] = dim[dim.size() - 1] / nranks;
Expand Down
2 changes: 2 additions & 0 deletions paddle/phi/infermeta/unary.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ void CropInferMeta(const MetaTensor& x,
MetaTensor* out,
MetaConfig config = MetaConfig());

void CScatterInferMeta(const MetaTensor& x, int nranks, MetaTensor* out);

void CSplitInferMeta(const MetaTensor& x, int nranks, MetaTensor* out);

void CumInferMeta(const MetaTensor& 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 @@ -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_c_reduce_max_translator)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_reduce_prod_translator)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_scatter_translator)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_c_split_translator)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_distributed_fused_lamb_init)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST
Expand Down
42 changes: 42 additions & 0 deletions test/ir/pir/translator/test_c_scatter_translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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 TestCScatterOpTranslator(test_op_translator.TestOpTranslator):
def append_op(self):
self.op_type = "c_scatter"
x = paddle.ones(shape=(100, 2, 3), dtype='float32')
y = paddle.ones(shape=(100, 2, 3), dtype='float32')
attrs = {'ring_id': 0, 'root': 0, 'nranks': 2, 'use_calc_stream': 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()