Skip to content

Commit 697a46d

Browse files
committed
fix u8 diff with thr 1.
Signed-off-by: xipingya <xiping.yan@intel.com>
1 parent da9ef23 commit 697a46d

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

tests/module_genai/cpp/modules/UniPCMultistepScheduler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ std::vector<UniPCMultistepSchedulerTestData> unipc_multistep_scheduler_test_data
8484
}
8585

8686
class UniPCMultistepSchedulerTest : public ::testing::TestWithParam<UniPCMultistepSchedulerTestData> {
87+
private:
88+
float m_threshold = 1e-2;
8789
public:
8890
static std::string get_test_case_name(const testing::TestParamInfo<UniPCMultistepSchedulerTestData> & obj) {
8991
std::string test_type;
@@ -110,7 +112,7 @@ class UniPCMultistepSchedulerTest : public ::testing::TestWithParam<UniPCMultist
110112
auto sigmas_data = sigmas.data<const float>();
111113

112114
for (size_t i = 0; i < sigmas.get_size(); ++i) {
113-
EXPECT_NEAR(sigmas_data[i], data.expected_sigmas[i], 1e-4);
115+
EXPECT_NEAR(sigmas_data[i], data.expected_sigmas[i], m_threshold);
114116
}
115117

116118
for (size_t i = 0; i < timesteps.size(); ++i) {
@@ -138,7 +140,7 @@ class UniPCMultistepSchedulerTest : public ::testing::TestWithParam<UniPCMultist
138140

139141
latents_data = latents.data<float>();
140142
for (size_t i = 0; i < data.expected_latents.size(); i++) {
141-
EXPECT_NEAR(latents_data[i], data.expected_latents[i], 1e-4);
143+
EXPECT_NEAR(latents_data[i], data.expected_latents[i], m_threshold);
142144
}
143145
}
144146
};

tests/module_genai/cpp/modules/VAEDecoderModule.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct VAEDecoderTestData {
1515
std::vector<uint8_t> expected_output_u8;
1616
std::vector<float> expected_output_f32;
1717
float threshold;
18+
uint8_t threshold_u8;
1819
};
1920

2021
namespace TEST_DATA {
@@ -26,6 +27,7 @@ VAEDecoderTestData vae_decoder_with_postprocess() {
2627
data.enable_postprocess = true;
2728
data.expected_output_u8 = {120, 150, 165, 104, 128, 145, 93, 108, 127, 92};
2829
data.threshold = 0.0f;
30+
data.threshold_u8 = 1;
2931
return data;
3032
}
3133

@@ -37,6 +39,7 @@ VAEDecoderTestData vae_decoder_skip_postprocess() {
3739
data.expected_output_f32 = {-0.0553406f, -0.177907f, -0.268292f, -0.276685f, -0.182945f,
3840
0.0203716f, 0.255036f, 0.342477f, 0.279524f, 0.0960406f};
3941
data.threshold = 1e-2f;
42+
data.threshold_u8 = 1;
4043
return data;
4144
}
4245

@@ -110,7 +113,7 @@ class VAEDecoderModuleTest : public ModuleTestBase, public ::testing::TestWithPa
110113
EXPECT_GT(image.get_size(), 0) << "VAE decoder output is empty";
111114

112115
if (m_test_data.enable_postprocess) {
113-
EXPECT_TRUE(compare_big_tensor<uint8_t>(image, m_test_data.expected_output_u8))
116+
EXPECT_TRUE(compare_big_tensor<uint8_t>(image, m_test_data.expected_output_u8, m_test_data.threshold_u8))
114117
<< "decoder output does not match expected values";
115118
} else {
116119
// Use non-template version that supports threshold for float comparison

tests/module_genai/cpp/utils/ut_modules_base.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class ModuleTestBase {
9595
T exp_val = static_cast<T>(expected_top[i]);
9696
if (std::fabs(val - exp_val) > thr) {
9797
bresult = false;
98-
std::cout << "Mismatch at index " << i << ": expected " << expected_top[i] << ", got " << val
98+
std::cout << "Mismatch at index " << i << ": expected " << static_cast<double>(exp_val) << ", got " << static_cast<double>(val)
9999
<< std::endl;
100100
}
101101
}

0 commit comments

Comments
 (0)