From b4c57295f7b3832880f3c52d4388dbc0febc2b9f Mon Sep 17 00:00:00 2001 From: Hoai Linh Tran Date: Tue, 28 Jul 2020 23:26:04 -0400 Subject: [PATCH] Lowering value checking threshold to support training with very small steps --- mindspore/core/ir/pattern_matcher.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mindspore/core/ir/pattern_matcher.h b/mindspore/core/ir/pattern_matcher.h index 327e47e20d..7a6e1f7ab9 100644 --- a/mindspore/core/ir/pattern_matcher.h +++ b/mindspore/core/ir/pattern_matcher.h @@ -484,16 +484,18 @@ class PConstant : public PBase > { TypeId tensor_type = tensor_ptr->Dtype()->type_id(); if ((tensor_type == TypeId::kNumberTypeFloat32) || (tensor_type == TypeId::kNumberTypeFloat)) { float *data2 = reinterpret_cast(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(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; } }