forked from mindspore-Ecosystem/mindspore
Fix I5IZU7 optimize log && clean pclint-plus warnings
Add loss to cfg instead train_cfg
This commit is contained in:
parent
229ed3b7a6
commit
4ba1af2f2c
|
@ -60,8 +60,8 @@ class TrainCfg {
|
||||||
~TrainCfg() = default;
|
~TrainCfg() = default;
|
||||||
|
|
||||||
OptimizationLevel optimization_level_ = kO0;
|
OptimizationLevel optimization_level_ = kO0;
|
||||||
std::vector<std::string> loss_name_ = {"loss_fct",
|
std::vector<std::string> loss_name_ = {
|
||||||
"_loss_fn"}; /**< Set part of the name that identify a loss kernel */
|
"loss_fct", "_loss_fn", "SigmoidCrossEntropy"}; /**< Set part of the name that identify a loss kernel */
|
||||||
MixPrecisionCfg mix_precision_cfg_; /**< Mix precision configuration */
|
MixPrecisionCfg mix_precision_cfg_; /**< Mix precision configuration */
|
||||||
bool accumulate_gradients_ = false;
|
bool accumulate_gradients_ = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,11 +20,11 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include "pybind11/pytypes.h"
|
||||||
#include "utils/hash_map.h"
|
#include "utils/hash_map.h"
|
||||||
#include "utils/ms_utils.h"
|
#include "utils/ms_utils.h"
|
||||||
#include "ir/anf.h"
|
#include "ir/anf.h"
|
||||||
#include "ir/signature.h"
|
#include "ir/signature.h"
|
||||||
#include "pybind11/pytypes.h"
|
|
||||||
|
|
||||||
namespace mindspore::pynative {
|
namespace mindspore::pynative {
|
||||||
struct AbsCacheKey {
|
struct AbsCacheKey {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <cmath>
|
||||||
#include "plugin/device/cpu/hal/device/cpu_device_address.h"
|
#include "plugin/device/cpu/hal/device/cpu_device_address.h"
|
||||||
|
|
||||||
namespace mindspore {
|
namespace mindspore {
|
||||||
|
@ -27,11 +28,7 @@ static constexpr int MAX_DIMS = 7;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T GetDivZeroVal(const T &v) {
|
T GetDivZeroVal(const T &v) {
|
||||||
auto zero = static_cast<T>(0.0);
|
auto zero = static_cast<T>(0.0);
|
||||||
if (std::numeric_limits<T>::has_infinity) {
|
|
||||||
return v > zero ? std::numeric_limits<T>::infinity() : -std::numeric_limits<T>::infinity();
|
return v > zero ? std::numeric_limits<T>::infinity() : -std::numeric_limits<T>::infinity();
|
||||||
} else {
|
|
||||||
return v > zero ? std::numeric_limits<T>::max() : std::numeric_limits<T>::min();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
@ -40,28 +37,42 @@ complex128 GetDivZeroVal(const complex128 &v) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
complex64 GetDivZeroVal(const complex64 &v) {
|
complex64 GetDivZeroVal(const complex64 &) {
|
||||||
return std::numeric_limits<complex64>::quiet_NaN();
|
return std::numeric_limits<complex64>::quiet_NaN();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
bool isZero(T val) {
|
||||||
|
return val == T(0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
bool isZero(float val) {
|
||||||
|
return std::fpclassify(val) == FP_ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
bool isZero(double val) {
|
||||||
|
return std::fpclassify(val) == FP_ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool XdivyCpuKernelMod::LaunchKernel(const std::vector<kernel::AddressPtr> &inputs,
|
bool XdivyCpuKernelMod::LaunchKernel(const std::vector<kernel::AddressPtr> &inputs,
|
||||||
const std::vector<kernel::AddressPtr> &,
|
const std::vector<kernel::AddressPtr> &,
|
||||||
const std::vector<kernel::AddressPtr> &outputs) {
|
const std::vector<kernel::AddressPtr> &outputs) {
|
||||||
CHECK_KERNEL_INPUTS_NUM(inputs.size(), INPUT_NUM, kernel_name_);
|
CHECK_KERNEL_INPUTS_NUM(inputs.size(), INPUT_NUM, kernel_name_);
|
||||||
CHECK_KERNEL_OUTPUTS_NUM(outputs.size(), OUTPUT_NUM, kernel_name_);
|
CHECK_KERNEL_OUTPUTS_NUM(outputs.size(), OUTPUT_NUM, kernel_name_);
|
||||||
auto x_addr = reinterpret_cast<T *>(inputs[0]->addr);
|
auto x_addr = static_cast<T *>(inputs[0]->addr);
|
||||||
auto y_addr = reinterpret_cast<T *>(inputs[1]->addr);
|
auto y_addr = static_cast<T *>(inputs[1]->addr);
|
||||||
auto output_addr = reinterpret_cast<T *>(outputs[0]->addr);
|
auto output_addr = static_cast<T *>(outputs[0]->addr);
|
||||||
size_t output_size = outputs[0]->size / sizeof(T);
|
size_t output_size = outputs[0]->size / sizeof(T);
|
||||||
auto sameShapeTask = [&x_addr, &y_addr, &output_addr](size_t start, size_t end) {
|
auto sameShapeTask = [&x_addr, &y_addr, &output_addr](size_t start, size_t end) {
|
||||||
for (size_t i = start; i < end; i++) {
|
for (size_t i = start; i < end; i++) {
|
||||||
auto dividend = x_addr[i];
|
auto dividend = x_addr[i];
|
||||||
auto divisor = y_addr[i];
|
auto divisor = y_addr[i];
|
||||||
auto zero = (T)0;
|
if (isZero(divisor)) {
|
||||||
if (divisor == zero) {
|
if (isZero(dividend)) {
|
||||||
if (dividend == zero) {
|
output_addr[i] = static_cast<T>(0.0);
|
||||||
output_addr[i] = zero;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output_addr[i] = GetDivZeroVal(dividend);
|
output_addr[i] = GetDivZeroVal(dividend);
|
||||||
|
@ -217,7 +228,7 @@ int XdivyCpuKernelMod::Resize(const BaseOperatorPtr &base_operator, const std::v
|
||||||
GetBroadCastIndex(x_shape, out_shape, &index_listx_);
|
GetBroadCastIndex(x_shape, out_shape, &index_listx_);
|
||||||
GetBroadCastIndex(y_shape, out_shape, &index_listy_);
|
GetBroadCastIndex(y_shape, out_shape, &index_listy_);
|
||||||
}
|
}
|
||||||
return KRET_OK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<KernelAttr> XdivyCpuKernelMod::GetOpSupport() { return support_ops_; }
|
std::vector<KernelAttr> XdivyCpuKernelMod::GetOpSupport() { return support_ops_; }
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#include <complex>
|
#include <complex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <utility>
|
|
||||||
#include "plugin/device/cpu/kernel/cpu_kernel.h"
|
#include "plugin/device/cpu/kernel/cpu_kernel.h"
|
||||||
#include "plugin/factory/ms_factory.h"
|
#include "plugin/factory/ms_factory.h"
|
||||||
|
|
||||||
|
@ -41,9 +40,9 @@ class XdivyCpuKernelMod : public NativeCpuKernelMod {
|
||||||
int Resize(const BaseOperatorPtr &base_operator, const std::vector<KernelTensorPtr> &inputs,
|
int Resize(const BaseOperatorPtr &base_operator, const std::vector<KernelTensorPtr> &inputs,
|
||||||
const std::vector<KernelTensorPtr> &outputs, const std::map<uint32_t, tensor::TensorPtr> &) override;
|
const std::vector<KernelTensorPtr> &outputs, const std::map<uint32_t, tensor::TensorPtr> &) override;
|
||||||
|
|
||||||
protected:
|
|
||||||
std::vector<KernelAttr> GetOpSupport() override;
|
std::vector<KernelAttr> GetOpSupport() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
void ResetResource() noexcept {
|
void ResetResource() noexcept {
|
||||||
input_size_list_.clear();
|
input_size_list_.clear();
|
||||||
output_size_list_.clear();
|
output_size_list_.clear();
|
||||||
|
|
|
@ -781,8 +781,8 @@ void FuncGraphManager::CommitChanges(std::vector<change::ChangePtr> &&changes) {
|
||||||
|
|
||||||
void FuncGraphManager::EraseOneGraph(const FuncGraphPtr &fg) {
|
void FuncGraphManager::EraseOneGraph(const FuncGraphPtr &fg) {
|
||||||
MS_EXCEPTION_IF_NULL(fg);
|
MS_EXCEPTION_IF_NULL(fg);
|
||||||
size_t erase_cnt = func_graphs_.erase(fg->shared_from_base<FuncGraph>());
|
bool erase_ret = func_graphs_.erase(fg->shared_from_base<FuncGraph>());
|
||||||
if (!erase_cnt) {
|
if (!erase_ret) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fg->DecAttachedMngCnt();
|
fg->DecAttachedMngCnt();
|
||||||
|
|
|
@ -617,7 +617,7 @@ class PConstant : public PBase<PConstant<T> > {
|
||||||
MS_EXCEPTION_IF_NULL(source_data);
|
MS_EXCEPTION_IF_NULL(source_data);
|
||||||
if (x_tensor_ptr->DataSize() == 1) {
|
if (x_tensor_ptr->DataSize() == 1) {
|
||||||
auto tensor_type_byte = GetTypeByte(tensor_type_ptr);
|
auto tensor_type_byte = GetTypeByte(tensor_type_ptr);
|
||||||
char *data = reinterpret_cast<char *>(new_tensor_ptr->data_c());
|
char *data = static_cast<char *>(new_tensor_ptr->data_c());
|
||||||
for (int i = 0; i < new_tensor_ptr->ElementsNum(); i++) {
|
for (int i = 0; i < new_tensor_ptr->ElementsNum(); i++) {
|
||||||
ret = memcpy_s(data + IntToSize(i) * tensor_type_byte, tensor_type_byte, source_data, tensor_type_byte);
|
ret = memcpy_s(data + IntToSize(i) * tensor_type_byte, tensor_type_byte, source_data, tensor_type_byte);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
@ -626,7 +626,7 @@ class PConstant : public PBase<PConstant<T> > {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char *data = reinterpret_cast<char *>(new_tensor_ptr->data_c());
|
char *data = static_cast<char *>(new_tensor_ptr->data_c());
|
||||||
ret = memcpy_s(data, new_tensor_ptr->Size(), source_data, new_tensor_ptr->Size());
|
ret = memcpy_s(data, new_tensor_ptr->Size(), source_data, new_tensor_ptr->Size());
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
MS_LOG(INFO) << "memcpy_s error, error no " << ret << ", source size " << new_tensor_ptr->Size()
|
MS_LOG(INFO) << "memcpy_s error, error no " << ret << ", source size " << new_tensor_ptr->Size()
|
||||||
|
|
|
@ -49,10 +49,10 @@ abstract::ShapePtr ExtractVolumePatchesInferShape(const PrimitivePtr &primitive,
|
||||||
primitive->name());
|
primitive->name());
|
||||||
auto padding = GetValue<std::string>(primitive->GetAttr(kPadding));
|
auto padding = GetValue<std::string>(primitive->GetAttr(kPadding));
|
||||||
for (auto &item : strides) {
|
for (auto &item : strides) {
|
||||||
(void)CheckAndConvertUtils::Check("strides", item, kGreaterThan, 0, primitive->name());
|
CheckAndConvertUtils::Check("strides", item, kGreaterThan, 0, primitive->name());
|
||||||
}
|
}
|
||||||
for (auto &item : kernel_size) {
|
for (auto &item : kernel_size) {
|
||||||
(void)CheckAndConvertUtils::Check("kernel_size", item, kGreaterThan, 0, primitive->name());
|
CheckAndConvertUtils::Check("kernel_size", item, kGreaterThan, 0, primitive->name());
|
||||||
}
|
}
|
||||||
std::vector<int64_t> y_shape(5);
|
std::vector<int64_t> y_shape(5);
|
||||||
int64_t padding_needed = 0;
|
int64_t padding_needed = 0;
|
||||||
|
|
|
@ -291,9 +291,9 @@ def check_type_valid(dtype, target_type, op_name):
|
||||||
if dtype != target_type and (isinstance(target_type, (list, tuple)) and dtype not in target_type):
|
if dtype != target_type and (isinstance(target_type, (list, tuple)) and dtype not in target_type):
|
||||||
if op_name in (TENSOR_GETITEM, TENSOR_SETITEM):
|
if op_name in (TENSOR_GETITEM, TENSOR_SETITEM):
|
||||||
raise IndexError(
|
raise IndexError(
|
||||||
f"The '{op_name}' doesn't support {dtype}' and expect to receive {target_type}.")
|
f"The '{op_name}' doesn't support '{dtype}' and expect to receive {target_type}.")
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
f"The '{op_name}' doesn't support {dtype}' and expect to receive {target_type}.")
|
f"The '{op_name}' doesn't support '{dtype}' and expect to receive {target_type}.")
|
||||||
|
|
||||||
|
|
||||||
@constexpr
|
@constexpr
|
||||||
|
|
Loading…
Reference in New Issue