Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tests/python_tests/test_llm_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ def test_encoded_inputs(
assert np.all(ov_res == hf_res)


@pytest.mark.parametrize("llm_model", ["katuni4ka/tiny-random-phi3"], indirect=True)
def test_readonly_input_tensor(ov_pipe: ov_genai.LLMPipeline) -> None:
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test calls ov_pipe.generate() twice but does not validate the outputs. Add assertions to confirm that generation succeeds and produces non-empty results when using read-only tensors.

Copilot uses AI. Check for mistakes.
input_ids = np.array([[1, 4, 42]], dtype=np.int64)
input_ids.flags.writeable = False

attention_mask = np.array([[1, 1, 1]], dtype=np.int64)
attention_mask.flags.writeable = False

inputs_ov = ov_genai.TokenizedInputs(ov.Tensor(input_ids), ov.Tensor(attention_mask))
ov_pipe.generate(inputs_ov, max_new_tokens=5)

readonly_tensor = ov.Tensor(input_ids)
ov_pipe.generate(readonly_tensor, max_new_tokens=5)


@pytest.mark.parametrize("llm_model", MODELS_LIST, indirect=True)
@pytest.mark.parametrize("generation_config_dict", TEST_CONFIGS)
@pytest.mark.parametrize("prompts", BATCHED_PROMPTS)
Expand Down Expand Up @@ -878,4 +893,3 @@ def test_pipelines_generate_with_streaming(
mock_streamer.assert_not_called()
else:
mock_streamer.assert_called()

20 changes: 19 additions & 1 deletion tests/python_tests/test_llm_pipeline_static.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright (C) 2024-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from openvino_genai import GenerationConfig, Tokenizer, LLMPipeline, StreamerBase, ChatHistory
from openvino_genai import GenerationConfig, Tokenizer, LLMPipeline, StreamerBase, ChatHistory, TokenizedInputs
from pathlib import Path

import openvino as ov
import numpy as np
import pytest
import platform
import sys
Expand Down Expand Up @@ -419,3 +421,19 @@ def generate_with_chat_history(pipe: LLMPipeline, questions: list[str]) -> ChatH
f"NPU chat mode output:\n{answers_chat_mode_static}\n"
f"NPU chat history output:\n{answers_chat_history_static}"
)


@pytest.mark.parametrize("llm_model", MODELS_LIST, indirect=True)
@pytest.mark.parametrize("npu_config", PIPELINE_CONFIGS, indirect=True)
def test_readonly_input_tensor(npu_model: LLMPipeline):
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test calls npu_model.generate() twice but does not capture or validate the outputs. Add assertions to verify that generation completes successfully and produces expected results when using read-only tensors.

Copilot uses AI. Check for mistakes.
input_ids = np.array([[1, 4, 42]], dtype=np.int64)
input_ids.flags.writeable = False

attention_mask = np.array([[1, 1, 1]], dtype=np.int64)
attention_mask.flags.writeable = False

inputs_ov = TokenizedInputs(ov.Tensor(input_ids), ov.Tensor(attention_mask))
npu_model.generate(inputs_ov, max_new_tokens=5)

readonly_tensor = ov.Tensor(input_ids)
npu_model.generate(readonly_tensor, max_new_tokens=5)
16 changes: 16 additions & 0 deletions tests/python_tests/test_vlm_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,22 @@ def streamer(word: str) -> bool:
assert res.texts[0] == "".join(result_from_streamer)


@parametrize_one_model_sdpa
def test_vlm_readonly_image_tensor(ov_pipe_model: VlmModelInfo, cat_image_32x32):
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test calls ov_pipe.generate() but does not verify the output or assert that generation succeeded. Consider adding an assertion to check that the result is not empty or meets expected criteria to ensure the read-only tensor is properly handled.

Copilot uses AI. Check for mistakes.
ov_pipe = ov_pipe_model.pipeline
generation_config = _setup_generation_config(ov_pipe, max_new_tokens=5)

image_array = np.array(cat_image_32x32, dtype=np.uint8)
image_array.flags.writeable = False

readonly_image_tensor = openvino.Tensor(image_array)
ov_pipe.generate(
PROMPTS[0],
images=[readonly_image_tensor],
generation_config=generation_config,
)


@pytest.mark.parametrize(
"config",
[
Expand Down
Loading