提交 78375e10 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!3680 lowering value checking threshold to fix bug of pass eps

Merge pull request !3680 from wangnan39/lowering_value_checking_threshold_to_support_training_with_very_small_steps
......@@ -404,16 +404,18 @@ class PConstant : public PBase<PConstant<T> > {
TypeId tensor_type = tensor_ptr->Dtype()->type_id();
if ((tensor_type == TypeId::kNumberTypeFloat32) || (tensor_type == TypeId::kNumberTypeFloat)) {
float *data2 = reinterpret_cast<float *>(tensor_ptr->data_c());
auto threshold = FLT_EPSILON * FLT_EPSILON;
for (int i = 0; i < tensor_ptr->DataSize(); i++) {
if (fabs(data2[i] - check_value_) > FLT_EPSILON) {
if (fabs(data2[i] - check_value_) > threshold) {
return false;
}
}
return true;
} else if (tensor_type == TypeId::kNumberTypeFloat64) {
double *data2 = reinterpret_cast<double *>(tensor_ptr->data_c());
auto threshold = DBL_EPSILON * DBL_EPSILON;
for (int i = 0; i < tensor_ptr->DataSize(); i++) {
if (fabs(data2[i] - check_value_) > DBL_EPSILON) {
if (fabs(data2[i] - check_value_) > threshold) {
return false;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册