forked from openvinotoolkit/openvino.genai
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge releases/2024/5 into master (openvinotoolkit#1168)
Co-authored-by: yatarkan <[email protected]> Co-authored-by: Ilya Lavrenov <[email protected]> Co-authored-by: TolyaTalamanov <[email protected]> Co-authored-by: wgzintel <[email protected]> Co-authored-by: Sergey Lyalin <[email protected]>
- Loading branch information
1 parent
809d93e
commit 747c5d2
Showing
12 changed files
with
420 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: 'Build App' | ||
inputs: | ||
ov_dir: | ||
description: 'Directory where OpenVINO is installed' | ||
default: './ov' | ||
required: false | ||
build_dir: | ||
description: 'Directory where the app is built' | ||
default: './build' | ||
required: false | ||
build_target: | ||
description: 'Target to build' | ||
default: '' | ||
required: false | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Build app | ||
shell: bash | ||
run: | | ||
source ${{ inputs.ov_dir }}/setupvars.sh | ||
cmake -DCMAKE_BUILD_TYPE=Release -S ./ -B ${{ inputs.build_dir }} | ||
cmake --build ${{ inputs.build_dir }} --config Release ${{ inputs.build_target && format('--target {0}', inputs.build_target) || '' }} -j |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: 'Install OpenVINO' | ||
inputs: | ||
ov_link: | ||
description: 'URL to download OpenVINO' | ||
required: true | ||
ov_dir: | ||
description: 'Directory to install OpenVINO' | ||
default: './ov' | ||
required: false | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: 'Install OpenVINO' | ||
shell: bash | ||
run: | | ||
mkdir ${{ inputs.ov_dir }} | ||
curl ${{ inputs.ov_link }} | tar --directory ${{ inputs.ov_dir }} --strip-components 1 -xz | ||
sudo ${{ inputs.ov_dir }}/install_dependencies/install_openvino_dependencies.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: 'Install Python Dependencies' | ||
inputs: | ||
ov_dir: | ||
description: 'Directory where OpenVINO is installed' | ||
default: './ov' | ||
required: false | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Install Python dependencies | ||
shell: bash | ||
run: | | ||
source ${{ inputs.ov_dir }}/setupvars.sh | ||
python -m pip install ./thirdparty/openvino_tokenizers/[transformers] --pre --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly | ||
python -m pip install --upgrade-strategy eager -r ./samples/requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import argparse | ||
from pathlib import Path | ||
from optimum.intel.openvino import OVModelForVisualCausalLM | ||
from transformers import AutoProcessor | ||
from PIL import Image | ||
|
||
IMAGE_EXTENSIONS = [".jpg", ".jpeg", ".png", ".bmp"] | ||
|
||
|
||
def main(model_path: str, images_path: str): | ||
print(f"Selected model: {model_path}\n") | ||
|
||
if Path(images_path).is_file(): | ||
image_files = [Path(images_path)] | ||
else: | ||
image_files = sorted( | ||
[f for f in Path(images_path).glob("*") if f.is_file() and f.suffix.lower() in IMAGE_EXTENSIONS], | ||
key=lambda x: x.name | ||
) | ||
|
||
if not image_files: | ||
raise FileNotFoundError(f"No images found in '{images_path}' directory. Supported formats: {IMAGE_EXTENSIONS}") | ||
|
||
images = [] | ||
for file in image_files: | ||
images.append( | ||
Image.open(file).convert("RGB") | ||
) | ||
|
||
print("Images:", image_files) | ||
|
||
model = OVModelForVisualCausalLM.from_pretrained(model_path, trust_remote_code=True) | ||
processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True) | ||
|
||
conversation = [{ | ||
"role": "user", | ||
"content": [ | ||
*[{"type": "image"} for _ in images], | ||
{"type": "text", "text": "Describe the images."}, | ||
], | ||
}] | ||
|
||
prompt = processor.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True) | ||
print(prompt) | ||
inputs = processor(text=[prompt], images=images, return_tensors="pt") | ||
result = model.generate(**inputs, max_new_tokens=100, do_sample=False) | ||
decoded = processor.tokenizer.batch_decode(result[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)[0] | ||
print(decoded) | ||
with open("ref.txt", "w") as f: | ||
f.write(f"question:\n{decoded}\n----------\nquestion:\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-m", "--model_path", type=str, required=True, help="Path to the model.") | ||
parser.add_argument("-i", "--images_path", type=str, required=True, help="Path to the directory with images.") | ||
args = parser.parse_args() | ||
main(args.model_path, args.images_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: visual_language_chat sample - LLaVA | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
model_id: | ||
required: true | ||
type: string | ||
model_dir: | ||
required: true | ||
type: string | ||
|
||
env: | ||
l_u22_ov_link: https://storage.openvinotoolkit.org/repositories/openvino/packages/nightly/2025.0.0-17289-7cf2bbb8391/l_openvino_toolkit_ubuntu22_2025.0.0.dev20241105_x86_64.tgz | ||
jobs: | ||
visual_language_chat_sample-ubuntu-llava: | ||
runs-on: ubuntu-22.04-16-cores | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.11 | ||
- uses: ./.github/actions/install_openvino | ||
with: | ||
ov_link: ${{ env.l_u22_ov_link }} | ||
- uses: ./.github/actions/build_app | ||
with: | ||
build_target: 'visual_language_chat py_openvino_genai' | ||
- uses: ./.github/actions/install_python_deps | ||
- name: Download and convert model | ||
run: | | ||
source ./ov/setupvars.sh | ||
optimum-cli export openvino --model ${{ inputs.model_id }} ./${{ inputs.model_dir }} | ||
- name: Download images | ||
run: | | ||
wget https://llava-vl.github.io/static/images/monalisa.jpg | ||
- name: Run visual_language_chat C++ sample | ||
run: > | ||
source ./ov/setupvars.sh | ||
&& ./build/samples/cpp/visual_language_chat/visual_language_chat ./${{ inputs.model_dir }} monalisa.jpg | ||
<<< $'Who drew this painting?\nWhen did the painter live?' | ||
timeout-minutes: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.