-
Notifications
You must be signed in to change notification settings - Fork 310
Fix const casting in non-writable numpy-based tensors #3086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
@@ -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): | ||
|
||
| 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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
||
| 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", | ||
| [ | ||
|
|
||
There was a problem hiding this comment.
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.