From c7f01474c2ee69e48d204c4187fbd0caa5e2d584 Mon Sep 17 00:00:00 2001 From: Anurag Dixit Date: Wed, 11 May 2022 13:59:31 -0700 Subject: [PATCH 1/3] feat(//tests): Update rtol and atol based tolerance for test Signed-off-by: Anurag Dixit --- tests/util/util.cpp | 5 +++-- tests/util/util.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/util/util.cpp b/tests/util/util.cpp index f58291d2a8..8e07ea46a1 100644 --- a/tests/util/util.cpp +++ b/tests/util/util.cpp @@ -5,13 +5,14 @@ namespace torch_tensorrt { namespace tests { namespace util { -bool almostEqual(const at::Tensor& a, const at::Tensor& b, float threshold, float atol = 1e-8, float rtol = 1e-5) { +bool almostEqual(const at::Tensor& a, const at::Tensor& b, float atol = 1e-8, float rtol = 1e-5) { LOG_GRAPH(a << std::endl << b << std::endl); auto a_float = a.toType(at::kFloat); auto b_float = b.toType(at::kFloat); auto diff = a_float - b_float; - auto result = diff.abs().max().item() - (atol + rtol * b.abs().max().item()); + auto result = diff.abs().max().item(); + auto threshold = atol + (rtol * b.abs().max().item()); std::cout << "Max Difference: " << result << std::endl; std::cout << "Acceptable Threshold: " << threshold << std::endl; diff --git a/tests/util/util.h b/tests/util/util.h index b795667fa4..72e3f2b348 100644 --- a/tests/util/util.h +++ b/tests/util/util.h @@ -11,7 +11,7 @@ namespace torch_tensorrt { namespace tests { namespace util { -bool almostEqual(const at::Tensor& a, const at::Tensor& b, float threshold, float atol = 1e-8, float rtol = 1e-5); +bool almostEqual(const at::Tensor& a, const at::Tensor& b, float atol = 1e-8, float rtol = 1e-5); bool exactlyEqual(const at::Tensor& a, const at::Tensor& b); From 00adb2193859855287c116bf7d6fc10c76537b4d Mon Sep 17 00:00:00 2001 From: Anurag Dixit Date: Tue, 31 May 2022 16:04:10 -0700 Subject: [PATCH 2/3] chore!: Changing the names of tensor Signed-off-by: Anurag Dixit --- tests/util/util.cpp | 28 ++++++++++++++++------------ tests/util/util.h | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/tests/util/util.cpp b/tests/util/util.cpp index 8e07ea46a1..6dc0d814a6 100644 --- a/tests/util/util.cpp +++ b/tests/util/util.cpp @@ -5,26 +5,30 @@ namespace torch_tensorrt { namespace tests { namespace util { -bool almostEqual(const at::Tensor& a, const at::Tensor& b, float atol = 1e-8, float rtol = 1e-5) { - LOG_GRAPH(a << std::endl << b << std::endl); - auto a_float = a.toType(at::kFloat); - auto b_float = b.toType(at::kFloat); +bool almostEqual(const at::Tensor& computed_tensor, const at::Tensor& gt_tensor, float atol = 1e-8, float rtol = 1e-5) { + std::ostringstream ss; + ss << computed_tensor << std::endl << gt_tensor << std::endl; + ss << " atol: " << atol << " rtol: " << rtol << std::endl; - auto diff = a_float - b_float; + LOG_GRAPH(ss.str()); + auto computed_tensor_float = computed_tensor.toType(at::kFloat); + auto gt_tensor_float = gt_tensor.toType(at::kFloat); + + auto diff = computed_tensor_float - gt_tensor_float; auto result = diff.abs().max().item(); - auto threshold = atol + (rtol * b.abs().max().item()); + auto threshold = atol + (rtol * gt_tensor.abs().max().item()); - std::cout << "Max Difference: " << result << std::endl; - std::cout << "Acceptable Threshold: " << threshold << std::endl; + LOG_GRAPH(std::string("Max Difference: ") + std::to_string(result) ); + LOG_GRAPH(std::string("Acceptable Threshold: ") + std::to_string(threshold)); return result <= threshold; } -bool exactlyEqual(const at::Tensor& a, const at::Tensor& b) { - LOG_GRAPH(a << std::endl << b << std::endl); - std::cout << "Max Difference: " << (a - b).abs().max().item() << std::endl; +bool exactlyEqual(const at::Tensor& computed_tensor, const at::Tensor& gt_tensor) { + LOG_GRAPH(computed_tensor << std::endl << gt_tensor << std::endl); + std::cout << "Max Difference: " << (computed_tensor - gt_tensor).abs().max().item() << std::endl; - return (a - b).abs().max().item() == 0.f; + return (computed_tensor - gt_tensor).abs().max().item() == 0.f; } } // namespace util diff --git a/tests/util/util.h b/tests/util/util.h index 72e3f2b348..f39e2a5766 100644 --- a/tests/util/util.h +++ b/tests/util/util.h @@ -11,7 +11,7 @@ namespace torch_tensorrt { namespace tests { namespace util { -bool almostEqual(const at::Tensor& a, const at::Tensor& b, float atol = 1e-8, float rtol = 1e-5); +bool almostEqual(const at::Tensor& computed_tensor, const at::Tensor& gt_tensor, float atol = 1e-8, float rtol = 1e-5); bool exactlyEqual(const at::Tensor& a, const at::Tensor& b); From 0f26bed9c92d2543f654ce4e43ac20fda2693d9d Mon Sep 17 00:00:00 2001 From: Anurag Dixit Date: Thu, 2 Jun 2022 10:08:19 -0700 Subject: [PATCH 3/3] chore: Applying lint Signed-off-by: Anurag Dixit --- tests/util/util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/util/util.cpp b/tests/util/util.cpp index 6dc0d814a6..13d0d18566 100644 --- a/tests/util/util.cpp +++ b/tests/util/util.cpp @@ -18,7 +18,7 @@ bool almostEqual(const at::Tensor& computed_tensor, const at::Tensor& gt_tensor, auto result = diff.abs().max().item(); auto threshold = atol + (rtol * gt_tensor.abs().max().item()); - LOG_GRAPH(std::string("Max Difference: ") + std::to_string(result) ); + LOG_GRAPH(std::string("Max Difference: ") + std::to_string(result)); LOG_GRAPH(std::string("Acceptable Threshold: ") + std::to_string(threshold)); return result <= threshold;