Rewrite all examples using standardization #6353
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "MacOS CPU ARM64 Build" | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| - rel-* | |
| pull_request: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }} | |
| cancel-in-progress: true | |
| env: | |
| ORT_NIGHTLY_REST_API: "https://feeds.dev.azure.com/aiinfra/PublicPackages/_apis/packaging/Feeds/ORT-Nightly/packages?packageNameQuery=Microsoft.ML.OnnxRuntime&api-version=6.0-preview.1" | |
| ORT_NIGHTLY_SOURCE: "https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/nuget/v3/index.json" | |
| ORT_PACKAGE_NAME: "Microsoft.ML.OnnxRuntime" | |
| jobs: | |
| mac-cpu-arm64-build: | |
| runs-on: macos-latest # arm64 | |
| steps: | |
| - name: Checkout OnnxRuntime GenAI repo | |
| uses: actions/checkout@v5 | |
| with: | |
| submodules: true | |
| - uses: microsoft/onnxruntime-github-actions/setup-build-tools@v0.0.8 | |
| with: | |
| vcpkg-version: '2025.06.13' | |
| vcpkg-hash: '735923258c5187966698f98ce0f1393b8adc6f84d44fd8829dda7db52828639331764ecf41f50c8e881e497b569f463dbd02dcb027ee9d9ede0711102de256cc' | |
| cmake-version: '3.31.8' | |
| cmake-hash: '99cc9c63ae49f21253efb5921de2ba84ce136018abf08632c92c060ba91d552e0f6acc214e9ba8123dee0cf6d1cf089ca389e321879fd9d719a60d975bcffcc8' | |
| add-cmake-to-path: 'true' | |
| disable-terrapin: 'true' | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.12.x' | |
| - name: Setup Java 17 | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: 'gradle' | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v3 | |
| with: | |
| gradle-version: '8.6' | |
| - name: Setup .NET 9.0 | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: '9.0.x' | |
| dotnet-quality: 'ga' | |
| - name: Create global.json to lock .NET SDK version | |
| run: | | |
| echo '{ | |
| "sdk": { | |
| "version": "9.0.306", | |
| "rollForward": "latestFeature" | |
| } | |
| }' > global.json | |
| cat global.json | |
| - name: Verify .NET version | |
| run: | | |
| dotnet --version | |
| dotnet --list-sdks | |
| - name: Get the Latest OnnxRuntime Nightly Version | |
| run: | | |
| ORT_NIGHTLY_VERSION=$(curl -s "${{ env.ORT_NIGHTLY_REST_API }}" | jq -r '.value[0].versions[0].normalizedVersion') | |
| echo "$ORT_NIGHTLY_VERSION" | |
| echo "ORT_NIGHTLY_VERSION=$ORT_NIGHTLY_VERSION" >> $GITHUB_ENV | |
| - name: Download OnnxRuntime Nightly | |
| run: | | |
| dotnet new console | |
| dotnet add package ${{ env.ORT_PACKAGE_NAME }} --version ${{ env.ORT_NIGHTLY_VERSION }} --source ${{ env.ORT_NIGHTLY_SOURCE }} --package-directory . | |
| - name: Extract OnnxRuntime library and header files | |
| run: | | |
| mkdir -p ort/lib | |
| mv ${{ env.ORT_PACKAGE_NAME }}/${{ env.ORT_NIGHTLY_VERSION }}/build/native/include ort/ | |
| mv ${{ env.ORT_PACKAGE_NAME }}/${{ env.ORT_NIGHTLY_VERSION }}/runtimes/osx-arm64/native/* ort/lib/ | |
| - name: Install Rust Toolchain | |
| run: | | |
| curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | |
| echo "$HOME/.cargo/bin" >> $GITHUB_PATH | |
| source "$HOME/.cargo/env" | |
| rustup install 1.86.0 | |
| rustup override set 1.86.0 | |
| rustup component add rust-src | |
| rustup show active-toolchain | |
| - name: Configure CMake | |
| run: | | |
| export MACOSX_DEPLOYMENT_TARGET=$(sw_vers -productVersion | cut -d. -f1,2) | |
| export RUSTFLAGS='-C link-arg=-Wl,-undefined,dynamic_lookup -C link-arg=-Wl,-no_dead_strip_inits_and_terms' | |
| cmake --preset macos_arm64_cpu_release | |
| - name: Build with CMake | |
| run: | | |
| export MACOSX_DEPLOYMENT_TARGET=$(sw_vers -productVersion | cut -d. -f1,2) | |
| export RUSTFLAGS='-C link-arg=-Wl,-undefined,dynamic_lookup -C link-arg=-Wl,-no_dead_strip_inits_and_terms' | |
| cmake --build --preset macos_arm64_cpu_release --parallel | |
| cmake --build --preset macos_arm64_cpu_release --target PyPackageBuild | |
| continue-on-error: false | |
| - name: Install the Python wheel and test dependencies | |
| run: | | |
| python3 -m venv genai-macos-venv | |
| source genai-macos-venv/bin/activate | |
| python3 -m pip install -r test/python/requirements.txt | |
| python3 -m pip install -r test/python/macos/torch/requirements.txt | |
| python3 -m pip install -r test/python/macos/ort/requirements.txt | |
| python3 -m pip install build/cpu/osx-arm64/wheel/onnxruntime_genai*.whl --no-deps | |
| - name: Build the Java API and Run the Java Tests | |
| run: | | |
| set -e -x | |
| source genai-macos-venv/bin/activate | |
| python3 build.py --config=Release --build_dir build/cpu/osx-arm64 --build_java --parallel --cmake_generator "Unix Makefiles" --macos MacOSX --osx_arch arm64 --apple_deploy_target 12.0 --apple_sysroot macosx | |
| - name: Remove the ort lib and header files | |
| run: | | |
| rm -rf ort | |
| - name: Verify Build Artifacts | |
| if: always() | |
| continue-on-error: true | |
| run: | | |
| ls -l ${{ github.workspace }}/build/cpu/osx-arm64 | |
| ls -l ${{ github.workspace }}/build/cpu/osx-arm64/wheel | |
| # This will also download all the test models to the test/test_models directory | |
| # These models are used by the python tests as well as C#, C++ and others. | |
| - name: Run the Python tests | |
| run: | | |
| source genai-macos-venv/bin/activate | |
| export HF_TOKEN="12345" | |
| export ORTGENAI_LOG_ORT_LIB=1 | |
| python3 -m pip install requests | |
| python3 test/python/test_onnxruntime_genai.py --cwd test/python --test_models test/test_models | |
| - name: Build the C# API and Run the C# Tests | |
| run: | | |
| export ORTGENAI_LOG_ORT_LIB=1 | |
| cd test/csharp | |
| dotnet test /p:Configuration=Release /p:NativeBuildOutputDir="../../build/cpu/osx-arm64" --verbosity normal | |
| - name: Build the C# Examples | |
| run: | | |
| export ORTGENAI_LOG_ORT_LIB=1 | |
| cd examples/csharp/ModelChat | |
| dotnet build -c Release | |
| cd ../ModelVision | |
| dotnet build -c Release | |
| cd ../HelloPhi4MM | |
| dotnet build -c Release | |
| - name: Test the C# LLM Example with Tool Calling | |
| run: | | |
| export ORTGENAI_LOG_ORT_LIB=1 | |
| python3 test/python/special_tokens.py -p test/test_models/qwen-2.5-0.5b/int4/cpu/tokenizer.json -s "<tool_call>" -e "</tool_call>" | |
| ./examples/csharp/ModelChat/bin/Release/net8.0/ModelChat -m test/test_models/qwen-2.5-0.5b/int4/cpu/ -e cpu --response_format lark_grammar --tools_file test/test_models/tool-definitions/weather.json --tool_call_start "<tool_call>" --tool_call_end "</tool_call>" --user_prompt "What is the weather in Redmond, WA?" --tool_output --non_interactive --verbose | |
| - name: Run tests | |
| run: | | |
| set -e -x | |
| export ORTGENAI_LOG_ORT_LIB=1 | |
| export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GITHUB_WORKSPACE/build/cpu/osx-arm64 | |
| ./build/cpu/osx-arm64/unit_tests | |