onnxruntime/docs/genai/howto/build-from-source.md
2024-03-14 15:35:55 -07:00

2.3 KiB

title description has_children parent grand_parent nav_order
Build from source How to build ONNX Runtime GenAI from source false How to Generative AI (Preview) 2

Build onnxruntime-genai from source

{: .no_toc }

  • TOC placeholder {:toc}

Pre-requisites

cmake

Build steps

  1. Clone this repo

    git clone https://github.com/microsoft/onnxruntime-genai
    cd onnxruntime-genai
    
  2. Install ONNX Runtime

    By default, the onnxruntime-genai build expects to find the ONNX Runtime include and binaries in a folder called ort in the root directory of onnxruntime-genai. You can put the ONNX Runtime files in a different location and specify this location to the onnxruntime-genai build. These instructions use ORT_HOME as the location.

    • Install from release

      These instructions are for the Linux GPU build of ONNX Runtime. Replace the location with the operating system and target of choice.

      cd $ORT_HOME
      wget https://github.com/microsoft/onnxruntime/releases/download/v1.17.0/onnxruntime-linux-x64-gpu-1.17.0.tgz
      tar xvzf onnxruntime-linux-x64-gpu-1.17.0.tgz 
      mv onnxruntime-linux-x64-gpu-1.17.0/include .
      mv onnxruntime-linux-x64-gpu-1.17.0/lib .
      
    • Or build from source

      git clone https://github.com/microsoft/onnxruntime.git
      cd onnxruntime
      

      Create include and lib folders in the ORT_HOME directory

      mkdir $ORT_HOME/include
      mkdir $ORT_HOME/lib
      

      Build from source and copy the include and libraries into ORT_HOME

      On Windows

      build.bat --build_shared_lib --skip_tests --parallel [--use_cuda]
      copy include\onnxruntime\core\session\onnxruntime_c_api.h $ORT_HOME\include
      copy build\Windows\Debug\Debug\*.dll $ORT_HOME\lib
      

      On Linux

      ./build.sh --build_shared_lib --skip_tests --parallel [--use_cuda]
      cp include/onnxruntime/core/session/onnxruntime_c_api.h $ORT_HOME/include
      cp build/Linux/RelWithDebInfo/libonnxruntime*.so* $ORT_HOME/lib
      
  3. Build onnxruntime-genai

    If you are building for CUDA, add the cuda_home argument.

    cd ..
    python build.py [--cuda_home <path_to_cuda_home>]
    
  4. Install Python wheel

    cd build/wheel
    pip install *.whl