Skip to content

Commit c20433c

Browse files
updated validation for odd elements
1 parent 7a51796 commit c20433c

File tree

1 file changed

+12
-7
lines changed
  • src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes

1 file changed

+12
-7
lines changed

src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/conversion.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -188,26 +188,31 @@ void ConvertCPULayerTest::validate_out_prc() const {
188188
void ConvertCPULayerTest::validate() {
189189
if (outPrc == ov::element::nf4) {
190190
// Use custom bit-exact validation, because common tests infra doesn't support 4bits tensors comparision
191-
auto div_up = [&](auto a, auto b) {
192-
assert(b);
193-
return (a + b - 1) / b;
194-
};
195-
196191
auto actualOutputs = get_plugin_outputs();
197192
auto expectedOutputs = calculate_refs();
198193
ASSERT_EQ(expectedOutputs.size(), actualOutputs.size());
199194
ASSERT_EQ(expectedOutputs.size(), 1);
200195
ASSERT_EQ(expectedOutputs[0].get_shape(), actualOutputs[0].get_shape());
196+
ASSERT_EQ(expectedOutputs[0].get_element_type(), ov::element::nf4);
197+
ASSERT_EQ(expectedOutputs[0].get_element_type(), actualOutputs[0].get_element_type());
201198

202199
auto expected_data = reinterpret_cast<const uint8_t*>(expectedOutputs[0].data());
203200
auto actual_data = reinterpret_cast<const uint8_t*>(actualOutputs[0].data());
204-
size_t shape_size_cnt = div_up(shape_size(expectedOutputs[0].get_shape()), 2);
205-
for (size_t i = 0; i < shape_size_cnt; ++i) {
201+
size_t byte_count = shape_size(expectedOutputs[0].get_shape()) / 2;
202+
bool has_tile = shape_size(expectedOutputs[0].get_shape()) % 2 != 0;
203+
for (size_t i = 0; i < byte_count; ++i) {
206204
uint8_t expected_value = expected_data[i];
207205
uint8_t actual_value = actual_data[i];
208206
ASSERT_EQ(expected_value, actual_value);
209207
}
210208

209+
// Convert operation doc doesn't specify behavior for odd amount of elements: should upper 4 bits of last byte be filled with zeros or not.
210+
// CPU Plugin fills these bits with zeros as it better fits optimized kernels which get NF4 inputs.
211+
// In general it is considered as UB, so skip the check for last 4 bits.
212+
if (has_tile) {
213+
ASSERT_EQ(expected_data[byte_count] & 0x0F, actual_data[byte_count] & 0x0F);
214+
}
215+
211216
return;
212217
}
213218

0 commit comments

Comments
 (0)