@@ -188,26 +188,31 @@ void ConvertCPULayerTest::validate_out_prc() const {
188
188
void ConvertCPULayerTest::validate () {
189
189
if (outPrc == ov::element::nf4) {
190
190
// 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
-
196
191
auto actualOutputs = get_plugin_outputs ();
197
192
auto expectedOutputs = calculate_refs ();
198
193
ASSERT_EQ (expectedOutputs.size (), actualOutputs.size ());
199
194
ASSERT_EQ (expectedOutputs.size (), 1 );
200
195
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 ());
201
198
202
199
auto expected_data = reinterpret_cast <const uint8_t *>(expectedOutputs[0 ].data ());
203
200
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) {
206
204
uint8_t expected_value = expected_data[i];
207
205
uint8_t actual_value = actual_data[i];
208
206
ASSERT_EQ (expected_value, actual_value);
209
207
}
210
208
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
+
211
216
return ;
212
217
}
213
218
0 commit comments