### Install Sample Binaries Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/tools/continuous_batching/accuracy/CMakeLists.txt Installs the defined targets to the 'samples_bin/' directory as runtime components. This makes the compiled executables accessible after installation. ```cmake install(TARGETS ${TARGET_NAME} ${TARGET_NAME_CB} RUNTIME DESTINATION samples_bin/ COMPONENT tools_bin EXCLUDE_FROM_ALL) ``` -------------------------------- ### Install Dependencies Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/site/README.md Run this command to install all project dependencies. ```bash $ npm i ``` -------------------------------- ### Install Dependencies for Running Samples Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/python/video_generation/README.md Installs necessary packages to run the OpenVINO GenAI samples. Use the --upgrade-strategy eager option to ensure the latest versions are installed. ```sh pip install --upgrade-strategy eager -r ../../deployment-requirements.txt ``` -------------------------------- ### Example Text to Video Generation Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/video_generation/README.md Provides a concrete example of running the text-to-video sample with the LTX-Video model and a specific prompt. ```bash ./text2video ltx_video_ov/FP32 "A woman with long brown hair and light skin smiles at another woman with long blonde hair" ``` -------------------------------- ### Install Executable Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/whisper_speech_recognition/CMakeLists.txt Installs the 'whisper_speech_recognition' executable to the 'samples_bin/' directory at runtime. This ensures the sample application is placed in the correct location after installation. ```cmake install(TARGETS whisper_speech_recognition RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL) ``` -------------------------------- ### Install WWB from Source Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/tools/who_what_benchmark/README.md Install the WWB tool from its source directory using pip. This command installs the core package and its required dependencies. ```bash pip install . ``` -------------------------------- ### Install Node.js dependencies Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/js/speech_generation/README.md Install project dependencies from the samples/js directory. ```bash npm install ``` -------------------------------- ### Start Local Development Server Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/site/README.md Starts a local development server that reflects changes live without requiring a restart. ```bash $ npm run start ``` -------------------------------- ### Set Up Environment with setupvars.sh Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/docs/BUILD.md Source the OpenVINO setupvars.sh script to configure the build environment. Replace with your OpenVINO installation path. ```sh source /setupvars.sh ``` -------------------------------- ### Run Text to Image Generation Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/image_generation/README.md Executes the text-to-image generation sample with a specified prompt and model path. Refer to 'Get Started with Samples' for detailed instructions. ```sh stable_diffusion ./dreamlike_anime_1_0_ov/FP16 'cyberpunk cityscape like Tokyo New York with tall buildings at dusk golden hour cinematic lighting' ``` -------------------------------- ### Install OpenVINO GenAI Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/README.md Install the OpenVINO GenAI library using pip. This is the first step to using the library. ```sh pip install openvino-genai ``` -------------------------------- ### Install OpenVINO GenAI Artifacts Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/docs/BUILD.md Install the built artifacts to the specified installation directory. ```sh cmake --install ./build/ --config Release --prefix ``` -------------------------------- ### Install Hugging Face Hub Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/site/docs/guides/model-preparation/download-openvino-models.mdx Install the huggingface_hub package to enable model downloads from Hugging Face. ```bash pip install huggingface_hub ``` -------------------------------- ### Install WWB with Nightly Builds Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/tools/who_what_benchmark/README.md Install WWB along with nightly builds of OpenVINO, openvino-tokenizers, and openvino-genai. This is useful for testing the latest features and fixes. ```bash PIP_PRE=1 \ PIP_EXTRA_INDEX_URL=https://storage.openvinotoolkit.org/simple/wheels/nightly \ pip install . ``` -------------------------------- ### Install ModelScope and Optimum Intel Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/site/docs/guides/model-preparation/convert-to-openvino.mdx Install the `modelscope` and `optimum-intel` packages to facilitate downloading models from ModelScope and converting them to OpenVINO IR format. ```bash pip install modelscope --requirement ./samples/export-requirements.txt ``` -------------------------------- ### Basic Text Generation in C++ Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/README.md A minimal example demonstrating how to initialize an LLMPipeline and generate text using a simple prompt. ```cpp #include "openvino/genai/llm_pipeline.hpp" #include int main(int argc, char* argv[]) { std::string models_path = argv[1]; ov::genai::LLMPipeline pipe(models_path, "CPU"); std::cout << pipe.generate("The Sun is yellow because", ov::genai::max_new_tokens(256)); } ``` -------------------------------- ### Install OpenVINO GenAI and Dependencies Source: https://context7.com/openvinotoolkit/openvino.genai/llms.txt Installs the OpenVINO GenAI library and necessary tools for model conversion and downloading pre-converted models. ```bash pip install openvino-genai ``` ```bash pip install optimum[openvino] optimum-cli export openvino --model TinyLlama/TinyLlama-1.1B-Chat-v1.0 --weight-format int4 --trust-remote-code TinyLlama_1_1b_v1_ov ``` ```bash pip install huggingface-hub huggingface-cli download OpenVINO/TinyLlama-1.1B-Chat-v1.0-int4-ov --local-dir TinyLlama_1_1b_v1_ov ``` -------------------------------- ### Prepare Python Virtual Environment Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/tools/llm_bench/README.md Commands to create a virtual environment, install dependencies, and clone the repository. ```bash python3 -m venv ov-llm-bench-env source ov-llm-bench-env/bin/activate pip install --upgrade pip git clone https://github.com/openvinotoolkit/openvino.genai.git cd openvino.genai/tools/llm_bench pip install -r requirements.txt ``` ```bash pip install -U --upgrade-strategy eager -r requirements.txt ``` -------------------------------- ### Install timm and einops for InternVL2 Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/site/docs/supported-models/index.mdx Required packages for converting InternVL2 models. Ensure these are installed before proceeding with the conversion. ```bash pip install timm einops ``` -------------------------------- ### Install OpenVINO GenAI via npm Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/site/docs/getting-started/installation.mdx Use this command to install the Node.js bindings for OpenVINO GenAI. ```bash npm install openvino-genai-node ``` -------------------------------- ### Set up Python Virtual Environment Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/tools/who_what_benchmark/README.md Create and activate a Python virtual environment for installing WWB and its dependencies. This is a recommended step for managing project dependencies. ```bash python -m venv eval_env source eval_env/bin/activate ``` -------------------------------- ### Install WWB with Extra Requirements Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/tools/who_what_benchmark/README.md Install WWB with specific extra requirements, such as support for certain model configurations like 'minicpm-o-2_6'. Refer to setup.py for available extras. ```bash pip install .[minicpm-o-2_6] ``` -------------------------------- ### Install Dependencies and Export Model to OpenVINO IR Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/c/text_generation/README.md Install necessary dependencies using pip and then export a model to OpenVINO IR format using the optimum-cli. The --upgrade-strategy eager option ensures optimum-intel is updated. ```sh pip install --upgrade-strategy eager -r ../../export-requirements.txt optimum-cli export openvino --model ``` -------------------------------- ### Install macOS command line tools Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/docs/BUILD.md Install the necessary Clang compiler and command line tools via Xcode. ```sh xcode-select --install ``` -------------------------------- ### Example LoRA Text to Video Generation Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/video_generation/README.md Demonstrates running the LoRA text-to-video sample with the LTX-Video model, a prompt, and a specific LoRA adapter with an alpha value. ```bash ./lora_text2video ltx_video_ov/FP32 "In the style of Pixel, the video shifts to a majestic castle under a starry sky." ltx_pixel_pytorch_lora_weights.safetensors 3.0 ``` -------------------------------- ### Install Dependencies and Export Model Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/image_generation/README.md Installs necessary dependencies and exports a Stable Diffusion model to OpenVINO format using the optimum-cli. Ensure optimum-intel is up-to-date. ```sh pip install --upgrade-strategy eager -r ../../requirements.txt optimum-cli export openvino --model dreamlike-art/dreamlike-anime-1.0 --task stable-diffusion --weight-format fp16 dreamlike_anime_1_0_ov/FP16 ``` -------------------------------- ### Install Dependencies and Export Model Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/js/whisper_speech_recognition/README.md Install necessary Python packages and export the Whisper model to OpenVINO format using the optimum-cli. ```sh pip install --upgrade-strategy eager -r /samples/requirements.txt optimum-cli export openvino --trust-remote-code --model openai/whisper-base whisper-base ``` -------------------------------- ### Define Sample Executables Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/visual_language_chat/CMakeLists.txt Defines build targets for various VLM and chat samples, linking them against OpenVINO GenAI and setting installation properties. ```cmake add_executable(visual_language_chat visual_language_chat.cpp load_image.cpp) target_include_directories(visual_language_chat PRIVATE "${CMAKE_BINARY_DIR}") target_link_libraries(visual_language_chat PRIVATE openvino::genai) set_target_properties(visual_language_chat PROPERTIES # Ensure out of box LC_RPATH on macOS with SIP INSTALL_RPATH_USE_LINK_PATH ON) install(TARGETS visual_language_chat RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL) ``` ```cmake add_executable(visual_language_lora visual_language_lora.cpp load_image.cpp) target_include_directories(visual_language_lora PRIVATE "${CMAKE_BINARY_DIR}") target_link_libraries(visual_language_lora PRIVATE openvino::genai) set_target_properties(visual_language_lora PROPERTIES # Ensure out of box LC_RPATH on macOS with SIP INSTALL_RPATH_USE_LINK_PATH ON) install(TARGETS visual_language_lora RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL) ``` ```cmake add_executable(encrypted_model_vlm encrypted_model_vlm.cpp load_image.cpp) target_include_directories(encrypted_model_vlm PRIVATE "${CMAKE_BINARY_DIR}") target_link_libraries(encrypted_model_vlm PRIVATE openvino::genai) set_target_properties(encrypted_model_vlm PROPERTIES # Ensure out of box LC_RPATH on macOS with SIP INSTALL_RPATH_USE_LINK_PATH ON) install(TARGETS encrypted_model_vlm RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL) ``` ```cmake add_executable(benchmark_vlm benchmark_vlm.cpp load_image.cpp ../text_generation/read_prompt_from_file.cpp) target_include_directories(benchmark_vlm PRIVATE "${CMAKE_BINARY_DIR}") target_link_libraries(benchmark_vlm PRIVATE openvino::genai cxxopts::cxxopts) set_target_properties(benchmark_vlm PROPERTIES # Ensure out of box LC_RPATH on macOS with SIP INSTALL_RPATH_USE_LINK_PATH ON) install(TARGETS benchmark_vlm RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL) ``` ```cmake add_executable(video_to_text_chat video_to_text_chat.cpp) target_include_directories(video_to_text_chat PRIVATE "${CMAKE_BINARY_DIR}") ov_genai_link_opencv(video_to_text_chat core imgproc videoio imgcodecs) target_link_libraries(video_to_text_chat PRIVATE openvino::genai cxxopts::cxxopts) install(TARGETS video_to_text_chat RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL) ``` -------------------------------- ### Install Whisper Sample Executable Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/c/whisper_speech_recognition/CMakeLists.txt Installs the compiled 'whisper_speech_recognition_c' executable into the 'samples_bin/' directory within the runtime destination. It is marked as a component 'samples_bin' and excluded from all targets. ```cmake install(TARGETS whisper_speech_recognition_c RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL) ``` -------------------------------- ### Install Optimum Intel for Model Conversion Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/site/docs/guides/model-preparation/convert-to-openvino.mdx Install the `optimum-intel` package along with its requirements to enable model conversion and optimization. Some models may require additional dependencies listed in `export-requirements.txt`. ```bash pip install --requirement ./samples/export-requirements.txt ``` -------------------------------- ### Initialize and use TextRerankPipeline Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/js/rag/README.md Example of initializing the rerank pipeline and reranking documents based on a query. ```js import { TextRerankPipeline } from 'openvino-genai-node'; const pipeline = await TextRerankPipeline(modelPath, { device: "CPU" }); const rerankResult = await pipeline.rerank(query, documents); ``` -------------------------------- ### Run Structured Output Generation Sample Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/text_generation/README.md Execute this command to start the interactive dialog for structured output generation. You can then prompt the model to solve equations step by step. ```bash structured_output_generation ``` -------------------------------- ### Get Timestamps for Transcription Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/python/whisper_speech_recognition/README.md Enable timestamp prediction during transcription by setting `return_timestamps=True`. The result object will contain chunks with start and end timestamps. ```python raw_speech = read_wav("how_are_you_doing_today.wav") result = pipe.generate(raw_speech, return_timestamps=True) for chunk in result.chunks: print(f"timestamps: [{chunk.start_ts:.2f}, {chunk.end_ts:.2f}] text: {chunk.text}") # timestamps: [0.00, 2.00] text: How are you doing today? ``` -------------------------------- ### Build OpenVINO GenAI Samples for Windows (Command Prompt) Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/c/text_generation/README.md Set up the environment and build the samples for Windows using the Command Prompt. Ensure you have sourced the setupvars batch script. ```bat \setupvars.bat \samples\c\build_samples_msvc.bat ``` -------------------------------- ### Image2ImagePipeline Generation Example Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/site/docs/use-cases/image-generation/_sections/_run_model/_image2image_python.mdx Use this snippet to generate an image based on a text prompt and an input image using the Image2ImagePipeline. Ensure you have the necessary libraries (openvino_genai, openvino, PIL, numpy) installed and model_path and prompt variables defined. ```python import openvino_genai as ov_genai import openvino as ov from PIL import Image import numpy as np def read_image(path: str) -> ov.Tensor: pic = Image.open(path).convert("RGB") image_data = np.array(pic)[None] return ov.Tensor(image_data) input_image_data = read_image("input_image.jpg") pipe = ov_genai.Image2ImagePipeline(model_path, "${props.device || 'CPU'}") image_tensor = pipe.generate(prompt, image=input_image_data, strength=0.8) image = Image.fromarray(image_tensor.data[0]) image.save("image.bmp") ``` -------------------------------- ### Build OpenVINO GenAI C Samples Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/c/whisper_speech_recognition/README.md Commands to initialize the environment and build the C samples across different operating systems. ```sh source /setupvars.sh .//samples/c/build_samples.sh ``` ```cmd \setupvars.bat \samples\c\build_samples_msvc.bat ``` ```powershell .\setupvars.ps1 \samples\c\build_samples.ps1 ``` -------------------------------- ### Verify OpenVINO GenAI Installation Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/docs/BUILD.md Verify the installation of OpenVINO GenAI by importing the library and printing its version. This confirms that the installation was successful. ```python python -c "import openvino_genai; print(openvino_genai.__version__)" ``` -------------------------------- ### Run image-to-image sample Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/image_generation/README.md Download an initial image and execute the image2image sample to perform denoising based on a provided prompt. ```bash wget https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png ./image2image ./dreamlike_anime_1_0_ov/FP16 'cat wizard, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney, 8k' cat.png ``` -------------------------------- ### Define Sample Executable Build Function Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/c/text_generation/CMakeLists.txt A CMake function to compile C source files, link against the OpenVINO GenAI C library, and configure installation properties. ```cmake function(add_sample_executable target_name) add_executable(${target_name} ${target_name}.c) # Specifies that the source file should be compiled as a C source file set_source_files_properties(${target_name}.c PROPERTIES LANGUAGE C) target_link_libraries(${target_name} PRIVATE openvino::genai::c) set_target_properties(${target_name} PROPERTIES # Ensure out-of-box LC_RPATH on macOS with SIP INSTALL_RPATH_USE_LINK_PATH ON) install(TARGETS ${target_name} RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL) endfunction() ``` -------------------------------- ### Install VLM Pipeline Executable Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/c/visual_language_chat/CMakeLists.txt Installs the VLM pipeline executable to a specific runtime destination. This ensures the sample binary is available after installation. ```cmake install(TARGETS vlm_pipeline_c RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL) ``` -------------------------------- ### Build OpenVINO GenAI Samples for Windows (PowerShell) Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/c/text_generation/README.md Set up the environment and build the samples for Windows using PowerShell. Ensure you have sourced the setupvars PowerShell script. ```ps1 .\setupvars.ps1 .\samples\c\build_samples.ps1 ``` -------------------------------- ### Configure Sample Executables Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/image_generation/CMakeLists.txt Standard CMake configuration for building sample executables with OpenVINO GenAI and indicators dependencies. ```cmake add_executable(stable_diffusion_export_import stable_diffusion_export_import.cpp load_image.cpp imwrite.cpp) target_include_directories(stable_diffusion_export_import PRIVATE ${CMAKE_BINARY_DIR} "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(stable_diffusion_export_import PRIVATE openvino::genai indicators::indicators) set_target_properties(stable_diffusion_export_import PROPERTIES # Ensure out of box LC_RPATH on macOS with SIP INSTALL_RPATH_USE_LINK_PATH ON) install(TARGETS stable_diffusion_export_import RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL) ``` ```cmake add_executable(inpainting inpainting.cpp load_image.cpp imwrite.cpp) target_include_directories(inpainting PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_BINARY_DIR}") target_link_libraries(inpainting PRIVATE openvino::genai indicators::indicators) set_target_properties(inpainting PROPERTIES # Ensure out of box LC_RPATH on macOS with SIP INSTALL_RPATH_USE_LINK_PATH ON) install(TARGETS inpainting RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin EXCLUDE_FROM_ALL) ``` -------------------------------- ### Build OpenVINO GenAI Samples for Linux/macOS Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/c/text_generation/README.md Set up the environment and build the samples for Linux and macOS. Ensure you have sourced the setupvars script. ```sh source /setupvars.sh .//samples/c/build_samples.sh ``` -------------------------------- ### Install OpenVINO GenAI from Source Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/docs/BUILD.md Install the OpenVINO GenAI package directly from the source code after setting up the environment. This command installs the package into the current Python environment. ```sh python -m pip install . ``` -------------------------------- ### Run Chat Sample Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/js/text_generation/README.md Launches the interactive chat sample. Provide the path to your model directory as an argument. ```bash node chat_sample.js model_dir ``` -------------------------------- ### Install Export Requirements Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/rag/README.md Install the necessary dependencies for model conversion. ```sh pip install --upgrade-strategy eager -r ../../export-requirements.txt ``` -------------------------------- ### Set Up Environment using OpenVINO setupvars Script Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/js/BUILD.md Source the OpenVINO setupvars script to configure the environment. This is the recommended method for setting up environment variables. ```sh source /setupvars.sh ``` ```cmd call \setupvars.bat ``` ```powershell . /setupvars.ps1 ``` -------------------------------- ### Initialize and Use WhisperPipeline Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/site/docs/use-cases/speech-recognition/_sections/_run_model/_code_example_js.mdx Demonstrates initializing the WhisperPipeline with a model path and device, then generating text from raw audio data. Ensure 'sample.wav' exists and the modelPath is correctly set. ```javascript import { WhisperPipeline } from 'openvino-genai-node'; import { readAudio } from './wav_utils.js'; const rawSpeech = readAudio('sample.wav'); const pipeline = await WhisperPipeline(modelPath, "${props.device || 'CPU'}"); const generationConfig = { max_new_tokens: 100 }; const result = await pipeline.generate(rawSpeech, { generationConfig }); console.log(result.texts[0]); ``` -------------------------------- ### Install test requirements Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/tests/python_tests/README.md Install the necessary dependencies for running the Python tests. ```sh pip install -r tests/python_tests/requirements.txt ``` -------------------------------- ### Run Chat Sample Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/text_generation/README.md Launches the interactive chat sample. Replace with the path to your model. ```bash ./chat_sample ``` -------------------------------- ### Install ModelScope Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/site/docs/guides/model-preparation/download-openvino-models.mdx Install the modelscope package to enable model downloads from ModelScope. ```bash pip install modelscope ``` -------------------------------- ### Run LLM Benchmarking Sample Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/text_generation/README.md Execute the benchmark tool with various options for model path, prompts, and performance metrics. ```bash ./benchmark_genai [OPTIONS] ``` -------------------------------- ### Install OpenVINO versions Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/tools/llm_bench/README.md Install specific or nightly versions of OpenVINO using pip. ```bash # e.g. pip install openvino==2024.4.0 # Optional, install the openvino nightly package if needed. # OpenVINO nightly is pre-release software and has not undergone full release validation or qualification. pip uninstall openvino pip install --upgrade --pre openvino openvino-tokenizers --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly ``` -------------------------------- ### Install macOS dependencies Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/docs/BUILD.md Install required build tools on macOS using Homebrew. ```sh brew install coreutils scons ``` -------------------------------- ### Install OpenCV Dependency Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/python/video_generation/README.md Install the specific version of OpenCV required for running the provided samples. ```sh pip install opencv-python==4.12.0.88 ``` -------------------------------- ### Build Samples from Archive Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/docs/BUILD.md Configure the environment and build samples after extracting the archive. ```sh source /setupvars.sh /samples/cpp/build_samples.sh ``` ```cmd \setupvars.bat \samples\cpp\build_samples_msvc.bat ``` ```powershell .\setupvars.ps1 \samples\cpp\build_samples.ps1 ``` -------------------------------- ### Install export requirements Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/js/speech_generation/README.md Install the necessary dependencies for exporting models using the Optimum CLI. ```sh pip install --upgrade-strategy eager -r /samples/export-requirements.txt ``` -------------------------------- ### Structured Output Example Output Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/js/text_generation/README.md Example of the output format generated by the structured output sample after processing a prompt. ```text > Generate a JSON for 2 cars and 1 person with an Irish surname output: {"name": "John Doe", "surname": "O'Reilly", "age": 30, "city": "Dublin"} {"model": "Toyota", "year": 2020, "engine": "hybrid"} {"model": "Ford", "year": 2019, "color": "red"} ``` -------------------------------- ### Apply and Switch LoRA Adapters Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/site/docs/guides/lora-adapters.mdx Demonstrates initializing an LLM pipeline with multiple LoRA adapters and switching configurations dynamically during generation. ```python import openvino_genai as ov_genai # Initialize pipeline with adapters adapter_config = ov_genai.AdapterConfig() # Add multiple adapters with different weights adapter1 = ov_genai.Adapter("path/to/lora1.safetensors") adapter2 = ov_genai.Adapter("path/to/lora2.safetensors") adapter_config.add(adapter1, alpha=0.5) adapter_config.add(adapter2, alpha=0.5) pipe = ov_genai.LLMPipeline( model_path, "CPU", adapters=adapter_config ) # Generate with current adapters output1 = pipe.generate("Generate story about", max_new_tokens=100) # Switch to different adapter configuration new_config = ov_genai.AdapterConfig() new_config.add(adapter1, alpha=1.0) output2 = pipe.generate( "Generate story about", max_new_tokens=100, adapters=new_config ) ``` ```cpp #include "openvino/genai/llm_pipeline.hpp" int main() { ov::genai::AdapterConfig adapter_config; // Add multiple adapters with different weights ov::genai::Adapter adapter1("path/to/lora1.safetensors"); ov::genai::Adapter adapter2("path/to/lora2.safetensors"); adapter_config.add(adapter1, 0.5f); adapter_config.add(adapter2, 0.5f); ov::genai::LLMPipeline pipe( model_path, "CPU", ov::genai::adapters(adapter_config) ); // Generate with current adapters auto output1 = pipe.generate("Generate story about", ov::genai::max_new_tokens(100)); // Switch to different adapter configuration ov::genai::AdapterConfig new_config; new_config.add(adapter1, 1.0f); auto output2 = pipe.generate( "Generate story about", ov::genai::adapters(new_config), ov::genai::max_new_tokens(100) ); } ``` -------------------------------- ### Display benchmark help Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/tools/llm_bench/README.md Access the help menu for the benchmarking script. ```bash python ./benchmark.py -h # for more information ``` -------------------------------- ### Windows Unicode Encoding Error Example Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/python/video_generation/README.md Example of the UnicodeEncodeError that may occur when printing output to the Windows console. ```text UnicodeEncodeError: 'charmap' codec can't encode character '\u25aa' in position 0: character maps to ``` -------------------------------- ### Set RPATH and Install Targets Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/python/CMakeLists.txt Configures platform-specific RPATHs and defines installation rules for the Python module and distribution files. ```cmake # setting RPATH / LC_RPATH depending on platform if(LINUX) # to find libopenvino_genai.so in the same folder set(py_rpaths "$ORIGIN") elseif(APPLE) # to find libopenvino_genai.dylib in the same folder set(py_rpaths "@loader_path") if(DEFINED PY_BUILD_CMAKE_PACKAGE_NAME) # in case we build pip package, we need to refer to libopenvino.dylib from 'openvino' package list(APPEND py_rpaths "@loader_path/../openvino/libs") endif() endif() if(py_rpaths) set_target_properties(${TARGET_NAME} PROPERTIES INSTALL_RPATH "${py_rpaths}") endif() install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/openvino_genai/__init__.py" "${CMAKE_CURRENT_SOURCE_DIR}/openvino_genai/__init__.pyi" "${CMAKE_CURRENT_SOURCE_DIR}/openvino_genai/py_openvino_genai.pyi" DESTINATION python/openvino_genai COMPONENT pygenai_${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}) install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION python/openvino_genai COMPONENT pygenai_${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}) install(FILES "${OpenVINOGenAI_SOURCE_DIR}/LICENSE" "${OpenVINOGenAI_SOURCE_DIR}/third-party-programs.txt" "${OpenVINOGenAI_SOURCE_DIR}/SECURITY.md" DESTINATION "${PY_BUILD_CMAKE_PACKAGE_NAME}-${PY_BUILD_CMAKE_PACKAGE_VERSION}.dist-info" COMPONENT wheel_genai EXCLUDE_FROM_ALL) # wheel_genai component is used for wheel generation in pyproject.toml. # Exclude wheel_genai from normal packaging because there's pygenai_X_Y component for that. install(TARGETS openvino_genai ${TARGET_NAME} LIBRARY DESTINATION openvino_genai COMPONENT wheel_genai EXCLUDE_FROM_ALL RUNTIME DESTINATION openvino_genai COMPONENT wheel_genai EXCLUDE_FROM_ALL) ``` -------------------------------- ### Register and Build Sample List Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/c/text_generation/CMakeLists.txt Defines a list of sample targets and iterates through them to invoke the build function. ```cmake set (SAMPLE_LIST greedy_causal_lm_c chat_sample_c benchmark_genai_c) foreach(sample IN LISTS SAMPLE_LIST) add_sample_executable(${sample}) endforeach() ``` -------------------------------- ### Initialize Pipeline and Generate Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/site/docs/concepts/optimization-techniques/visual-token-pruning.md Create a VLMPipeline instance and execute generation with the provided configuration. ```python pipe = ov_genai.VLMPipeline(models_path, device, scheduler_config=scheduler_config) res = pipe.generate(prompt, images=images, generation_config=config) ``` -------------------------------- ### Run TaylorSeer Text-to-Video Sample Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/python/video_generation/README.md Execute the TaylorSeer sample script to compare baseline performance against optimized caching. Requires a model directory and a prompt string. ```bash python taylorseer_text2video.py model_dir prompt ``` ```bash python taylorseer_text2video.py ./ltx_video_ov/INT8 "a robot dancing in the rain" ``` -------------------------------- ### Run Basic Text to Video Generation Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/python/video_generation/README.md Executes the text2video.py sample to generate a video from a text prompt using a pre-exported OpenVINO model. Specify the model directory and the text prompt as arguments. ```bash python text2video.py ./ltx_video_ov/FP32 "A woman with long brown hair and light skin smiles at another woman with long blonde hair" ``` -------------------------------- ### Install Python Dependencies for JavaScript Tests Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/js/BUILD.md Install the required Python packages for running JavaScript tests. This includes 'openvino-genai' and 'optimum-intel' for model conversion. ```sh python -m pip install openvino-genai optimum-intel ``` -------------------------------- ### Install Dependencies and Export Model Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/whisper_speech_recognition/README.md Installs necessary dependencies and exports the Whisper model using the optimum-cli. Ensure optimum-intel is upgraded to the latest version. ```sh pip install --upgrade-strategy eager -r ../../requirements.txt optimum-cli export openvino --trust-remote-code --model openai/whisper-base whisper-base ``` -------------------------------- ### Benchmark GenAI CMake Setup Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/rag/CMakeLists.txt Includes CMake's FetchContent module and sets a policy for compatibility. This is typically used for managing external dependencies or modules required for benchmarking. ```cmake include(FetchContent) if(POLICY CMP0135) cmake_policy(SET CMP0135 NEW) endif() ``` -------------------------------- ### Verify Node.js Bindings Installation Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/js/BUILD.md Verify the installation of the OpenVINO GenAI Node.js bindings by checking if the LLMPipeline class can be imported. This confirms the package is accessible in your Node.js environment. ```javascript node -e "const { LLMPipeline } = require('openvino-genai-node'); console.log(LLMPipeline);" ``` -------------------------------- ### Find OpenVINO GenAI Package Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/c/whisper_speech_recognition/CMakeLists.txt Locates the OpenVINO GenAI package. It searches in the build directory and the OpenVINO installation directory. Ensure OpenVINO is installed or built in one of these locations. ```cmake find_package(OpenVINOGenAI REQUIRED PATHS "${CMAKE_BINARY_DIR}" # Reuse the package from the build. ${OpenVINO_DIR} # GenAI may be installed alogside OpenVINO. NO_CMAKE_FIND_ROOT_PATH ) ``` -------------------------------- ### Run LLM ReAct Agent Sample Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/js/text_generation/README.md Launches the LLM ReAct Agent sample for real-time reasoning and action based on user input. Provide the path to your model directory. ```bash node react_sample.js model_dir ``` -------------------------------- ### Run LLM Benchmarking Sample Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/c/text_generation/README.md Benchmark Large Language Models in OpenVINO GenAI using C. This sample allows customization of the model, prompt, device, and iteration counts. ```sh ./benchmark_genai_c [-m MODEL] [-p PROMPT] [-nw NUM_WARMUP] [-n NUM_ITER] [-mt MAX_NEW_TOKENS] [-d DEVICE] ``` -------------------------------- ### Structured Output - Stage One Example Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/python/text_generation/README.md Example of a model generating a JSON schema to indicate the number of items of each type requested in a prompt. This is an internal step not shown to the user. ```json {"person": 1, "car": 2, "transaction": 0} ``` -------------------------------- ### Run text-to-speech sample Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/js/speech_generation/README.md Execute the text-to-speech sample with various configuration options. ```bash node speech_generation/text2speech.js speecht5_tts "Hello OpenVINO GenAI" ``` ```bash node speech_generation/text2speech.js speecht5_tts "Hello OpenVINO GenAI" --speaker_embedding speaker_embedding.bin ``` ```bash node speech_generation/text2speech.js speecht5_tts "Hello OpenVINO GenAI" GPU ``` ```bash node speech_generation/text2speech.js speecht5_tts "Hello OpenVINO GenAI" --output my_audio.wav ``` -------------------------------- ### Run LoRA text-to-image sample Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/image_generation/README.md Execute the lora_text2image sample with a specified model path, prompt, adapter file, and alpha scaling factor. ```bash ./lora_text2image dreamlike_anime_1_0_ov/FP16 'curly-haired unicorn in the forest, anime, line' soulcard.safetensors 0.7 ``` -------------------------------- ### Install Dependencies and Export Model Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/visual_language_chat/README.md Installs necessary Python packages and exports a Hugging Face model to OpenVINO format using the optimum-cli. Ensure optimum-intel is upgraded to the latest version. ```sh pip install --upgrade-strategy eager -r ../../requirements.txt optimum-cli export openvino --model openbmb/MiniCPM-V-2_6 --trust-remote-code MiniCPM-V-2_6 ``` -------------------------------- ### Example Structured JSON Output Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/src/README.md This is an example of a JSON object that conforms to the `Person` schema defined in the Python code. Note that while the JSON format is guaranteed, the factual correctness or sensibility of the content is not. ```json { "name": "John", "surname": "Doe", "age": 30, "city": "Dublin" } ``` -------------------------------- ### Basic Text to Video Generation Command Source: https://github.com/openvinotoolkit/openvino.genai/blob/master/samples/cpp/video_generation/README.md Executes the text-to-video sample to generate a video from a text prompt. Requires the model directory and the prompt as arguments. ```bash ./text2video model_dir prompt ```