From 70209667e888f2f9f035b2e11afbdc479f2ba815 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Thu, 28 Apr 2022 14:46:19 +0800 Subject: [PATCH] fix(dnn/test): fix some bug when force_deduce_layout is off GitOrigin-RevId: d7ccc397dfdbd9e2c599a24dd072242f69d19027 --- dnn/src/common/fake_quant.cpp | 2 +- dnn/src/common/lsq.cpp | 2 +- dnn/src/common/tqt.cpp | 2 +- dnn/test/common/checker.h | 2 +- dnn/test/common/elemwise.cpp | 2 ++ dnn/test/cuda/check_non_finite.cpp | 9 +++++---- dnn/test/cuda/diag.cpp | 6 +++--- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/dnn/src/common/fake_quant.cpp b/dnn/src/common/fake_quant.cpp index 7dcf39d9..7383e59f 100644 --- a/dnn/src/common/fake_quant.cpp +++ b/dnn/src/common/fake_quant.cpp @@ -16,7 +16,7 @@ namespace megdnn { void FakeQuantBase::deduce_layout_fwd(const TensorLayout& input, TensorLayout& output) { - output = TensorLayout(input, input.dtype); + output = TensorLayout(input); } void FakeQuantBase::check_layout_fwd( diff --git a/dnn/src/common/lsq.cpp b/dnn/src/common/lsq.cpp index 78fbdc49..7f4963d2 100644 --- a/dnn/src/common/lsq.cpp +++ b/dnn/src/common/lsq.cpp @@ -16,7 +16,7 @@ namespace megdnn { void LSQBase::deduce_layout_fwd(const TensorLayout& input, TensorLayout& output) { - output = TensorLayout(input, input.dtype); + output = TensorLayout(input); } void LSQBase::check_layout_fwd( diff --git a/dnn/src/common/tqt.cpp b/dnn/src/common/tqt.cpp index 95a094f5..463af6e9 100644 --- a/dnn/src/common/tqt.cpp +++ b/dnn/src/common/tqt.cpp @@ -16,7 +16,7 @@ namespace megdnn { void TQTBase::deduce_layout_fwd(const TensorLayout& input, TensorLayout& output) { - output = TensorLayout(input, input.dtype); + output = TensorLayout(input); } void TQTBase::check_layout_fwd( diff --git a/dnn/test/common/checker.h b/dnn/test/common/checker.h index 688de2f0..13a8be27 100644 --- a/dnn/test/common/checker.h +++ b/dnn/test/common/checker.h @@ -84,7 +84,7 @@ protected: TensorsConstriant m_tensor_constraint; bool m_no_naive_and_check = false; bool m_stable_check = false; - bool m_force_deduce_dst = true; + bool m_force_deduce_dst = false; bool m_allow_invalid_check = false; /** * the offset from the start of malloc memory diff --git a/dnn/test/common/elemwise.cpp b/dnn/test/common/elemwise.cpp index 90dfbf86..51922571 100644 --- a/dnn/test/common/elemwise.cpp +++ b/dnn/test/common/elemwise.cpp @@ -756,6 +756,8 @@ DEF_TEST(all_modes) { for (size_t i = 0; i < shapes.size() - 1; ++i) { shapes[i] = {3, 9, 7}; } + //! NOTE: force set output layout to empty to trigger layout deduce + shapes[shapes.size() - 1] = {}; auto do_run = [&](DType dtype, float eps = 1e-3) { // limit value ranges for some modes if (mode == Mode::LOG || mode == Mode::LOG1P) { diff --git a/dnn/test/cuda/check_non_finite.cpp b/dnn/test/cuda/check_non_finite.cpp index 3a228466..ed147a81 100644 --- a/dnn/test/cuda/check_non_finite.cpp +++ b/dnn/test/cuda/check_non_finite.cpp @@ -22,16 +22,17 @@ TEST_F(CUDA, CHECK_NON_FINITE_BASIC) { const auto nan = std::numeric_limits::quiet_NaN(); UniformFloatWithValueRNG rng(-1.0f, 1.0f, 0.1f, inf); checker.set_rng(0, &rng); - checker.execs({{512 * 4}, {4}, {1}}); + //! while deduce layout, dst tensor dtype will be set to Int32 + checker.execs({{512 * 4}, {4}, {}}); rng = UniformFloatWithValueRNG(-1.0f, 1.0f, 1.f, inf); checker.set_rng(0, &rng); - checker.execs({{4}, {512 * 4}, {1}}); + checker.execs({{4}, {512 * 4}, {}}); rng = UniformFloatWithValueRNG(-1.0f, 1.0f, 1.f, nan); checker.set_rng(0, &rng); - checker.execs({{32}, {256}, {1}}); + checker.execs({{32}, {256}, {}}); rng = UniformFloatWithValueRNG(-1.0f, 1.0f, 0.f, nan); checker.set_rng(0, &rng); - checker.execs({{16}, {16}, {2}, {1}}); + checker.execs({{16}, {16}, {2}, {}}); } } // namespace test diff --git a/dnn/test/cuda/diag.cpp b/dnn/test/cuda/diag.cpp index dacf8dd2..91d485ca 100644 --- a/dnn/test/cuda/diag.cpp +++ b/dnn/test/cuda/diag.cpp @@ -26,10 +26,10 @@ TEST_F(CUDA, DIAG) { checker.set_dtype(1, dtype); size_t absk = static_cast(std::abs(k)); checker.exec(TensorShapeArray{{8}, {8 + absk, 8 + absk}}); - + //! NOTE: diag for vector or matrix is a vector auto oshape = [&](int n, int m) -> TensorShape { - size_t o = (k >= 0 ? std::min(n - k, m) : std::min(m + k, n)); - return {o, o}; + size_t o = (k >= 0 ? std::min(m - k, n) : std::min(n + k, m)); + return {o}; }; checker.exec(TensorShapeArray{{8, 6}, oshape(8, 6)}); checker.exec(TensorShapeArray{{6, 8}, oshape(6, 8)});