forked from huawei/mindspore2022
fix some codestyle warnings
This commit is contained in:
parent
ad1ea03779
commit
07e1e39a82
|
|
@ -343,6 +343,6 @@ void Edge::SetCostMapAndInputOutput(std::map<CostPtrKey, CostPtrList> &cost_map)
|
|||
}
|
||||
|
||||
// Return true if there are available strategies in this edge.
|
||||
bool Edge::CheckStrategyCostPossibility() { return !cost_map_.empty(); }
|
||||
bool Edge::CheckStrategyCostPossibility() const { return !cost_map_.empty(); }
|
||||
} // namespace parallel
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ class Edge {
|
|||
Status CalculateMemoryCostForInference();
|
||||
void mark_output_critical() { is_output_critical_ = 1; }
|
||||
// Whether there exists any available strategy in 'cost_map_'
|
||||
bool CheckStrategyCostPossibility();
|
||||
bool CheckStrategyCostPossibility() const;
|
||||
|
||||
private:
|
||||
std::string edge_name_;
|
||||
|
|
@ -153,7 +153,7 @@ class Edge {
|
|||
// the index of outputs of prev_op, and the index of inputs of next_op
|
||||
size_t prev_op_output_index_, next_op_input_index_;
|
||||
|
||||
// pre_op_output_indexs_ and next_op_input_indexs_ store the indexs of inputs and outputs if is_combined = true
|
||||
// 'pre_op_output_indexs_' and 'next_op_input_indexs_' store the indexes of inputs and outputs if is_combined = true
|
||||
std::vector<size_t> pre_op_output_indexs_;
|
||||
std::vector<size_t> next_op_input_indexs_;
|
||||
// is this edge constructed by combining multiple edges? If is is, then is_combined = true, else is_combined = false
|
||||
|
|
|
|||
|
|
@ -729,7 +729,7 @@ void CostGraph::CreateSourceEliminationSubCostList(StrategyPtr op1_old_stra, con
|
|||
std::pair<std::vector<EdgePtr>, std::vector<EdgePtr>> UpdateEdgesIncidentToNodes(
|
||||
OperatorInfoPtr op1, std::vector<EdgePtr> *op1_old_succ_edges,
|
||||
std::vector<std::map<CostPtrKey, CostPtrList>> *op1_new_edges_cost, std::vector<EdgePtr> *op1_new_succ_edges,
|
||||
OperatorInfoPtr op2, std::vector<EdgePtr> *op2_old_succ_edges,
|
||||
const OperatorInfoPtr op2, std::vector<EdgePtr> *op2_old_succ_edges,
|
||||
std::vector<std::map<CostPtrKey, CostPtrList>> *op2_new_edges_cost, std::vector<EdgePtr> *op2_new_succ_edges) {
|
||||
for (size_t i = 0; i < op1_old_succ_edges->size(); ++i) {
|
||||
auto &new_cost_map = op1_new_edges_cost->at(i);
|
||||
|
|
@ -754,8 +754,8 @@ std::pair<std::vector<EdgePtr>, std::vector<EdgePtr>> UpdateEdgesIncidentToNodes
|
|||
// replace the old successive edges with the new ones.
|
||||
op1->ReplaceSuccEdge(ith_edge->next_operator(), new_edge);
|
||||
ith_edge->next_operator()->ReplacePreEdge(op1, new_edge);
|
||||
op1_new_succ_edges->erase(op1_new_succ_edges->begin() + i);
|
||||
op1_new_succ_edges->emplace(op1_new_succ_edges->begin() + i, new_edge);
|
||||
(void)op1_new_succ_edges->erase(op1_new_succ_edges->begin() + i);
|
||||
(void)op1_new_succ_edges->emplace(op1_new_succ_edges->begin() + i, new_edge);
|
||||
}
|
||||
for (size_t i = 0; i < op2_old_succ_edges->size(); ++i) {
|
||||
auto &new_cost_map = op2_new_edges_cost->at(i);
|
||||
|
|
@ -779,14 +779,14 @@ std::pair<std::vector<EdgePtr>, std::vector<EdgePtr>> UpdateEdgesIncidentToNodes
|
|||
// replace the old successive edges with the new ones.
|
||||
destination->ReplacePreEdge(op2, new_edge);
|
||||
op1->AddSuccEdge(new_edge);
|
||||
op2_new_succ_edges->erase(op2_new_succ_edges->begin() + i);
|
||||
op2_new_succ_edges->emplace(op2_new_succ_edges->begin() + i, new_edge);
|
||||
(void)op2_new_succ_edges->erase(op2_new_succ_edges->begin() + i);
|
||||
(void)op2_new_succ_edges->emplace(op2_new_succ_edges->begin() + i, new_edge);
|
||||
}
|
||||
return std::make_pair(*op1_new_succ_edges, *op2_new_succ_edges);
|
||||
}
|
||||
|
||||
std::pair<std::vector<std::shared_ptr<Edge>>, std::vector<std::shared_ptr<Edge>>> CostGraph::EliminationSources(
|
||||
OperatorInfoPtr op1, OperatorInfoPtr op2) {
|
||||
const OperatorInfoPtr op1, const OperatorInfoPtr op2) {
|
||||
MS_EXCEPTION_IF_NULL(op1);
|
||||
MS_EXCEPTION_IF_NULL(op2);
|
||||
MS_LOG(INFO) << "Now source eliminating node: " << op2->name() << " to node: " << op1->name();
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ class CostGraph {
|
|||
// We merge 'op2' into op1. The returned value are '<Edges1, Edges2>'. 'Edges1' are newly updated edges for 'op1',
|
||||
// 'Edges2' are newly updated edges for 'op2'.
|
||||
std::pair<std::vector<std::shared_ptr<Edge>>, std::vector<std::shared_ptr<Edge>>> EliminationSources(
|
||||
OperatorInfoPtr op1, OperatorInfoPtr op2);
|
||||
const OperatorInfoPtr op1, const OperatorInfoPtr op2);
|
||||
// Calculate memory cost for training phase or inference phase.
|
||||
Status CalculateMemoryCost();
|
||||
// When the input of a operator is neither a WEIGHT, nor a output of a subsequent operator involving WEIGHT, then
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ double OperatorCost::GetInputMemoryCost(const std::vector<TensorInfo> &inputs, c
|
|||
return result;
|
||||
}
|
||||
|
||||
double OperatorCost::GetOutputMemoryCost(const std::vector<TensorInfo> &inputs,
|
||||
double OperatorCost::GetOutputMemoryCost(const std::vector<TensorInfo> &,
|
||||
const std::vector<TensorInfo> &outputs) const {
|
||||
double result = 0.0;
|
||||
if (is_output_should_in_memory_) {
|
||||
|
|
@ -243,7 +243,7 @@ double CastCost::GetBackwardComputationCost(const std::vector<TensorInfo> &, con
|
|||
void CastCost::CalculateOutputInMemory() { is_output_should_in_memory_ = false; }
|
||||
|
||||
// Not taking account of input
|
||||
void CastCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void CastCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
is_inputs_should_in_memory_[0] = is_parameter_[0];
|
||||
}
|
||||
|
||||
|
|
@ -314,7 +314,7 @@ double SoftmaxCost::GetBackwardComputationCost(const std::vector<mindspore::para
|
|||
void SoftmaxCost::CalculateOutputInMemory() { is_output_should_in_memory_ = is_parameter_involve_[0]; }
|
||||
|
||||
// Not taking account of input
|
||||
void SoftmaxCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void SoftmaxCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
is_inputs_should_in_memory_[0] = is_parameter_[0];
|
||||
}
|
||||
|
||||
|
|
@ -322,7 +322,7 @@ void SoftmaxCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_out
|
|||
void PackCost::CalculateOutputInMemory() { is_output_should_in_memory_ = false; }
|
||||
|
||||
// Not taking account of input
|
||||
void PackCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void PackCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
is_inputs_should_in_memory_[0] = is_parameter_[0];
|
||||
}
|
||||
|
||||
|
|
@ -351,7 +351,7 @@ void TileCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output
|
|||
// Not taking account of output
|
||||
void BroadcastToCost::CalculateOutputInMemory() { is_output_should_in_memory_ = false; }
|
||||
|
||||
void BroadcastToCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void BroadcastToCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
is_inputs_should_in_memory_[0] = is_parameter_[0];
|
||||
}
|
||||
|
||||
|
|
@ -418,7 +418,7 @@ double TmpIdentityCost::GetBackwardComputationCost(const std::vector<mindspore::
|
|||
void TmpIdentityCost::CalculateOutputInMemory() { is_output_should_in_memory_ = false; }
|
||||
|
||||
// Not taking account of input
|
||||
void TmpIdentityCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void TmpIdentityCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
is_inputs_should_in_memory_[0] = is_parameter_[0];
|
||||
}
|
||||
|
||||
|
|
@ -494,8 +494,7 @@ void SparseSoftmaxCrossEntropyWithLogitsCost::CalculateOutputInMemory() {
|
|||
is_output_should_in_memory_ = is_parameter_involve_[0];
|
||||
}
|
||||
|
||||
void SparseSoftmaxCrossEntropyWithLogitsCost::CalculateInputsInMemory(
|
||||
const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void SparseSoftmaxCrossEntropyWithLogitsCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
is_inputs_should_in_memory_[0] = is_parameter_[0];
|
||||
is_inputs_should_in_memory_[1] = is_parameter_[1];
|
||||
}
|
||||
|
|
@ -614,7 +613,7 @@ double OneHotCost::GetBackwardComputationCost(const std::vector<TensorInfo> &, c
|
|||
void OneHotCost::CalculateOutputInMemory() { is_output_should_in_memory_ = false; }
|
||||
|
||||
// Not taking account of input
|
||||
void OneHotCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void OneHotCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
is_inputs_should_in_memory_[0] = is_parameter_[0];
|
||||
is_inputs_should_in_memory_[1] = is_parameter_[1];
|
||||
is_inputs_should_in_memory_[ONEHOT_INPUTS_SIZE - 2] = is_parameter_[ONEHOT_INPUTS_SIZE - 2];
|
||||
|
|
@ -659,7 +658,7 @@ void SoftmaxCrossEntropyWithLogitsCost::CalculateOutputInMemory() {
|
|||
is_output_should_in_memory_ = is_parameter_involve_[0];
|
||||
}
|
||||
|
||||
void SoftmaxCrossEntropyWithLogitsCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void SoftmaxCrossEntropyWithLogitsCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
is_inputs_should_in_memory_[0] = is_parameter_[0];
|
||||
is_inputs_should_in_memory_[1] = is_parameter_[1];
|
||||
}
|
||||
|
|
@ -727,7 +726,7 @@ double ReshapeCost::GetBackwardComputationCost(const std::vector<mindspore::para
|
|||
|
||||
void ReshapeCost::CalculateOutputInMemory() { is_output_should_in_memory_ = false; }
|
||||
|
||||
void ReshapeCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void ReshapeCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
is_inputs_should_in_memory_[0] = is_parameter_[0];
|
||||
is_inputs_should_in_memory_[1] = is_parameter_[1];
|
||||
}
|
||||
|
|
@ -815,7 +814,7 @@ double SubCost::GetBackwardCommCost(const std::vector<TensorInfo> &inputs, const
|
|||
void SubCost::CalculateOutputInMemory() { is_output_should_in_memory_ = false; }
|
||||
|
||||
// Not taking account of input
|
||||
void SubCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void SubCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
is_inputs_should_in_memory_[0] = is_parameter_[0];
|
||||
is_inputs_should_in_memory_[1] = is_parameter_[1];
|
||||
}
|
||||
|
|
@ -1336,7 +1335,7 @@ void GatherV2Cost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_ou
|
|||
|
||||
void GetNextCost::CalculateOutputInMemory() { is_output_should_in_memory_ = false; }
|
||||
|
||||
void GetNextCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void GetNextCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
if (is_inputs_should_in_memory_.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1345,7 +1344,7 @@ void GetNextCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_out
|
|||
|
||||
void UniqueCost::CalculateOutputInMemory() { is_output_should_in_memory_ = is_parameter_involve_[0]; }
|
||||
|
||||
void UniqueCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void UniqueCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
is_inputs_should_in_memory_[0] = is_parameter_[0];
|
||||
}
|
||||
|
||||
|
|
@ -1534,7 +1533,7 @@ double UniformCandidateSamplerCost::GetForwardComputationCost(const std::vector<
|
|||
|
||||
void UniformCandidateSamplerCost::CalculateOutputInMemory() { is_output_should_in_memory_ = false; }
|
||||
|
||||
void UniformCandidateSamplerCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void UniformCandidateSamplerCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
is_inputs_should_in_memory_[0] = is_parameter_[0];
|
||||
}
|
||||
|
||||
|
|
@ -1746,7 +1745,7 @@ void UnsortedSegmentMinCost::CalculateInputsInMemory(const std::map<size_t, bool
|
|||
void VirtualDatasetCost::CalculateOutputInMemory() { is_output_should_in_memory_ = false; }
|
||||
|
||||
// Not taking account of input
|
||||
void VirtualDatasetCost::CalculateInputsInMemory(const std::map<size_t, bool> &prev_output_in_mem) {
|
||||
void VirtualDatasetCost::CalculateInputsInMemory(const std::map<size_t, bool> &) {
|
||||
for (size_t i = 0; i < is_inputs_should_in_memory_.size(); ++i) {
|
||||
is_inputs_should_in_memory_[i] = is_parameter_[i];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ bool GetLoopIndexFromCNode(const CNodePtr &cnode, size_t *loop_index) {
|
|||
if (result.length() < 2) {
|
||||
MS_LOG(EXCEPTION) << "Wrong format of fullname_with_scope: " << cnode_fullname;
|
||||
}
|
||||
*loop_index = std::stoi(result[1]);
|
||||
*loop_index = IntToSize(std::stoi(result[1]));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -493,6 +493,7 @@ Status ConstructCostGraphNodesByUniqueIdTC(const std::vector<AnfNodePtr> &all_no
|
|||
if (StrategyCheckpoint::GetInstance().LoadCheckPointOn() &&
|
||||
StrategyCheckpoint::GetInstance().Load(&stra_map) != SUCCESS) {
|
||||
MS_LOG(EXCEPTION) << "Load strategy checkpoint failed";
|
||||
return FAILED;
|
||||
}
|
||||
for (auto &node : all_nodes) {
|
||||
// NOTE: we only care about splittable Primitive operators
|
||||
|
|
|
|||
|
|
@ -46,26 +46,65 @@ class _AlgoParameterConfig():
|
|||
raise ValueError("Config handle is none!!!")
|
||||
|
||||
def set_fully_use_devices(self, not_fully):
|
||||
"""
|
||||
Set the flag of whether ONLY generating strategies that fully use all available devices.
|
||||
Default: True
|
||||
|
||||
Args:
|
||||
not_fully (bool): The flag.
|
||||
"""
|
||||
self.check_config_handle()
|
||||
self._config_handle.set_fully_use_devices(not_fully)
|
||||
|
||||
def get_fully_use_devices(self):
|
||||
"""
|
||||
Get the flag of whether ONLY generating strategies that fully use all available devices.
|
||||
|
||||
Return:
|
||||
The flag.
|
||||
"""
|
||||
self.check_config_handle()
|
||||
return self._config_handle.get_fully_use_devices()
|
||||
|
||||
def set_elementwise_op_strategy_follow(self, element_strategy_follow):
|
||||
"""
|
||||
Set the flag of whether the elementwise operator has the same strategies as its subsequent operators.
|
||||
Default: False
|
||||
|
||||
Args:
|
||||
element_strategy_follow (bool): The flag.
|
||||
"""
|
||||
self.check_config_handle()
|
||||
self._config_handle.set_elementwise_op_strategy_follow(element_strategy_follow)
|
||||
|
||||
def get_elementwise_op_strategy_follow(self):
|
||||
"""
|
||||
Get the flag of whether the elementwise operator has the same strategies as its subsequent operators.
|
||||
|
||||
Returns:
|
||||
The flag.
|
||||
"""
|
||||
self.check_config_handle()
|
||||
return self._config_handle.get_elementwise_op_strategy_follow()
|
||||
|
||||
def set_tensor_slice_align_enable(self, align_enable):
|
||||
"""
|
||||
Set the flag of whether to check the shape of tensor slice of MatMul.
|
||||
Default: False
|
||||
|
||||
Args:
|
||||
align_enable (bool): The flag.
|
||||
"""
|
||||
self.check_config_handle()
|
||||
self._config_handle.set_tensor_slice_align_enable(align_enable)
|
||||
|
||||
def get_tensor_slice_align_enable(self):
|
||||
"""
|
||||
Get the flag of whether to check the shape of tensor slice of MatMul.
|
||||
|
||||
Returns:
|
||||
The flag.
|
||||
"""
|
||||
self.check_config_handle()
|
||||
return self._config_handle.get_tensor_slice_align_enable()
|
||||
|
||||
|
|
@ -85,26 +124,61 @@ class _AlgoParameterConfig():
|
|||
self._config_handle.set_tensor_slice_align_size(align_size)
|
||||
|
||||
def get_tensor_slice_align_size(self):
|
||||
"""
|
||||
Get the tensor slice align size.
|
||||
|
||||
Returns:
|
||||
The size.
|
||||
"""
|
||||
self.check_config_handle()
|
||||
return self._config_handle.get_tensor_slice_align_size()
|
||||
|
||||
def set_dp_algo_enable_approxi(self, enable_flag):
|
||||
"""
|
||||
Set the flag of whether to enable the approximation in the DP algorithms.
|
||||
Default: False.
|
||||
|
||||
Args:
|
||||
enable_flag (bool): The flag.
|
||||
"""
|
||||
self.check_config_handle()
|
||||
self._config_handle.set_dp_algo_enable_approxi(enable_flag)
|
||||
|
||||
def get_dp_algo_enable_approxi(self):
|
||||
"""
|
||||
Get the flag of whether to enable the approximation in the DP algorithms.
|
||||
|
||||
Returns:
|
||||
The flag.
|
||||
"""
|
||||
self.check_config_handle()
|
||||
return self._config_handle.get_dp_algo_enable_approxi()
|
||||
|
||||
def set_dp_algo_approxi_epsilon(self, epsilon):
|
||||
"""
|
||||
Set the epsilon value used in the approximation DP algorithm.
|
||||
Default: 0.1.
|
||||
|
||||
Args:
|
||||
epsilon (float): The epsilon value, should in the range dp_(0, 1].
|
||||
"""
|
||||
self.check_config_handle()
|
||||
self._config_handle.set_dp_algo_approxi_epsilon(epsilon)
|
||||
|
||||
def get_dp_algo_approxi_epsilon(self):
|
||||
"""
|
||||
Get the epsilon value used in the approximation DP algorithm.
|
||||
|
||||
Returns:
|
||||
The epsilon value.
|
||||
"""
|
||||
self.check_config_handle()
|
||||
return self._config_handle.get_dp_algo_approxi_epsilon()
|
||||
|
||||
def reset_algo_parameters(self):
|
||||
"""
|
||||
Reset algorithm parameter attributes.
|
||||
"""
|
||||
self.check_config_handle()
|
||||
self._config_handle.reset_algo_parameters()
|
||||
|
||||
|
|
@ -161,8 +235,8 @@ def set_algo_parameters(**kwargs):
|
|||
Default: True
|
||||
elementwise_op_strategy_follow (bool): Whether the elementwise operator has the same strategies as its
|
||||
subsequent operators. Default: False
|
||||
enable_algo_approxi (bool): Whether to enable the approximation in the DP algorithms.
|
||||
algo_approxi_epsilon (float): The epsilon value used int the approximation DP algorithm.
|
||||
enable_algo_approxi (bool): Whether to enable the approximation in the DP algorithms. Default: False.
|
||||
algo_approxi_epsilon (float): The epsilon value used in the approximation DP algorithm. Default: 0.1.
|
||||
|
||||
Raises:
|
||||
ValueError: If context keyword is not recognized.
|
||||
|
|
|
|||
Loading…
Reference in New Issue