### Install Olive and dependencies Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/iGPU/getting_started/README.md Installs the required Python packages for the iGPU example from the requirements.txt file. Navigate to the getting_started directory first. ```bash cd \CNN-examples\iGPU\getting_started python -m pip install -r requirements.txt ``` -------------------------------- ### Clone RyzenAI-SW repository and enter tutorial directory Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/getstartex.rst Clone the RyzenAI-SW repository and navigate to the tutorial/getting_started_resnet directory to access the source files for this getting started tutorial. ```bash git clone https://github.com/amd/RyzenAI-SW.git cd tutorial/getting_started_resnet ``` -------------------------------- ### Quick Start: Setup, Download, and Run WinML Segmentation Source: https://github.com/amd/ryzenai-sw/blob/main/WinML/CNN/ImageSegmentation/README.md Quick start commands for setting up the environment, downloading the DeepLabV3 model, and running inference on the NPU. The model download is about 167 MB and the inference command uses the --ep_policy NPU flag. ```sh # 1. Setup environment (one-time) conda create -n winml_seg --clone winml_env conda activate winml_seg cd \WinML\CNN\ImageSegmentation\python pip install --upgrade -r requirements.txt # 2. Download model (one-time, ~167 MB) cd ..\model python download_model.py # 3. Run inference cd ..\python python run_model.py --model ..\model\deeplabv3_resnet50.onnx --ep_policy NPU ``` -------------------------------- ### Quick Start: Setup, Download Model, and Run Inference Source: https://github.com/amd/ryzenai-sw/blob/main/WinML/CNN/ObjectDetection/README.md Quick start commands for setting up the environment, downloading the YOLOv8m model, and running inference with the NPU execution policy. Requires Python 3.12 and a pre-existing conda environment named winml_env. Use --ep_policy CPU for testing. ```sh # 1. Setup environment (one-time) - Python 3.12 REQUIRED conda create -n winml_objdet --clone winml_env conda activate winml_objdet cd \WinML\CNN\ObjectDetection\python pip install --upgrade -r requirements.txt # 2. Download model (one-time) cd ..\model python download_yolov8.py # Default: YOLOv8m # 3. Run inference cd ..\python python run_model.py --model ..\model\yolov8m.onnx --image ..\images\object_detection_input.jpg --ep_policy NPU # or CPU for testing ``` -------------------------------- ### Install dependencies for quantize_quark.py Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/quark_docs_repo_supported_accelerators_ryzenai_tutorial_uint4_oga.rst Navigate to the Quark example directory and install the additional dependencies required by the quantize_quark.py script. ```bash cd examples/torch/language_modeling/llm_ptq/ pip install -r requirements.txt ``` -------------------------------- ### Install additional packages for ResNet BF16 example Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/getting_started_resnet/bf16/README.md Creates a conda environment cloned from the Ryzen AI installation, activates it, sets the RYZEN_AI_INSTALLATION_PATH environment variable, and installs the required Python packages from requirements.txt. ```bash conda create --name resnet_bf16 --clone ryzen-ai- conda activate resnet_bf16 set RYZEN_AI_INSTALLATION_PATH = cd \CNN-examples\getting_started_resnet\bf16 python -m pip install -r requirements.txt ``` -------------------------------- ### Setup conda environment and install requirements Source: https://github.com/amd/ryzenai-sw/blob/main/Transformer-examples/DistilBERT_text_classification_bf16/README.md Creates and activates a conda environment cloned from the RyzenAI installer environment, then installs the required Python packages for this example. ```bash conda create --name bert --clone ryzen-ai- conda activate bert cd \Transformer-examples\DistilBERT_text_classification_bf16 python -m pip install -r requirements.txt ``` -------------------------------- ### Install additional dependencies with Olive setup Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/iGPU/getting_started/README.md Sets up additional dependencies for the example using Olive with the resnet50_config.json configuration. ```bash python -m olive.workflows.run --config resnet50_config.json --setup ``` -------------------------------- ### Run API server on NPU Source: https://github.com/amd/ryzenai-sw/blob/main/Demos/ASR/Parakeet-TDT/README.md Installs requirements and starts the API server on NPU. ```bash pip install -r requirements.txt python server.py --device npu ``` -------------------------------- ### Setup conda environment for image classification Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/image_classification/README.md Sets up the conda environment for the image classification example. Requires the RyzenAI installer's conda environment and the path to the example directory. ```bash cd \CNN-examples\image_classification conda create --name image_classification --clone ryzen-ai- conda activate image_classification python -m pip install -r requirements.txt ``` -------------------------------- ### Import AMD Quark ONNX quantization classes for fast_finetune example Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/quark_docs_repo_onnx_tutorial_bfp16_quantization.rst Imports the necessary classes for configuring BFP16 quantization in AMD Quark for ONNX. This is the starting point for the example that enables fast_finetune to improve accuracy. ```python from quark.onnx import ModelQuantizer, ExtendedQuantFormat, ExtendedQuantType from onnxruntime.quantization.calibrate import CalibrationMethod from quark.onnx.quantization.config.config import Config, QuantizationConfig ``` -------------------------------- ### Install tutorial dependencies Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/quark_quantization/README.md Installs the required Python packages for the tutorial from the requirements.txt file in the quark_quantization directory. ```bash cd ryzenai-sw\tutorial\quark_quantization pip install -r requirements.txt ``` -------------------------------- ### Run Ryzen AI installer with defaults Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/ryzen_ai_docs_repo_rai_linux.rst Runs the installer with default settings, prompting to read and agree to the EULA. ```bash cd ryzen_ai-1.4.0 ./install_ryzen_ai_1_4.sh ``` -------------------------------- ### Execute example with model path Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/oga_api/README.md Runs the compiled example executable, passing the path to the model directory. ```bash .\example.exe -m "" ``` -------------------------------- ### Clone RyzenAI-SW and install RAG-OGA dependencies Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/README.md Clones the RyzenAI-SW repository, navigates to the RAG-OGA example directory, and installs the required Python dependencies. ```sh git clone https://github.com/amd/RyzenAI-SW.git cd RyzenAI-SW/LLM-examples/RAG-OGA pip install -r requirements.txt ``` -------------------------------- ### Install required packages with pip Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/getstartex.rst Install the additional packages required by this example using the conda environment created during Ryzen AI Software installation. ```bash python -m pip install -r requirements.txt ``` -------------------------------- ### run_all_benchmarks.py examples Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/VLM/README.md Example invocations of run_all_benchmarks.py covering default all-size runs, custom image/output directory, specific sizes, verbose mode, and compact output. ```bash # Run all sizes (448x448 to 4032x4032) python run_all_benchmarks.py -m ./phi-4-mm-onnx # Custom image and output directory python run_all_benchmarks.py -m ./model -i my_image.jpg -o ./my_results # Run specific sizes only python run_all_benchmarks.py -m ./model --sizes 1024x1024 2048x2048 # Verbose mode (shows generated text) python run_all_benchmarks.py -m ./model -v --sizes 1024x1024 # Compact output (simplified table) python run_all_benchmarks.py -m ./model --compact ``` -------------------------------- ### Create and activate igpu-example conda environment Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/iGPU/getting_started/README.md Creates a clone of the Ryzen AI conda environment and activates it for the iGPU example. Replace with the installed Ryzen AI version. ```python set RYZEN_AI_CONDA_ENV_NAME=ryzen-ai- conda create --name igpu-example --clone %RYZEN_AI_CONDA_ENV_NAME% conda activate igpu-example ``` -------------------------------- ### Quick Start Commands for Face Detection Source: https://github.com/amd/ryzenai-sw/blob/main/WinML/CNN/FaceDetection/README.md Quick start commands for setting up the environment, downloading and optimizing the model, and running inference. Use `--backbone mobilenet` for a lightweight model and `--ep_policy CPU` for testing on CPU. ```sh # 1. Setup environment (one-time) conda create -n winml_face --clone winml_env conda activate winml_face cd \WinML\CNN\FaceDetection\python pip install --upgrade -r requirements.txt # 2. Download and optimize model (one-time) cd ..\model python download_and_export.py # Default: ResNet34 # OR for lightweight MobileNet model: # python download_and_export.py --backbone mobilenet # 3. Run inference cd ..\python python run_model.py --model ..\model\retinaface_resnet.onnx --image ..\images\face_detection_input.jpg --ep_policy NPU # or CPU for testing ``` -------------------------------- ### CMakeLists.txt for resnet50 example Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/iGPU/getting_started/cpp/resnet50/CMakeLists.txt CMake configuration for building the resnet50 example. Requires Python 3.10, OpenCV (core, highgui, imgproc), and the Ryzen AI installation path set via the RYZEN_AI_INSTALLATION_PATH environment variable. Links against onnxruntime and copies DirectML.dll and onnxruntime.dll to the build output directory after building. ```cmake cmake_minimum_required(VERSION 3.5) project(resnet50 VERSION 1.0.0 LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 17) find_package(Python 3.10 EXACT COMPONENTS Interpreter Development) set (RYZEN_AI_INSTALLATION_PATH $ENV{RYZEN_AI_INSTALLATION_PATH}) set(ONNXRUNTIME_ROOTDIR "${RYZEN_AI_INSTALLATION_PATH}/onnxruntime") include_directories("${ONNXRUNTIME_ROOTDIR}/include/onnxruntime/core/session") link_directories("${ONNXRUNTIME_ROOTDIR}/lib") link_directories("${CMAKE_INSTALL_PREFIX}/lib") find_package(OpenCV COMPONENTS core highgui imgproc REQUIRED) add_executable(resnet50 resnet50.cpp util/getopt.c) target_include_directories(resnet50 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/util ) target_link_libraries(resnet50 ${ORT_LIBRARY} ${OpenCV_LIBS} onnxruntime) install(TARGETS resnet50 RUNTIME DESTINATION bin) add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${RYZEN_AI_INSTALLATION_PATH}/onnxruntime/bin/DirectML.dll ${CMAKE_CURRENT_BINARY_DIR}/$/DirectML.dll) add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${RYZEN_AI_INSTALLATION_PATH}/onnxruntime/bin/onnxruntime.dll ${CMAKE_CURRENT_BINARY_DIR}/$/onnxruntime.dll) ``` -------------------------------- ### Run hello_world.py Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/hello_world/README.md Runs the hello_world.py script to execute the example. ```bash python hello_world.py ``` -------------------------------- ### Create and set up conda environment for Ryzen AI LLM Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/ryzen_ai_docs_repo_llm_high_level_python.rst Run these commands in a terminal to create a conda environment named 'ryzenai-llm' with Python 3.10, activate it, install the lemonade-sdk with the 'llm-oga-hybrid' extra, and run 'lemonade-install --ryzenai hybrid' to complete the setup. ```bash conda create -n ryzenai-llm python=3.10 conda activate ryzenai-llm pip install lemonade-sdk[llm-oga-hybrid] lemonade-install --ryzenai hybrid ``` -------------------------------- ### Expected quicktest output Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/ryzen_ai_docs_repo_inst.rst Example output from a successful quicktest.py run, indicating the model is running on the NPU and the installation was successful. ```text [Vitis AI EP] No. of Operators : CPU 2 NPU 398 [Vitis AI EP] No. of Subgraphs : NPU 1 Actually running on NPU 1 ... Test Passed ... ``` -------------------------------- ### Clone the RyzenAI-SW repository Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/Nemotron-OCR-V2/README.md Clones the RyzenAI-SW repository and changes into the Nemotron-OCR-V2 example directory. Requires Git LFS to be installed. ```bash git lfs install git clone https://github.com/amd/RyzenAI-SW.git cd RyzenAI-SW\CNN-examples\Nemotron-OCR-V2 ``` -------------------------------- ### Install required Python packages Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/object_detection/yolov8m/README.md Installs the required Python packages for the tutorial, including amd-quark and the dependencies listed in requirements.txt. Run from the object_detection directory. ```bash cd \CNN-examples\object_detection pip install amd-quark pip install -r requirements.txt ``` -------------------------------- ### Set up conda environment and install dependencies Source: https://github.com/amd/ryzenai-sw/blob/main/WinML/CNN/ResNet/README.md Creates a new conda environment by cloning winml_env, activates it, changes to the ResNet Python directory, and installs the required packages from requirements.txt. ```sh conda create -n winml_resnet --clone winml_env conda activate winml_resnet cd \WinML\CNN\ResNet\python pip install --upgrade -r requirements.txt ``` -------------------------------- ### Run quicktest.py Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/ryzen_ai_docs_repo_inst.rst Runs the quicktest.py script from the Ryzen AI installation folder to verify the installation. The script sets up the environment and runs a simple CNN model on the NPU. ```bash cd %RYZEN_AI_INSTALLATION_PATH%/quicktest python quicktest.py ``` -------------------------------- ### Sample command for Llama-3.1-8B-Instruct hybrid Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/oga_api/README.md Example command using a sample path to the hybrid model. ```bash .\example.exe -m "path\to\Llama-3.1-8B-Instruct_hybrid" ``` -------------------------------- ### vlm_benchmark.py examples Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/VLM/README.md Example invocations of vlm_benchmark.py: a quick single-size test and a full benchmark with JSON export and verbose output. ```bash # Quick test python vlm_benchmark.py -m ./model -i image.jpg --image_size 1024 1024 # Full benchmark with JSON export python vlm_benchmark.py -m ./model -i image.jpg --image_size 1024 1024 \ -n 5 -w 2 --max_tokens 100 -o results.json -v ``` -------------------------------- ### Install Transformers Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/quark_docs_repo_pytorch_basic_usage_pytorch.rst Install the Transformers library from Hugging Face to load the model. ```bash pip install transformers ``` -------------------------------- ### Navigate to OGA_API folder Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/oga_api/README.md Changes directory to the OGA_API example folder. ```bash cd path\to\RyzenAI-SW\LLM-examples\oga_api ``` -------------------------------- ### Navigate to Whisper-AI directory Source: https://github.com/amd/ryzenai-sw/blob/main/Transformer-examples/ASR/Whisper-AI/README.md Navigates to the Whisper-AI example directory. Replace with the path to your RyzenAI-SW repository. ```bash cd \Transformer-examples\ASR\Whisper-AI ``` -------------------------------- ### Copy required files for hybrid LLM run Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/ryzen_ai_docs_repo_hybrid_oga.rst Creates a local folder and copies the necessary DLLs and example files from the Ryzen AI installation path to run LLMs in hybrid mode. ```bash mkdir hybrid_run cd hybrid_run xcopy /Y /E "%RYZEN_AI_INSTALLATION_PATH%\hybrid-llm\onnxruntime_genai\benchmark" . xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\hybrid-llm\examples\amd_genai_prompt.txt" . xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\deployment\hybrid-llm\onnxruntime-genai.dll" . xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\deployment\hybrid-llm\onnx_custom_ops.dll" . xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\deployment\hybrid-llm\ryzen_mm.dll" . xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\deployment\hybrid-llm\ryzenai_onnx_utils.dll" . xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\deployment\voe\DirectML.dll" . xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\deployment\voe\onnxruntime.dll" . ``` -------------------------------- ### Sample output from running the LLM example Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/oga_api/README.md Shows the expected console output when running the example with the Llama-3.1-8B-Instruct model, including initialization messages and a generated response to a prompt about OOP. ```text Initializing ORT GenAI... Loading Model from: path\to\Meta-Llama-3.1-8B-Instruct_hybrid Model loaded. Creating Tokenizer... Tokenizer created. Creating Generator... Generator created. -------------------------------- Enter prompt: Explain the basics of object oriented programming Generating response: Object-Oriented Programming (OOP) is a programming paradigm that revolves around the concept of objects and their interactions. Here are the basics: **Key Concepts:** 1. **Objects**: An object is a self-contained entity that has its own properties and behavior. It's a "thing" in your program that can interact with other objects. 2. **Classes**: A class is a blueprint or a template that defines the structure and behavior of an object. It's a set of instructions that defines the characteristics and actions of an object. 3. **Inheritance**: Inheritance is the mechanism by which one class can inherit the properties and behavior of another class. This allows for code reuse and facilitates the creation of a hierarchy of classes. 4. **Polymorphism**: Polymorphism is the ability of an object to take on multiple forms. This can be achieved through method overriding or method overloading. 5. **Encapsulation**: Encapsulation is the concept of bundling data and its associated methods that operate on that data within a single unit (i.e., an object). 6. **Abstraction**: Abstraction is the process of hiding implementation details and showing only the necessary information to the outside world. **OOP Principles:** 1. **Single Responsibility Principle (SRP)**: Each object should have a single responsibility and should not be responsible for multiple, unrelated tasks. 2. **Open/Closed Principle (OCP)**: Objects should be open for extension but closed for modification. 3. **Liskov Substitution Principle (LSP)**: Derived classes should be substitutable for their base classes. 4. **Interface Segregation Principle (ISP)**: A client should not be forced to depend on interfaces it does not use. 5. **Dependency Inversion Principle (DIP)**: High-level modules should not depend on low-level modules, but both should depend on abstractions. **OOP Concepts in Action:** 1. **Objects**: Create an object that represents a car. The car object has properties (color, make, model) and behavior (startEngine, accelerate). 2. **Classes**: Define a Car class that serves as a blueprint for creating car objects. 3. **Inheritance**: Create a ElectricCar class that inherits from the Car class and adds electric-specific properties and behavior. 4. **Polymorphism**: Create a method that takes an object as an argument and performs different actions based on the object's type. 5. **Encapsulation**: Create a BankAccount object that encapsulates the account balance and associated methods (deposit, withdraw). **Benefits of OOP:** 1. **Modularity**: OOP promotes modularity, making it easier to maintain and extend code. 2. **Code Reuse**: OOP enables code reuse through inheritance and polymorphism. 3. **Easier Maintenance**: OOP makes it easier to modify and extend code without affecting existing functionality. 4. **Improved Readability**: OOP promotes clear and concise code that's easier to understand. I hope this helps! Do you have any specific questions or topics you'd like me to expand on?? ``` -------------------------------- ### Install Foundry Local with winget Source: https://github.com/amd/ryzenai-sw/blob/main/WinML/LLM/README.md Installs Foundry Local from the Microsoft Store using the winget package manager. Requires Windows and an active internet connection. ```bash winget install Microsoft.FoundryLocal ``` -------------------------------- ### Build and install OpenCV 4.6.0 from source Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/iGPU/getting_started/README.md Builds OpenCV 4.6.0 from source with static libraries and installs it to C:\opencv. Modify CMAKE_PREFIX_PATH to change the installation location. Build files are written to build\. ```bash git clone https://github.com/opencv/opencv.git -b 4.6.0 cd opencv cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_CONFIGURATION_TYPES=Release -A x64 -T host=x64 -G "Visual Studio 17 2022" "-DCMAKE_INSTALL_PREFIX=C:\opencv" "-DCMAKE_PREFIX_PATH=C:\opencv" -DCMAKE_BUILD_TYPE=Release -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DBUILD_WITH_STATIC_CRT=OFF -B build cmake --build build --config Release cmake --install build --config Release ``` -------------------------------- ### Set up conda environment for WinML ConvNeXt Source: https://github.com/amd/ryzenai-sw/blob/main/WinML/CNN/ConvNeXt/README.md Creates a new conda environment named winml_convnext by cloning the existing winml_env environment, activates it, and installs the required packages from requirements.txt. Run these commands after completing the Python Setup in the main README. ```sh conda create -n winml_convnext --clone winml_env conda activate winml_convnext pip install --upgrade -r requirements.txt ``` -------------------------------- ### Output of pip install -r requirements.txt Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/hello_world/hello_world.ipynb Shows the output of the pip install command, indicating that all required packages are already installed. ```text Requirement already satisfied: torch in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from -r requirements.txt (line 1)) (2.4.0) Requirement already satisfied: ipykernel in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from -r requirements.txt (line 2)) (6.29.5) Requirement already satisfied: filelock in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from torch->-r requirements.txt (line 1)) (3.15.4) Requirement already satisfied: typing-extensions>=4.8.0 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from torch->-r requirements.txt (line 1)) (4.12.2) Requirement already satisfied: sympy in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from torch->-r requirements.txt (line 1)) (1.13.2) Requirement already satisfied: networkx in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from torch->-r requirements.txt (line 1)) (3.3) Requirement already satisfied: jinja2 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from torch->-r requirements.txt (line 1)) (3.1.4) Requirement already satisfied: fsspec in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from torch->-r requirements.txt (line 1)) (2024.6.1) Requirement already satisfied: comm>=0.1.1 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipykernel->-r requirements.txt (line 2)) (0.2.2) Requirement already satisfied: debugpy>=1.6.5 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipykernel->-r requirements.txt (line 2)) (1.8.5) Requirement already satisfied: ipython>=7.23.1 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipykernel->-r requirements.txt (line 2)) (8.26.0) Requirement already satisfied: jupyter-client>=6.1.12 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipykernel->-r requirements.txt (line 2)) (8.6.2) Requirement already satisfied: jupyter-core!=5.0.*,>=4.12 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipykernel->-r requirements.txt (line 2)) (5.7.2) Requirement already satisfied: matplotlib-inline>=0.1 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipykernel->-r requirements.txt (line 2)) (0.1.7) Requirement already satisfied: nest-asyncio in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipykernel->-r requirements.txt (line 2)) (1.6.0) Requirement already satisfied: packaging in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipykernel->-r requirements.txt (line 2)) (24.1) Requirement already satisfied: psutil in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipykernel->-r requirements.txt (line 2)) (6.0.0) Requirement already satisfied: pyzmq>=24 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipykernel->-r requirements.txt (line 2)) (26.1.0) Requirement already satisfied: tornado>=6.1 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipykernel->-r requirements.txt (line 2)) (6.4.1) Requirement already satisfied: traitlets>=5.4.0 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipykernel->-r requirements.txt (line 2)) (5.14.3) Requirement already satisfied: decorator in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipython>=7.23.1->ipykernel->-r requirements.txt (line 2)) (5.1.1) Requirement already satisfied: jedi>=0.16 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipython>=7.23.1->ipykernel->-r requirements.txt (line 2)) (0.19.1) Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipython>=7.23.1->ipykernel->-r requirements.txt (line 2)) (3.0.47) Requirement already satisfied: pygments>=2.4.0 in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipython>=7.23.1->ipykernel->-r requirements.txt (line 2)) (2.18.0) Requirement already satisfied: stack-data in c:\users\vgods\miniconda3\envs\ryzen-ai-1.2.0\lib\site-packages (from ipython>=7.23.1->ipykernel->-r requirements.txt (line 2)) (0.6.2) ``` -------------------------------- ### Example output Source: https://github.com/amd/ryzenai-sw/blob/main/WinML/CNN/ObjectDetection/README.md Shows the expected console output when running with NPU, including performance metrics and detection results. ```text Model: yolov8m.onnx Image: object_detection_input.jpg EP Policy: NPU Registered: VitisAIExecutionProvider Creating inference session... Execution Providers: ['VitisAIExecutionProvider', 'CPUExecutionProvider'] Input: images [1, 3, 640, 640] Preprocessing image... Warming up... Benchmarking... Performance: Average latency: 37.29 ms Throughput: 26.82 images/sec Processing results... Detected 1 objects, output saved to: ../images\object_detection_npu_output.png Detections: - dog: 1 ``` -------------------------------- ### Install OpenCV Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/quark_docs_repo_onnx_basic_usage_onnx.rst Installs the OpenCV Python library, which is used to read images for calibration. ```bash pip install opencv-python ``` -------------------------------- ### Build ResNet50 C++ example Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/iGPU/getting_started/README.md Builds the ResNet50 C++ example using the compile.bat script. Provide the path to your OpenCV build directory. ```bash cd cpp compile.bat "path/to/your/opencv/build" ``` -------------------------------- ### Install Ryzen AI with EULA agreement and venv Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/ryzen_ai_docs_repo_rai_linux.rst Re-runs the installer after reading the EULA, agreeing to it and creating a Python virtual environment at the specified path. ```bash ./install_ryzen_ai_1_4.sh -a yes -p -l ``` -------------------------------- ### Set Ryzen AI installation path Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/hello_world/README.md Sets the RYZEN_AI_INSTALLATION_PATH environment variable to the Ryzen AI installation location. Replace with the actual path. ```bash # Default location of RyzenAI software installation set RYZEN_AI_INSTALLATION_PATH= ``` -------------------------------- ### Install dependencies and create conda environment Source: https://github.com/amd/ryzenai-sw/blob/main/Demos/ASR/Parakeet-TDT/README.md Clone the repository, create a conda environment cloned from your Ryzen AI installation, activate it, and install dependencies. ```bash git clone https://github.com/amd/RyzenAI-SW.git cd RyzenAI-SW/Demos/ASR/Parakeet-TDT conda create --name asr_parakeet_env --clone ryzen-ai- conda activate asr_parakeet_env pip install -r requirements.txt ``` -------------------------------- ### Install AMD Quark 0.8 Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/ryzen_ai_docs_repo_oga_model_prepare.rst Installs AMD Quark 0.8 from the extracted archive. Replace the placeholder with the actual wheel filename. ```bash cd pip install amd_quark-0.8+<>.whl ``` -------------------------------- ### Build and prepare C++ example for model_benchmark.exe Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/ryzen_ai_docs_repo_hybrid_oga.rst Builds the C++ example source code for model_benchmark.exe using CMake with Visual Studio 17 2022, then copies the required runtime DLLs to the build output. ```batch :: Copy project files xcopy /E /I "%RYZEN_AI_INSTALLATION_PATH%\hybrid-llm\examples\c" .\sources xcopy /E /I "%RYZEN_AI_INSTALLATION_PATH%\hybrid-llm\onnxruntime_genai\include" .\sources\include xcopy /E /I "%RYZEN_AI_INSTALLATION_PATH%\hybrid-llm\onnxruntime_genai\lib" .\sources\lib :: Build project cd sources cmake -G "Visual Studio 17 2022" -A x64 -S . -B build cmake --build build --config Release :: Copy runtime DLLs xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\deployment\hybrid-llm\onnxruntime-genai.dll" .\build\Release xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\deployment\hybrid-llm\onnx_custom_ops.dll" .\build\Release xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\deployment\hybrid-llm\ryzen_mm.dll" .\build\Release xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\deployment\hybrid-llm\ryzenai_onnx_utils.dll" .\build\Release xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\deployment\voe\DirectML.dll" .\build\Release xcopy /Y "%RYZEN_AI_INSTALLATION_PATH%\deployment\voe\onnxruntime.dll" .\build\Release ``` -------------------------------- ### Run RAG example with profiling flag Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/README.md Run the RAG example with the --profiling flag to enable profiling of LLM performance metrics. Actual numbers may vary depending on the LLM used, model version, and specific system configuration. ```sh python rag.py --profiling ``` -------------------------------- ### Compact benchmark output example (--compact) Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/VLM/README.md Example compact output produced with the --compact flag. Shows only total tokens, image tokens, TTFT, and tokens per second for each size. ```text ============================================================ BENCHMARK SUMMARY ============================================================ Model: ./phi-4-mm-fine-tuned-onnx Image: ./test_image.jpg Prompt: "Describe this image in detail." Text tokens (constant across sizes): 16 Size Total Tok Img Tok TTFT (s) TPS (tok/s) ------------------------------------------------------------ 448x448 555 539 8.95 4.05 1024x1024 2635 2619 47.02 3.61 2048x2048 5781 5765 137.72 2.29 ============================================================ ``` -------------------------------- ### model_benchmark.exe example usage Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/ryzen_ai_docs_repo_npu_oga.rst Example usage of model_benchmark.exe with a Llama-2-7b model. The command specifies the input folder, generation length, prompt file, and a list of prompt lengths. ```text .\libs\model_benchmark.exe -i "Llama-2-7b-hf-awq-g128-int4-asym-bf16-onnx-ryzen-strix" -g 20 -p "Llama-2-7b-hf-awq-g128-int4-asym-bf16-onnx-ryzen-strix\prompts.txt" -l "2048,1024,512,256,128" ``` -------------------------------- ### Batch benchmark summary table example Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/VLM/README.md Example batch benchmark summary table. Shows preprocessing time, TTFT, prefill throughput, decode throughput, and decode latency for three image sizes. ```text ============================================================================================================== BENCHMARK SUMMARY ============================================================================================================== Model: ./phi-4-mm-fine-tuned-onnx Image: ./test_image.jpg Prompt: "Describe this image in detail." Text tokens (constant across sizes): 16 Size Img Tok Total Tok Preproc (ms) TTFT (s) Prefill Decode Decode Lat (tokens/s) (tokens/s) (ms/token) -------------------------------------------------------------------------------------------------------------- 448x448 539 555 9.76 8.94 62.10 4.05 246.94 1024x1024 2619 2635 74.41 46.95 56.97 3.61 277.03 2048x2048 5765 5781 198.19 137.52 42.05 2.29 436.58 ============================================================================================================== ``` -------------------------------- ### Live microphone transcription on NPU Source: https://github.com/amd/ryzenai-sw/blob/main/Demos/ASR/Parakeet-TDT/README.md Installs sounddevice and runs live microphone transcription on NPU. ```bash pip install sounddevice python live_transcribe.py --device npu ``` -------------------------------- ### vlm_run.py examples Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/VLM/README.md Example invocations of vlm_run.py covering basic inference, custom prompt, image resizing, token count, and prompt debugging. Each command uses the same model and image paths. ```bash # Basic inference python vlm_run.py -m ./model -i image.jpg # Custom prompt python vlm_run.py -m ./model -i image.jpg -p "What's in this image?" # Resize image before running python vlm_run.py -m ./model -i image.jpg --image_size 1024 1024 # Generate more tokens python vlm_run.py -m ./model -i image.jpg --max_tokens 512 # Debug prompt formatting python vlm_run.py -m ./model -i image.jpg --show_prompt ``` -------------------------------- ### Example output from face detection inference Source: https://github.com/amd/ryzenai-sw/blob/main/WinML/CNN/FaceDetection/README.md Example console output showing model info, execution providers, performance metrics, and detection results. ```text Model: retinaface_resnet.onnx Image: face_detection_input.jpg EP Policy: NPU Registered: VitisAIExecutionProvider Creating inference session... Execution Providers: ['VitisAIExecutionProvider', 'CPUExecutionProvider'] Input: input [1, 3, 640, 640] Preprocessing image... Warming up... Benchmarking... Performance: Average latency: 15.34 ms Throughput: 65.19 images/sec Processing results... Generated 16800 anchors Score Statistics: Min: 0.000012, Max: 0.998745, Mean: 0.023456 Scores > 0.5: 5 Top 10 scores: [0.991, 0.992, 0.995, 0.997, 0.998, ...] Using standard threshold: 0.5 Detected 4 faces (after NMS), output saved to: ../images/face_detection_npu_output.png ``` -------------------------------- ### Single benchmark output example Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/VLM/README.md Example output from a single benchmark run. Shows token counts, preprocessing time, TTFT, prefill throughput, decode latency, and peak memory usage for a phi4mm model at 1024x1024. ```text ============================================================ VLM BENCHMARK RESULTS ============================================================ Model Type: phi4mm Image Size: 1024x1024 Number of runs: 3 Token Breakdown: Total Prompt Tokens: 2635 Text Tokens: 16 Image Tokens: 2619 Preprocessing Time (image processing): Average: 74.41 ms Time To First Token (TTFT): Average: 46948.55 ms Prefill Throughput: Average: 56.97 tokens/sec Token Generation (excluding first token): Average: 277.03 ms/token TPS: 3.61 tokens/sec Peak Memory Usage: 8192.45 MB (8.00 GB) ============================================================ ``` -------------------------------- ### Build oga_api example with CMake Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/oga_api/CMakeLists.txt CMake configuration for building the oga_api example. Requires CMake 3.15 or higher and C++17. Sets output directories, includes headers from include/, links against onnxruntime-genai, and copies DLLs from libs/ to the executable directory after build. ```cmake cmake_minimum_required(VERSION 3.15) project(oga_api) set(CMAKE_CXX_STANDARD 17) # Output directory setup set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) # Include headers include_directories(${CMAKE_SOURCE_DIR}/include) # Add library search path link_directories(${CMAKE_SOURCE_DIR}/libs) # Executable source add_executable(example main.cpp) # Link the .lib file (drop the extension) target_link_libraries(example onnxruntime-genai) # Copy DLLs after build file(GLOB DLLS "${CMAKE_SOURCE_DIR}/libs/*.dll") add_custom_command(TARGET example POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DLLS} $) ``` -------------------------------- ### Install and Run Open WebUI Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/ryzen_ai_docs_repo_llm_server_interface.rst Install and run Open WebUI in a terminal. Requires Python 3.11 and conda. After running these commands, Open WebUI will be available at http://localhost:8080/. ```bash conda create -n webui python=3.11 conda activate webui pip install open-webui open-webui serve ``` -------------------------------- ### Run SESR-M7 2x super-resolution inference Source: https://github.com/amd/ryzenai-sw/blob/main/CNN-examples/super-resolution/README.md Quick start workflow for running SESR-M7 2x super-resolution inference on an AMD AI PC NPU. Clone the model repository, install dependencies, and run inference with the provided command. The example uses the 256x256 tile variant; substitute the repository name and ONNX filename for other tile sizes. ```powershell git clone https://hf.co/amd/sesr-m7-256x256-tiles-amdnpu cd sesr-m7-256x256-tiles-amdnpu ``` ```powershell pip install -r requirements.txt ``` ```powershell python onnx_inference.py --onnx onnx-models/sesr_nchw_int8.onnx --input assets/input_ice_climber_0844.png --out-dir outputs --device npu ``` -------------------------------- ### Install OpenCV from source Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/getstartex.rst Commands to clone and build OpenCV 4.6.0 from source with static libraries. The build files are written to 'build\'. ```bash git clone https://github.com/opencv/opencv.git -b 4.6.0 cd opencv cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_CONFIGURATION_TYPES=Release -A x64 -T host=x64 -G "Visual Studio 17 2022" "-DCMAKE_INSTALL_PREFIX=C:\opencv" "-DCMAKE_PREFIX_PATH=C:\opencv" -DCMAKE_BUILD_TYPE=Release -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DBUILD_WITH_STATIC_CRT=OFF -B build cmake --build build --config Release cmake --install build --config Release ``` -------------------------------- ### Create calibration data folder and download sample image Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/quark_docs_repo_onnx_basic_usage_onnx.rst Creates a 'calib_data' directory and downloads a sample daisy.jpg image from the onnxruntime-inference-examples repository for calibration. ```bash mkdir calib_data wget -O calib_data/daisy.jpg https://github.com/microsoft/onnxruntime-inference-examples/blob/main/quantization/image_classification/cpu/test_images/daisy.jpg?raw=true ``` -------------------------------- ### Reproduction Commands for NPU Optimization Source: https://github.com/amd/ryzenai-sw/blob/main/Demos/ASR/Parakeet-TDT/OPTIMIZATION.md Commands to set up the environment, download models, preprocess for NPU, benchmark, run live transcription, and start the API server. The first benchmark run takes ~30 minutes for compilation, subsequent runs take ~4 seconds for initialization. ```powershell # Environment conda activate ryzen-ai-1.7.0 # Download models python download_models.py --precision fp32 # Static shapes + NPU encoder fixes python preprocess_for_npu.py --precision fp32 # Benchmark (first run = ~30min compile, subsequent = ~4s init) python test_transcribe.py audio.wav --device npu --decoder-device gpu --runs 3 # Live microphone demo python live_transcribe.py --device npu # API server python server.py --device npu ``` -------------------------------- ### Set up conda environment and install dependencies Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/VLM/README.md Creates a conda environment named vlm-bench with Python 3.12 and installs the required packages for CPU-based VLM benchmarking. For AMD NPU models, activate the Ryzen AI conda environment instead. ```bash conda create -n vlm-bench python=3.12 conda activate vlm-bench pip install onnxruntime-genai pillow numpy psutil ``` -------------------------------- ### Import dependencies for SmoothQuant dummy example Source: https://github.com/amd/ryzenai-sw/blob/main/LLM-examples/RAG-OGA/Dataset/quark_docs_repo_pytorch_smoothquant.rst Imports required for the dummy example that verifies SmoothQuant's effect on quantization error using a single Linear layer and LayerNorm. ```python import torch import torch.nn as nn import copy from torch.utils.data import DataLoader ``` -------------------------------- ### Download calibration data with setup_calib_data.py Source: https://github.com/amd/ryzenai-sw/blob/main/WinML/CNN/ConvNeXt/README.md Downloads calibration data for INT8 quantization. No authentication is required. Run from the model directory. ```sh cd \WinML\CNN\ConvNeXt\model\ python setup_calib_data.py ``` -------------------------------- ### Run NPU-GPU pipeline Source: https://github.com/amd/ryzenai-sw/blob/main/Demos/NPU-GPU-Pipeline/README.md Runs the NPU-GPU pipeline example. This command off-loads Stable Diffusion to the iGPU and Yolov8+RCAN to the NPU. ```bash cd .. python pipeline.py -i test/test_img2img.mp4 --npu --provider_config vaip_config.json --igpu ```