Browse Source

!3637 Lowering value checking threshold to support training with very small steps or

Merge pull request !3637 from thlinh/dev_Jul28_lower_checking_threshold
tags/v0.7.0-beta
mindspore-ci-bot Gitee 5 years ago
parent
commit
e4a7ca7f08
1 changed files with 4 additions and 2 deletions
  1. +4
    -2
      mindspore/core/ir/pattern_matcher.h

+ 4
- 2
mindspore/core/ir/pattern_matcher.h View File

@@ -484,16 +484,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;
}
}


Loading…
Cancel
Save