### Run Inceptionv3 Inference Example Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/onnxruntime/inceptionV3/README.md Navigates to the example directory, runs prerequisite scripts, checks for Onnxruntime installation, and executes the Inceptionv3 Python script for inference. ```bash cd examples/onnxruntime/inveptionv3 ./prereq_steps.sh pip list | grep onnxruntime python invepctionv3.py ``` -------------------------------- ### Build and Run Custom MIOpen Kernel Example Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/migraphx/custom_op_miopen_kernel/README.md Steps to build and execute the custom MIOpen kernel example. Ensure ROCm is installed and environment variables are set. ```bash export LD_LIBRARY_PATH=/opt/rocm/lib:$LD_LIBRARY_PATH ``` ```bash cd $MIGRAPHX_SRC/examples/migraphx/custom_op_miopen_kernel/ ``` ```bash mkdir build && cd build ``` ```bash cmake .. && make ``` ```bash ./custom_op_miopen_kernel ``` -------------------------------- ### Run Resnet50 Inference Example Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/onnxruntime/resnet50/README.md Navigate to the example directory, run prerequisite steps to install onnxruntime, and then execute the Python inference script. Check onnxruntime installation. ```bash cd examples/onnxruntime/resnet50 ./prereq_steps.sh pip list | grep onnxruntime python resnet50.py ``` -------------------------------- ### Install Jupyter Notebook Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/vision/python_nfnet/README.md Instructions for installing the Jupyter Notebook library. Ensure this is installed before proceeding with the notebook examples. ```bash https://jupyter.org/install ``` -------------------------------- ### Build and Run Custom rocBLAS Kernel Example Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/migraphx/custom_op_rocblas_kernel/README.md Steps to build and execute the custom operator example. Ensure ROCm is installed and environment variables are set correctly. ```bash export LD_LIBRARY_PATH=/opt/rocm/lib:$LD_LIBRARY_PATH cd $MIGRAPHX_SRC/examples/migraphx/custom_op_rocblas_kernel/ mkdir build && cd build cmake .. && make ./custom_op_rocblas_kernel ``` -------------------------------- ### Setup Python Virtual Environment Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/transformers/python_llama2/README.md Creates and activates a Python virtual environment. Ensure the python venv package is installed. ```bash # this will require the python venv to installed (e.g. apt install python3.8-venv) python3 -m venv ll2_venv . ll2_venv/bin/activate ``` -------------------------------- ### Setup Python Virtual Environment Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/diffusion/python_controlnet_canny_sd_15/README.md Creates and activates a Python virtual environment. Requires python3-venv to be installed. ```bash python3 -m venv sd_venv . sd_venv/bin/activate ``` -------------------------------- ### Install and Upgrade Python Packages Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/vision/python_resnet50/resnet50_inference.ipynb Installs or upgrades pip, opencv-python, and matplotlib. Ensure these are installed before proceeding with the example. ```python !pip install --upgrade pip !pip install opencv-python==4.1.2.30 !pip install matplotlib ``` -------------------------------- ### Run Gradio Application Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/transformers/python_whisper/README.md Starts the Gradio web server. This requires the 'Console application' setup to be complete and may take several minutes to load models. ```bash python gradio_app.py ``` -------------------------------- ### Install MIGraphX from Binaries Source: https://github.com/rocm/amdmigraphx/blob/develop/README.md Installs MIGraphX using the system's package manager. Ensure ROCm is installed beforehand. ```bash sudo apt update && sudo apt install -y migraphx ``` -------------------------------- ### Setup Python Environment for MIGraphX Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/diffusion/python_stable_diffusion_21/README.md Creates and activates a Python virtual environment. Ensure the python3-venv package is installed. ```bash # this will require the python venv to installed (e.g. apt install python3.8-venv) python3 -m venv sd_venv . sd_venv/bin/activate ``` -------------------------------- ### Install Dependencies Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/vision/python_nfnet/nfnet_inference.ipynb Installs necessary packages for the environment, including FFmpeg and system libraries. ```bash !apt-get update !apt-get install ffmpeg libsm6 libxext6 -y ``` -------------------------------- ### Compile and Run MIGraphX Example Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/migraphx/cpp_parse_load_save/README.md Instructions for compiling and running the `parse_load_save.cpp` example using CMake. Shows command-line usage for the executable. ```bash $ mkdir build $ cd build $ cmake .. $ make ``` ```bash $ ./parse_load_save [options] options: --parse onnx --load json/msgpack --save ``` -------------------------------- ### CMake Configuration for Dynamic Batch Example Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/migraphx/cpp_dynamic_batch/CMakeLists.txt Configures CMake for a C++ project using AMDMIGraphX. Ensure migraphx is installed and its path is added to CMAKE_PREFIX_PATH. This setup is for a dynamic batching example. ```cmake cmake_minimum_required(VERSION 3.5) project (cpp_dynamic_batch) set (CMAKE_CXX_STANDARD 14) set (EXAMPLE dynamic_batch) list (APPEND CMAKE_PREFIX_PATH /opt/rocm) find_package (migraphx) message("source file: " ${EXAMPLE}.cpp " ---> bin: " ${EXAMPLE}) add_executable(${EXAMPLE} ${EXAMPLE}.cpp) target_link_libraries(${EXAMPLE} migraphx::c) ``` -------------------------------- ### CMakeLists.txt Configuration Example Source: https://github.com/rocm/amdmigraphx/wiki/Getting-started:-using-the-new-features-of-MIGraphX-0.2 Example settings for the CMakeLists.txt file to specify the locations of MIGraphX, its build directory, and dependencies. Adjust these paths to your system. ```cmake set (MIGRAPHX_FOLDER /home/scxiao/Workplace/projects/AMDMIGraphX) set (MIGRAPHX_BUILD /home/scxiao/Workplace/projects/AMDMIGraphX/build) set (MIGRAPHX_DEPS /home/scxiao/Workplace/projects/AMDMIGraphX/deps_py/lib) ``` -------------------------------- ### Install MIGraphX from Source Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/onnxruntime/inceptionV3/README.md Compiles and installs MIGraphX from source within the Docker container. This process builds the package and installs it as a .deb file. ```bash rbuild develop -d deps -B build cd build make -j$(nproc) package && dpkg -i *.deb ``` -------------------------------- ### Run Gradio Application Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/diffusion/python_controlnet_canny_sd_15/README.md Launches the Gradio web application for text-to-image generation. This requires the console application setup to be complete. The application loads models, which can take time, and then starts a server. ```bash python gradio_app.py --prompt "blue bird" --control_image bird_canny.png ``` -------------------------------- ### Install Dependencies Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/diffusion/python_stable_diffusion_xl/README.md Installs or upgrades pip and then installs project dependencies from requirement files. ```bash pip install -U pip pip install -r torch_requirements.txt -r requirements.txt ``` -------------------------------- ### Install Dependencies Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/vision/python_super_resolution/Run_Super_Resolution_Model.ipynb Installs pip and project requirements. Ensure requirements.txt is available in the current directory. ```python !pip3 install --upgrade pip #needed for opencv-python installation !pip3 install -r requirements.txt ``` -------------------------------- ### Download Example Image Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/vision/python_nfnet/nfnet_inference.ipynb Downloads a sample image ('traffic_light.jpg') for testing the inference pipeline. ```bash !wget -nc http://farm5.static.flickr.com/4072/4462811418_8bc2bd42ca_z_d.jpg -O traffic_light.jpg ``` -------------------------------- ### Install Dependencies Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/diffusion/python_controlnet_canny_sd_15/README.md Installs project dependencies using pip. Ensure torch_requirements.txt and requirements.txt exist. ```bash pip install -r torch_requirements.txt -r requirements.txt ``` -------------------------------- ### Install Dependencies for SD3 Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/diffusion/python_stable_diffusion_3/README.md Installs project dependencies using pip. Make sure to upgrade pip first. ```bash pip install --upgrade pip pip install -r torch_requirements.txt pip install -r requirements.txt ``` -------------------------------- ### Install Dependencies Source: https://github.com/rocm/amdmigraphx/blob/develop/tools/model_zoo/test_generator/README.md Installs Python virtual environment and project dependencies. Also installs sndfile and ffmpeg for audio datasets. ```bash python3 -m venv .venv . .venv/bin/activate pip install -r requirements.txt ``` ```bash apt install libsndfile1 apt install ffmpeg ``` -------------------------------- ### Inference Output Example (Guitar 2) Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/onnxruntime/resnet50/README.md Example output for a second guitar image, showing the top predicted classes and inference time. ```text using guitar2.jpg. Image of a les paul stype electric guitar which is in the imagenet classes electric guitar 0.7114628 acoustic guitar 0.23226906 banjo 0.044191252 pick 0.0056983875 stage 0.0013321621 resnet50, time = 43.09 ms ``` -------------------------------- ### Install Requirements Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/nlp/python_bert_squad/README.md Installs all necessary Python packages listed in the requirements file. ```bash pip3 install -r requirements_bertsquad.txt ``` -------------------------------- ### Install Dependencies Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/nlp/python_bert_squad/BERT-Squad.ipynb Installs necessary Python packages from a requirements file. Ensure 'requirements_bertsquad.txt' is available. ```python !pip3 install -r requirements_bertsquad.txt ``` -------------------------------- ### Install MIGraphX FPGA Targets Source: https://github.com/rocm/amdmigraphx/blob/develop/src/targets/fpga/CMakeLists.txt Installs the MIGraphX FPGA target and its include directories. ```cmake rocm_install_targets( PRIVATE TARGETS migraphx_fpga INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include ) ``` -------------------------------- ### Inference Output Example (Guitar 3) Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/onnxruntime/resnet50/README.md Example output for a third guitar image, showing the top predicted classes and inference time. ```text using guitar3.jpg. Image of a super strat 7 string style electric guitar which is in the imagenet classes electric guitar 0.71952045 prayer rug 0.08914763 banjo 0.078091994 acoustic guitar 0.056061186 violin 0.021640636 resnet50, time = 71.71 ms ``` -------------------------------- ### Build and Install Onnxruntime Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/onnxruntime/inceptionV3/README.md Builds Onnxruntime using a provided script and installs the generated wheel file. Ensure the Python version used matches the host system. ```bash ../../../tools/build_and_test_onnxrt.sh pip3 install /onnxruntime/build/Release/Linux/dist/*.whl ``` -------------------------------- ### Inference Output Example (Guitar) Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/onnxruntime/resnet50/README.md Example output for a guitar image, showing the top predicted classes and inference time. ```text using guitar.jpg. Image of an non traditional electric guitar shape (Telecaster) which is in the imagenet class labels electric guitar 0.4413027 acoustic guitar 0.14725313 Band Aid 0.14059556 pick 0.076821454 rule 0.020968033 resnet50, time = 77.01 ms ``` -------------------------------- ### Download Optional Samples Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/transformers/python_whisper/README.md Downloads optional sample files for testing. The example can be tested without these. ```bash ./download_samples.sh ``` -------------------------------- ### Install MIGraphX Package Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/onnxruntime/resnet50/README.md Build and install MIGraphX as a deb package within the Docker container. Verify the installation using dpkg. ```bash rbuild develop -d deps -B build cd build make -j$(nproc) package && dpkg -i *.deb ``` ```bash dpkg -l | grep migraphx ``` -------------------------------- ### Install FFmpeg Dependency Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/transformers/python_whisper/README.md Installs FFmpeg, a tool required for handling audio files. ```bash apt install ffmpeg ``` -------------------------------- ### Prepare Prerequisites with rbuild Source: https://github.com/rocm/amdmigraphx/blob/develop/README.md Installs all necessary prerequisites for building MIGraphX into the 'depend' folder. Ensure you have followed the rbuild installation instructions first. ```bash rbuild prepare -d depend ``` -------------------------------- ### Install Prerequisites with apt Source: https://github.com/rocm/amdmigraphx/wiki/Build-MIGraphX-Source-in-ROCm3.3 Installs essential packages like rocm-cmake, python3-pip, and rocblas using the apt package manager. Note that MIOpen is not installed here as it's outdated in ROCm 3.3. ```bash sudo apt update && sudo apt install -y rocm-cmake python3-pip rocblas ``` -------------------------------- ### Install Dependencies Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/vision/python_3dunet/3dunet_inference.ipynb Installs necessary Python libraries for the project, including MIGraphX, SimpleITK, and Matplotlib. ```python !pip install SimpleITK matplotlib scikit-image ``` -------------------------------- ### Install ROCm Libraries Source: https://github.com/rocm/amdmigraphx/wiki/Getting-started:--An-example-of-using-MIGraphX-0.1 Installs necessary ROCm libraries including MIOpen. Ensure MIOpen version 1.6 or greater is installed. ```bash sudo apt install rocm-libs miopen-hip ``` -------------------------------- ### Install Torch-MIGraphX using pip Source: https://github.com/rocm/amdmigraphx/blob/develop/docs/install/install-torch-migraphx.rst Use this command to install the Torch-MIGraphX library via pip. Ensure PyTorch and ROCm are installed beforehand. ```shell pip install torch_migraphx ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/transformers/python_whisper/README.md Installs project dependencies listed in requirements.txt. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install rbuild Build Tool Source: https://github.com/rocm/amdmigraphx/wiki/Build-MIGraphX-Source-in-ROCm3.3 Installs the rbuild build tool from its master branch using pip3. sudo may be required for installation. ```bash pip3 install https://github.com/RadeonOpenCompute/rbuild/archive/master.tar.gz ``` -------------------------------- ### Install Optimum-ONNX from Development Branch Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/diffusion/python_stable_diffusion_3/README.md Installs the optimum-onnx package from its development branch, as the latest release may not include necessary changes for model export. ```bash pip install "optimum-onnx[onnxruntime]"@git+https://github.com/huggingface/optimum-onnx.git ``` -------------------------------- ### Inference Output Example (Screwdrivers) Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/onnxruntime/resnet50/README.md Example output for screwdrivers image, showing the top predicted class and inference time. ```text using screwdrivers.jpg. Image of screwdrivers which are in the imagenet class labels screwdriver 0.96512324 carpenter's kit 0.03258186 hammer 0.0007571124 ballpoint 0.00058690814 can opener 0.00026641905 resnet50, time = 109.67 ms ``` -------------------------------- ### Build and Compile MNIST Inference Example Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/vision/cpp_mnist/README.md Use these commands to create the executable for the MNIST inference example. Ensure you are in the 'build' directory and have the correct C++ compiler path. ```bash $ mkdir build $ cd build $ CXX=/opt/rocm/llvm/bin/clang++ cmake .. $ make ``` -------------------------------- ### Install Sphinx Requirements for Documentation Source: https://github.com/rocm/amdmigraphx/blob/develop/README.md Installs the Python dependencies required for building the MIGraphX documentation using Sphinx. May require sudo privileges. ```bash cd docs pip3 install -r sphinx/requirements.txt ``` -------------------------------- ### Makefile for MIGraphX Example Source: https://github.com/rocm/amdmigraphx/wiki/Getting-started:--An-example-of-using-MIGraphX-0.1 A Makefile to compile the MIGraphX C++ example. It specifies compiler flags, include paths for MIGraphX and ROCm, and libraries to link against. ```makefile CXXFLAGS=-g -std=c++14 MIGRAPHX_INCLUDES= -I /opt/rocm/include -I /opt/rocm/targets/gpu/include MIGRAPHX_LIBS = -L /opt/rocm/lib -lmigraphx -lmigraphx_onnx -lmigraphx_gpu CXX=/opt/rocm/hcc/bin/hcc example: example.cxx $(CXX) -o example $(CXXFLAGS) $(MIGRAPHX_INCLUDES) example.cxx $(MIGRAPHX_LIBS) ``` -------------------------------- ### Install MIGraphX Source: https://github.com/rocm/amdmigraphx/wiki/Build-MIGraphX-Source-in-ROCm3.3 Installs the compiled MIGraphX libraries and associated files to their designated locations on the system. This is typically done after successful compilation and verification. ```bash make install ``` -------------------------------- ### Install Requirements (Shell) Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/vision/python_super_resolution/README.md Installs all Python package dependencies listed in the requirements.txt file. Ensure this file is present in the current directory. ```shell pip3 install -r requirements.txt ``` -------------------------------- ### Install MIGraphx GPU Targets Source: https://github.com/rocm/amdmigraphx/blob/develop/src/targets/gpu/CMakeLists.txt Installs the specified MIGraphx GPU targets (`migraphx_gpu`, `migraphx_device`, `compile_for_gpu`) and include directories using the `rocm_install_targets` macro. ```cmake rocm_install_targets( PRIVATE TARGETS migraphx_gpu migraphx_device compile_for_gpu INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include ) ``` -------------------------------- ### Download Sample Video and Install youtube-dl Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/vision/python_resnet50/resnet50_inference.ipynb Downloads a sample video using youtube-dl. It first prompts for a sudo password to install/upgrade youtube-dl if necessary, then downloads the video and renames it. ```python if not path.exists("./sample_vid.mp4"): import getpass import os password = getpass.getpass() command = "sudo -H -S pip install --upgrade youtube-dl" os.system('echo %s | %s' % (password, command)) !youtube-dl https://youtu.be/TkqYmvH_XVs !mv sample_vid-TkqYmvH_XVs.mp4 sample_vid.mp4 ``` -------------------------------- ### Run Jupyter Notebook Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/migraphx/export_frozen_graph_tf2/README.md Navigate to the example directory and run this command to launch Jupyter Notebook from your browser. ```bash jupyter notebook ``` -------------------------------- ### Install Build Dependencies for MIGraphX Source: https://github.com/rocm/amdmigraphx/blob/develop/docs/install/install-migraphx.rst Install necessary build tools and libraries like rocm-cmake, pip3, rocblas, and miopen-hip before building MIGraphX from source. This requires sudo privileges. ```shell sudo apt install -y rocm-cmake python3-pip rocblas miopen-hip ``` -------------------------------- ### BERT Input IDs Example Source: https://github.com/rocm/amdmigraphx/wiki/Getting-started:-using-the-new-features-of-MIGraphX-0.4 This is an example of tokenized input for BERT, representing two sentences. It includes a starting token [CLS], tokens for each sentence, separator tokens [SEP], and padding zeros. ```text 101 1124 1163 1103 11785 1200 14301 16288 1671 2144 112 189 4218 1103 1419 112 188 1263 118 1858 3213 5564 119 102 107 1109 11785 1200 14301 16288 1671 1674 1136 4218 1412 1263 118 1858 3213 5564 119 102 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ``` -------------------------------- ### Enter Docker Development Environment Source: https://github.com/rocm/amdmigraphx/wiki/Build-MIGraphX-Source-in-ROCm3.3 Launches a Docker container for development, mounting the current directory, setting the working directory, and enabling access to GPU devices. The container is based on the 'migraphx:rocm3.3' image. ```bash docker run --device='/dev/kfd' --device='/dev/dri' -v=`pwd`:/code/AMDMIGraphX -w /code/AMDMIGraphX --group-add video -it migraphx:rocm3.3 ``` -------------------------------- ### Get libstdc++ Path for GCC 11 Source: https://github.com/rocm/amdmigraphx/blob/develop/src/CMakeLists.txt Executes a command to find the installation path of libstdc++ for GCC 11. This path is used to configure compiler options for Clang. ```cmake execute_process(COMMAND gcc-11 --print-file-name "" OUTPUT_VARIABLE LIBSTDCXX11_PATH OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) ``` -------------------------------- ### Link MIGraphX C/C++ API in CMake Source: https://github.com/rocm/amdmigraphx/blob/develop/README.md Example CMake code to find and link the MIGraphX C/C++ library in your application. Ensure CMAKE_PREFIX_PATH is set to the MIGraphX installation directory. ```cmake find_package(migraphx) target_link_libraries(myApp migraphx::c) ``` -------------------------------- ### Build Custom HIP Kernel Operator for MIGraphX Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/migraphx/custom_op_hip_kernel/README.md Follow these steps to build a custom operator using a HIP kernel. Ensure ROCm is installed and set the necessary environment variables. This process involves navigating to the example directory, creating a build folder, and using CMake with the ROCm clang++ compiler. ```bash export LD_LIBRARY_PATH=/opt/rocm/lib:$LD_LIBRARY_PATH cd $MIGRAPHX_SRC/examples/migraphx/custom_op_hip_kernel/ mkdir build && cd build CXX=/opt/rocm/llvm/bin/clang++ cmake .. && make ``` -------------------------------- ### Verify MIGraphX Installation Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/onnxruntime/inceptionV3/README.md Checks if MIGraphX has been installed correctly by listing installed packages. This command is useful for confirming the installation within the Docker environment. ```bash dpkg -l | grep migraphx ``` -------------------------------- ### Upgrade Pip and Install Requirements Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/vision/python_nfnet/nfnet_inference.ipynb Upgrades the pip package installer and installs project-specific requirements from a file. ```bash !pip3 install --upgrade pip !pip3 install -r requirements_nfnet.txt ``` -------------------------------- ### INT8 Quantization Usage Example Source: https://github.com/rocm/amdmigraphx/wiki/Getting-started:-using-the-new-features-of-MIGraphX-0.4 Demonstrates loading an ONNX model, creating calibration data, quantizing the program to INT8 using a GPU target, and running the quantized program. ```cpp // load program from an onnx file migraphx::program load_onnx_file(std::string file_name) { auto prog = migraphx::parse_onnx(file_name); return prog; } // generate inputs of the program, this example uses the inputs as // the calibration data. Users can use whatever data they think reasonable // as the calibration data (but should pack the data in the same format) migraphx::program::parameter_map create_param_map(migraphx::program& p) { migraphx::program::parameter_map m; for (auto&& x : p.get_parameter_shapes()) { m[x.first] = migraphx::generate_argument(x.second); } return m; } // run the program on the target device with the input void run_prog(migraphx::program p, const migraphx::target& t, migraphx::parameter_map& inputs, std::vector& result) { p.compile(t); migraphx::program::parameter_map m; for (auto &&x : p.get_parameter_shapes()) { if (inputs.count(x.first) > 0) { m[x.first] = t.copy_to(inputs[x.first]); } else { m[x.first] = migraphx::generate_argument(x.second); } } auto res_arg = t.copy_from(p.eval(m)); res_arg.visit([&](auto output) { result.assign(output.begin(), output.end()); }); } auto prog = load_onnx_file(file.onnx); // create inputs, also used as calibration data auto m = create_param_map(prog); std::vector cali = {m}; migraphx::target gpu_t = migraphx::gpu::target{}; // quantize the program migraphx::quantize_int8(prog, gpu_t, cali); std::vector result; // run the program run_prog(prog, gpu_t, m, result); ``` -------------------------------- ### Install Driver Target Source: https://github.com/rocm/amdmigraphx/blob/develop/src/driver/CMakeLists.txt Installs the driver target using the ROCm installation commands. This makes the driver available after the build process. ```cmake rocm_install_targets( TARGETS driver ) ``` -------------------------------- ### C++ Seq2Seq Build Instructions Source: https://github.com/rocm/amdmigraphx/wiki/Getting-started:-using-the-new-features-of-MIGraphX-0.2 Steps to build the seq2seq_trans binary from the source code using CMake and Make. Ensure CMakeLists.txt is configured correctly. ```bash cd ${XXX}/seq2seq mkdir build cd build cmake .. make ``` -------------------------------- ### Install ROCm DKMS Driver Source: https://github.com/rocm/amdmigraphx/wiki/Setup-to-use-MIGraphX-with-docker This sequence of commands adds the ROCm repository, updates package lists, and installs the ROCm DKMS driver. A reboot is required after installation. ```bash sh -c 'echo deb [arch=amd64 trusted=yes] http://repo.radeon.com/rocm/apt/4.2/ xenial main > /etc/apt/sources.list.d/rocm.list' ``` ```bash sudo apt-get update ``` ```bash sudo apt-get -y install rocm-dkms && sudo reboot ``` -------------------------------- ### Build MIGraphX with CPU Support Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/vision/cpp_mnist/README.md Example CMake command to build MIGraphX with CPU target support enabled. ```bash CXX=/opt/rocm/llvm/bin/clang++ cmake -DMIGRAPHX_ENABLE_CPU=On .. ``` -------------------------------- ### Complete MIGraphX Python API Example Source: https://github.com/rocm/amdmigraphx/wiki/Getting-started:-using-the-new-features-of-MIGraphX-0.2 This is the complete end-to-end program demonstrating the MIGraphX Python API, including webcam capture, image preprocessing, ONNX model parsing, compilation, parameter loading, and inference. ```python import numpy as np import cv2 import json import migraphx # video settings cap = cv2.VideoCapture(0) cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 320) cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 240) ret, frame = cap.read() ``` -------------------------------- ### MIOpen Performance Database Entries Source: https://github.com/rocm/amdmigraphx/wiki/resnext-,-a-case-study-demonstrating-the-importance-of-library-tuning These are example entries found in the MIOpen local performance database before tuning. They represent pre-tuned kernel configurations. ```text 2048-8-8-1x1-384-8-8-32-0x0-1x1-1x1-0-NCHW-FP32-F=ConvAsm1x1U:4,8,4,16,1,4,4,2;ConvOclDirectFwd1x1:1,64,1,1,1,4,16,2048,0 2048-8-8-1x1-448-8-8-32-0x0-1x1-1x1-0-NCHW-FP32-F=ConvAsm1x1U:2,8,2,32,2,4,1,4;ConvOclDirectFwd1x1:1,64,1,1,1,1,16,256,0 2048-8-8-1x1-192-8-8-32-0x0-1x1-1x1-0-NCHW-FP32-F=ConvAsm1x1U:1,8,1,64,2,4,2,2;ConvOclDirectFwd1x1:1,64,1,1,1,0,16,256,0 3-224-224-3x3-64-224-224-16-1x1-1x1-1x1-0-NCHW-FP32-F=ConvOclDirectFwd:8,32,32,32,4,1,4,1,2;ConvOclDirectFwdFused:8,32,32,32,4,1,4,1,2 ``` -------------------------------- ### Load, Compile, and Print Model, Setup Video Capture Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/vision/python_resnet50/resnet50_inference.ipynb Loads the ONNX model, compiles it for GPU execution using MIGraphX, prints the compiled model's structure, and initializes video capture from the sample video file. ```python model = migraphx.parse_onnx("resnet50.onnx") model.compile(migraphx.get_target("gpu")) model.print() # Printed in terminal cap = cv2.VideoCapture("sample_vid.mp4") ``` -------------------------------- ### Install Gradio Dependencies Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/diffusion/python_controlnet_canny_sd_15/README.md Installs the necessary dependencies for the Gradio application using pip. ```bash pip install -r gradio_requirements.txt ``` -------------------------------- ### Build Torch-MIGraphX from Source Source: https://github.com/rocm/amdmigraphx/blob/develop/docs/install/install-torch-migraphx.rst Clone the repository and install Torch-MIGraphX locally using pip. This method is useful for development or when specific build configurations are needed. Refer to the GitHub repository for more details on local builds and Docker environments. ```shell git clone https://github.com/ROCm/torch_migraphx.git cd torch_migraphx pip install . --no-build-isolation ``` -------------------------------- ### Install MIGraphX ONNX Targets Source: https://github.com/rocm/amdmigraphx/blob/develop/src/onnx/CMakeLists.txt Installs the MIGraphX ONNX targets as private components of the build. ```cmake rocm_install_targets( PRIVATE TARGETS migraphx_onnx ) ``` -------------------------------- ### Generate All Samples Source: https://github.com/rocm/amdmigraphx/blob/develop/tools/model_zoo/test_generator/README.md Executes the generation script to create samples for all supported models and datasets. ```bash python generate.py ``` -------------------------------- ### Install Hjson Source: https://github.com/rocm/amdmigraphx/blob/develop/docs/gpu-driver/gpu-driver.rst Command to install the hjson Python package, which is required for converting Hjson files to Json. ```bash pip install hjson ``` -------------------------------- ### Set up MIGraphX Python Path Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/transformers/python_whisper/whisper.ipynb Ensures the MIGraphX library is accessible in the Python path before importing. Adjust the `mgx_lib_path` if your installation differs. ```python import sys mgx_lib_path = "/opt/rocm/lib/" # or "/code/AMDMIGraphX/build/lib/" if mgx_lib_path not in sys.path: sys.path.append(mgx_lib_path) import migraphx as mgx import numpy as np import os ``` -------------------------------- ### Install Whisper Dependencies Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/transformers/python_whisper/whisper.ipynb Installs the required Python packages for running Whisper with MIGraphX. Ensure you have a compatible environment. ```python # Install dependencies %pip install accelerate datasets optimum[onnxruntime] transformers ``` -------------------------------- ### Run Gradio Application Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/diffusion/python_stable_diffusion_21/README.md Launches the Gradio web server for the Stable Diffusion application. This requires the console application setup to be complete. Loading models can take several minutes. ```bash python gradio_app.py -p "a photograph of an astronaut riding a horse" --seed 13 ``` -------------------------------- ### Install Dependencies for Llama-2 Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/transformers/python_llama2/llama2.ipynb Installs necessary Python packages for running Llama-2 with MIGraphX. Ensure you have pip available. ```python # Install dependencies %pip install accelerate huggingface_hub[cli] optimum[onnxruntime] transformers sentencepiece ``` -------------------------------- ### Install OpenCV for Python Source: https://github.com/rocm/amdmigraphx/wiki/Getting-started:-using-the-new-features-of-MIGraphX-0.2 Install the OpenCV package for Python on Ubuntu systems. Ensure the PYTHONPATH is correctly set. ```bash prompt% apt install python-opencv ``` ```bash export PYTHONPATH=/opt/rocm/lib:$PYTHONPATH ``` -------------------------------- ### Create and Activate Python Virtual Environment Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/nlp/python_rnnt/README.md Use this command to create a new virtual environment for the project and activate it. Ensure you have Python 3 installed. ```bash python3 -m venv rnnt_venv . rnnt_venv/bin/activate ``` -------------------------------- ### Install Dependencies for Stable Diffusion Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/diffusion/python_stable_diffusion_21/sd21.ipynb Installs PyTorch with ROCm support and other necessary libraries for running Stable Diffusion models. ```python # Install dependencies # We need this version to run torch with gpu tensors !pip install torch -f https://download.pytorch.org/whl/rocm6.2.4/ !pip install optimum[onnxruntime] transformers diffusers accelerate ``` -------------------------------- ### Inference Output Example (Oscilloscope) Source: https://github.com/rocm/amdmigraphx/blob/develop/examples/onnxruntime/resnet50/README.md Example output for an oscilloscope image, showing the top predicted class and inference time. ```text using scope.jpg. Image of an oscilliscope which is in the imagenet class labels oscilloscope 0.99869776 radio 0.00051740184 screen 0.00044122382 monitor 8.556517e-05 tape player 5.1727424e-05 resnet50, time = 61.98 ms ```