forked from huawei/mindspore2022
!17378 fix pclint and codedex for master ops info
From: @yangzhenzhang Reviewed-by: @kisnwang,@jjfeing Signed-off-by: @jjfeing
This commit is contained in:
commit
aeaf2d14b3
|
|
@ -171,7 +171,7 @@ Status Softmax::GetAttrs() {
|
|||
auto it =
|
||||
std::find_if(axis_.begin(), axis_.end(), [dim](int64_t element) { return ((element >= dim) || (element < -dim)); });
|
||||
if (it != axis_.end()) {
|
||||
MS_LOG(ERROR) << name_ << " : The axis(" << *it << ") is out of range[" << -dim << ", " << dim - 1 << "].";
|
||||
MS_LOG(ERROR) << name_ << " : The axis(" << *it << ") is out of range[" << (-dim) << ", " << (dim - 1) << "].";
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
|
|
@ -399,7 +399,7 @@ Status ExpandDimsInfo::GetAttrs() {
|
|||
|
||||
int64_t dim = SizeToLong(inputs_shape_[0].size());
|
||||
if ((axis > dim) || (axis < -dim - 1)) {
|
||||
MS_LOG(ERROR) << name_ << ": The axis(" << axis << ") is out of range[" << -dim - 1 << ", " << dim << "]";
|
||||
MS_LOG(ERROR) << name_ << ": The axis(" << axis << ") is out of range[" << (-dim - 1) << ", " << dim << "]";
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -412,13 +412,13 @@ Status GatherPInfo::InferDevMatrixShape() {
|
|||
|
||||
dev_matrix_shape_ = param_strategy;
|
||||
|
||||
// param_strategy(axis)==1,
|
||||
// param_strategy(axis) is 1
|
||||
if (param_strategy.at(LongToSize(axis_)) == 1) {
|
||||
dev_matrix_shape_.insert(dev_matrix_shape_.end(), index_strategy.begin(), index_strategy.end());
|
||||
}
|
||||
|
||||
// infer out dev_matrix_shape
|
||||
// axis!=0, split axis
|
||||
// axis is not 0, split axis
|
||||
if (axis_ != 0 && param_strategy.at(LongToSize(axis_)) != 1) {
|
||||
for (size_t i = 1; i < param_strategy.size(); ++i) {
|
||||
if (i == LongToSize(axis_)) {
|
||||
|
|
@ -447,7 +447,7 @@ Status GatherPInfo::InferDevMatrixShape() {
|
|||
|
||||
void GatherPInfo::InferInputsTensorMap() {
|
||||
// infer input tensor map
|
||||
// param_strategy(axis) != 1
|
||||
// param_strategy(axis) is not 1
|
||||
size_t param_size = inputs_shape_.at(0).size();
|
||||
size_t index_size = inputs_shape_.at(1).size();
|
||||
size_t total_size = param_size + index_size;
|
||||
|
|
@ -460,7 +460,7 @@ void GatherPInfo::InferInputsTensorMap() {
|
|||
tensor_map_params.push_back(SizeToLong(param_size - i - 1));
|
||||
}
|
||||
} else {
|
||||
// param_strategy(axis) == 1
|
||||
// param_strategy(axis) is 1
|
||||
for (size_t i = 0; i < param_size; ++i) {
|
||||
tensor_map_params.push_back(SizeToLong(total_size - i - 1));
|
||||
}
|
||||
|
|
@ -480,7 +480,7 @@ void GatherPInfo::InferOutputsTensorMap() {
|
|||
Shape tensor_map_out;
|
||||
auto param_strategy = strategy_->GetInputDim().at(0);
|
||||
if (param_strategy.at(LongToSize(axis_)) == 1) {
|
||||
// param_strategy(axis) == 1
|
||||
// param_strategy(axis) is 1
|
||||
for (size_t i = 0; i < param_size; ++i) {
|
||||
if (i == LongToSize(axis_)) {
|
||||
for (size_t j = 0; j < index_size; ++j) {
|
||||
|
|
@ -491,7 +491,7 @@ void GatherPInfo::InferOutputsTensorMap() {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// param_strategy(axis) != 1
|
||||
// param_strategy(axis) is not 1
|
||||
if (axis_ == 0) {
|
||||
if ((dynamic_shape_indices_ && target_ != CPU) || axis_split_forward_allreduce_) {
|
||||
// the output is repeat calculation
|
||||
|
|
@ -516,7 +516,7 @@ void GatherPInfo::InferOutputsTensorMap() {
|
|||
}
|
||||
}
|
||||
}
|
||||
outputs_tensor_map_.emplace_back(std::move(tensor_map_out));
|
||||
(void)outputs_tensor_map_.emplace_back(std::move(tensor_map_out));
|
||||
}
|
||||
|
||||
Status GatherPInfo::InferTensorMap() {
|
||||
|
|
@ -524,9 +524,9 @@ Status GatherPInfo::InferTensorMap() {
|
|||
Shape param_map = {1, 0};
|
||||
Shape indices_map = {-1, 1};
|
||||
Shape out_map = {-1, 1, 0};
|
||||
inputs_tensor_map_.emplace_back(std::move(param_map));
|
||||
inputs_tensor_map_.emplace_back(std::move(indices_map));
|
||||
outputs_tensor_map_.emplace_back(std::move(out_map));
|
||||
(void)inputs_tensor_map_.emplace_back(std::move(param_map));
|
||||
(void)inputs_tensor_map_.emplace_back(std::move(indices_map));
|
||||
(void)outputs_tensor_map_.emplace_back(std::move(out_map));
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -589,7 +589,7 @@ Status GatherPInfo::InferBias() {
|
|||
}
|
||||
|
||||
// axis don't split
|
||||
if (params_strategy.at(LongToSize(axis_) == 1)) {
|
||||
if (params_strategy.at(LongToSize(axis_)) == 1) {
|
||||
bias_ = 0;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
|
@ -737,12 +737,14 @@ Status GatherPInfo::ComputeReplaceGraph(const CNodePtr &cnode) {
|
|||
MS_LOG(ERROR) << name_ << ": Infer Bias failed.";
|
||||
return FAILED;
|
||||
}
|
||||
auto sub = gen_g.PushBack({gen_g.NewOpInst(SUB), gen_g.virtual_input_node(), CreateInt32Tensor(index_offset_)});
|
||||
auto gather_v2 =
|
||||
gen_g.PushBack({gen_g.NewOpInst(replace_op_name_), gen_g.virtual_input_node(), sub, CreatInt64Imm(axis_)});
|
||||
std::vector<std::pair<AnfNodePtr, int64_t>> input_nodes = {std::make_pair(sub, 2), std::make_pair(gather_v2, 1)};
|
||||
auto sub_node =
|
||||
gen_g.PushBack({gen_g.NewOpInst(SUB), gen_g.virtual_input_node(), CreateInt32Tensor(index_offset_)});
|
||||
auto gather_v2_node =
|
||||
gen_g.PushBack({gen_g.NewOpInst(replace_op_name_), gen_g.virtual_input_node(), sub_node, CreatInt64Imm(axis_)});
|
||||
std::vector<std::pair<AnfNodePtr, int64_t>> input_nodes = {std::make_pair(sub_node, 2),
|
||||
std::make_pair(gather_v2_node, 1)};
|
||||
replace_graph_ = std::make_shared<std::pair<std::vector<std::pair<AnfNodePtr, int64_t>>, AnfNodePtr>>(
|
||||
std::make_pair(input_nodes, gather_v2));
|
||||
std::make_pair(input_nodes, gather_v2_node));
|
||||
return SUCCESS;
|
||||
}
|
||||
if (InferBias() != SUCCESS) {
|
||||
|
|
|
|||
|
|
@ -141,12 +141,12 @@ Status GetNextInfo::GetAttrTypes() {
|
|||
types_.push_back(type->ToString());
|
||||
}
|
||||
} else if (iter->second->isa<ValueTuple>()) {
|
||||
auto iter_cast = iter->second->cast<ValueTuplePtr>();
|
||||
MS_EXCEPTION_IF_NULL(iter_cast);
|
||||
auto types = iter_cast->value();
|
||||
for (auto &type : types) {
|
||||
MS_EXCEPTION_IF_NULL(type);
|
||||
types_.push_back(type->ToString());
|
||||
auto iter_tuple = iter->second->cast<ValueTuplePtr>();
|
||||
MS_EXCEPTION_IF_NULL(iter_tuple);
|
||||
auto tuple_types = iter_tuple->value();
|
||||
for (auto &ele : tuple_types) {
|
||||
MS_EXCEPTION_IF_NULL(ele);
|
||||
types_.push_back(ele->ToString());
|
||||
}
|
||||
} else {
|
||||
MS_LOG(ERROR) << name_ << " : The value of types is not list.";
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ Status LayerNormInfo::GetAttrs() {
|
|||
int64_t dim = SizeToLong(inputs_shape_[0].size());
|
||||
auto axis = GetValue<int64_t>(iter->second);
|
||||
if ((axis >= dim) || (axis < -dim)) {
|
||||
MS_LOG(ERROR) << name_ << ": The axis(" << axis << ") is out of range[" << -dim << ", " << dim - 1 << "]";
|
||||
MS_LOG(ERROR) << name_ << ": The axis(" << axis << ") is out of range[" << (-dim) << ", " << (dim - 1) << "]";
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -856,35 +856,35 @@ std::vector<std::shared_ptr<Edge>> OperatorInfo::GetAlivePrevEdges() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
void OperatorInfo::ReplacePreEdge(const std::shared_ptr<OperatorInfo> &op, const std::shared_ptr<Edge> &new_edge) {
|
||||
void OperatorInfo::ReplacePreEdge(const std::shared_ptr<OperatorInfo> &op, const std::shared_ptr<Edge> &replace_edge) {
|
||||
if (op == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << ": ReplacePreEdge: the op is null.";
|
||||
return;
|
||||
}
|
||||
for (auto &edge : prev_edges_) {
|
||||
if (edge->prev_operator() == op) {
|
||||
edge = new_edge;
|
||||
edge = replace_edge;
|
||||
return;
|
||||
}
|
||||
}
|
||||
MS_LOG(EXCEPTION) << name_ << ": Replace edge failed: no edge has been replaced";
|
||||
}
|
||||
|
||||
void OperatorInfo::ReplaceSuccEdge(const std::shared_ptr<OperatorInfo> &op, const std::shared_ptr<Edge> &new_edge) {
|
||||
void OperatorInfo::ReplaceSuccEdge(const std::shared_ptr<OperatorInfo> &op, const std::shared_ptr<Edge> &replace_edge) {
|
||||
if (op == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << ": ReplaceSuccEdge: the op is null.";
|
||||
return;
|
||||
}
|
||||
for (auto &edge : succ_edges_) {
|
||||
if (edge->next_operator() == op) {
|
||||
edge = new_edge;
|
||||
edge = replace_edge;
|
||||
return;
|
||||
}
|
||||
}
|
||||
MS_LOG(EXCEPTION) << name_ << ": Replace edge failed: no edge has been replaced";
|
||||
}
|
||||
|
||||
void OperatorInfo::ReplacePreEdges(const std::shared_ptr<OperatorInfo> &op, const std::shared_ptr<Edge> &new_edge) {
|
||||
void OperatorInfo::ReplacePreEdges(const std::shared_ptr<OperatorInfo> &op, const std::shared_ptr<Edge> &replace_edge) {
|
||||
if (op == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << ": ReplacePreEdges: the op is null.";
|
||||
return;
|
||||
|
|
@ -895,11 +895,12 @@ void OperatorInfo::ReplacePreEdges(const std::shared_ptr<OperatorInfo> &op, cons
|
|||
new_pre_edges.push_back(edge);
|
||||
}
|
||||
}
|
||||
new_pre_edges.push_back(new_edge);
|
||||
new_pre_edges.push_back(replace_edge);
|
||||
prev_edges_ = new_pre_edges;
|
||||
}
|
||||
|
||||
void OperatorInfo::ReplaceSuccEdges(const std::shared_ptr<OperatorInfo> &op, const std::shared_ptr<Edge> &new_edge) {
|
||||
void OperatorInfo::ReplaceSuccEdges(const std::shared_ptr<OperatorInfo> &op,
|
||||
const std::shared_ptr<Edge> &replace_edge) {
|
||||
if (op == nullptr) {
|
||||
MS_LOG(ERROR) << name_ << ": ReplaceSuccEdges: the op is null";
|
||||
return;
|
||||
|
|
@ -910,7 +911,7 @@ void OperatorInfo::ReplaceSuccEdges(const std::shared_ptr<OperatorInfo> &op, con
|
|||
new_succ_edges.push_back(edge);
|
||||
}
|
||||
}
|
||||
new_succ_edges.push_back(new_edge);
|
||||
new_succ_edges.push_back(replace_edge);
|
||||
succ_edges_ = new_succ_edges;
|
||||
}
|
||||
|
||||
|
|
@ -1534,7 +1535,7 @@ int64_t ComputeRepeatDeviceNumByTensorMap(const Shape &dev_matrix_shape, const S
|
|||
}
|
||||
}
|
||||
|
||||
return (int64_t)device_num;
|
||||
return device_num;
|
||||
}
|
||||
|
||||
Status OperatorInfo::InferAsLossDivisor() {
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ static std::vector<ValuePtr> GetValueSequeue(const ValuePtr &sequeue) {
|
|||
}
|
||||
|
||||
if (sequeue->isa<ValueTuple>()) {
|
||||
auto val = sequeue->cast<ValueTuplePtr>();
|
||||
return val->value();
|
||||
auto val_tuple = sequeue->cast<ValueTuplePtr>();
|
||||
return val_tuple->value();
|
||||
}
|
||||
auto val = sequeue->cast<ValueListPtr>();
|
||||
return val->value();
|
||||
|
|
|
|||
|
|
@ -30,12 +30,6 @@
|
|||
|
||||
namespace mindspore {
|
||||
namespace parallel {
|
||||
// The operator UnsortedSegment accepts three inputs:
|
||||
// input0 : vector, the shape is x1,x2,x3,...,xr
|
||||
// input1 : segment id, the shape is x1,x2,..,xn
|
||||
// input2 : value, the number of the segments
|
||||
// For Sum: r >= n
|
||||
// For Min: r >=n, n=1
|
||||
Status UnsortedSegmentOpInfo::GetAttrs() {
|
||||
if (inputs_shape_.size() != UNSORTEDSEGMENTOP_INPUTS_SIZE) {
|
||||
MS_LOG(ERROR) << name_ << ": inputs shape size must be 2, but is " << inputs_shape_.size();
|
||||
|
|
@ -229,9 +223,7 @@ Status UnsortedSegmentOpInfo::InferForwardCommunication() {
|
|||
return SUCCESS;
|
||||
}
|
||||
|
||||
Operator op;
|
||||
op = CreateAllReduceOp(REDUCE_OP_SUM, group_list[0].name());
|
||||
|
||||
Operator op = CreateAllReduceOp(REDUCE_OP_SUM, group_list[0].name());
|
||||
forward_op_.push_back(op);
|
||||
MS_LOG(INFO) << name_ << " : The group name of forward communication is " << group_list[0].name();
|
||||
return SUCCESS;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,13 @@ namespace mindspore {
|
|||
namespace parallel {
|
||||
constexpr size_t UNSORTEDSEGMENTOP_INPUTS_SIZE = 2;
|
||||
constexpr size_t UNSORTEDSEGMENTOP_OUTPUTS_SIZE = 1;
|
||||
|
||||
// The operator UnsortedSegment accepts three inputs:
|
||||
// input0 : vector, the shape is x1,x2,x3,...,xr
|
||||
// input1 : segment id, the shape is x1,x2,..,xn
|
||||
// input2 : value, the number of the segments
|
||||
// For Sum: r >= n
|
||||
// For Min: r >=n, n=1
|
||||
class UnsortedSegmentOpInfo : public OperatorInfo {
|
||||
public:
|
||||
UnsortedSegmentOpInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape,
|
||||
|
|
|
|||
Loading…
Reference in New Issue