Skip to content

Commit

Permalink
benchmark_app: fix npy batch (openvinotoolkit#25162)
Browse files Browse the repository at this point in the history
Ticket 129902
  • Loading branch information
Wovchena authored Jun 24, 2024
1 parent fe469ee commit 2878545
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions samples/cpp/benchmark_app/inputs_filling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ ov::Tensor create_tensor_from_numpy(const std::vector<std::string>& files,
<< slog::endl;
}

tensor_size = tensor_size / numpy_batch_size;
for (size_t b = 0; b < numpy_batch_size; ++b) {
auto inputIndex = (inputId + b) % files.size();
if (filenames_used) {
Expand Down
16 changes: 16 additions & 0 deletions tests/samples_tests/smoke_tests/test_benchmark_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,19 @@ def test_4bit_precision_input(sample_language, device, inp, cache, tmp_path):
if inp != None and inp.endswith(".bin"):
create_random_4bit_bin_file(tmp_path, inp_shape, inp)
verify(sample_language, device, model=model_4bit, inp=inp, cache=cache, tmp_path=tmp_path, batch=None, tm='1')


@pytest.mark.parametrize('sample_language', ['C++', 'Python'])
@pytest.mark.parametrize('device', get_devices())
def test_out_of_tensor_size_range_npy_multibatch(sample_language, device, cache, tmp_path):
inp = tmp_path / 'batch2.npy'
with open(inp, "wb") as batch2_npy:
np.save(
batch2_npy,
np.random.RandomState(
np.random.MT19937(np.random.SeedSequence(0))
).uniform(0, 256, [2, 3, 224, 224]).astype(np.uint8)
)
# benchmark_app reads batch from model or cmd, not from npy.
# benchmark_app still verifyes npy shape for python impl.
verify(sample_language, device, inp=inp, cache=cache, tmp_path=tmp_path, batch='2')
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def get_numpy_tensors(numpy_paths: List[str], info: AppInputInfo, batch_sizes: L
else:
try:
if info.layout.has_name("N"):
numpy_arrays[[None] * info.layout.get_index_by_name("N") + [b]] = numpy_arr
numpy_arrays[[None] * info.layout.get_index_by_name("N") + [b]] = numpy_arr[b]
else:
numpy_arrays = numpy_arr
except ValueError:
Expand Down Expand Up @@ -308,7 +308,7 @@ def get_binary_tensors(binary_paths: List[str], info: AppInputInfo, batch_sizes:
f"File {binary_filename} contains {binary_file_bit_size} bites but model expects {blob_bit_size}")
from_file = np.fromfile(binary_filename, dtype)
if info.layout.has_name("N"):
binaries[[None] * info.layout.get_index_by_name("N") + [b]] = from_file
binaries[[None] * info.layout.get_index_by_name("N") + [b]] = from_file[b]
else:
binaries = from_file
else:
Expand Down

0 comments on commit 2878545

Please sign in to comment.