Skip to content

Commit

Permalink
Enable Wheel and NuGet packaging on macOS x64 & arm64 (#841)
Browse files Browse the repository at this point in the history
* Implement #693 on macOS for non-framework usage.
* Enable macOS x64 & ARM64 wheel build & packaging
* Enable macOS x64 & ARM64 NuGet build & packaging

Python validation run:
*
https://aiinfra.visualstudio.com/ONNX%20Runtime/_build/results?buildId=548627&view=results

NuGet validation run: 
*
https://aiinfra.visualstudio.com/ONNX%20Runtime/_build/results?buildId=548631&view=results
  • Loading branch information
skyline75489 authored Sep 12, 2024
1 parent b49e3b1 commit 39a0da1
Show file tree
Hide file tree
Showing 31 changed files with 410 additions and 74 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/linux-cpu-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,28 @@ jobs:
run: |
rm -rf ort
- name: Verify Build Artifacts
if: always()
continue-on-error: true
run: |
ls -l ${{ github.workspace }}/build/cpu
# 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: |
export ORTGENAI_LOG_ORT_LIB=1
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/"
- name: Verify Build Artifacts
if: always()
continue-on-error: true
run: |
ls -l ${{ github.workspace }}/build/cpu
- name: Run tests
run: |
set -e -x
export ORTGENAI_LOG_ORT_LIB=1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build/cpu/
./build/cpu/test/unit_tests
2 changes: 1 addition & 1 deletion .github/workflows/linux-gpu-x64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ jobs:
--rm \
--volume /data/ortgenai_pytorch_models:/data/ortgenai_pytorch_models \
--volume $GITHUB_WORKSPACE:/ort_genai_src \
-w /ort_genai_src onnxruntimecudabuildx64 bash -c "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/ort_genai_src/build/cuda/ /ort_genai_src/build/cuda/test/unit_tests"
-w /ort_genai_src onnxruntimecudabuildx64 bash -c "ORTGENAI_LOG_ORT_LIB=1 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/ort_genai_src/build/cuda/ /ort_genai_src/build/cuda/test/unit_tests"
44 changes: 34 additions & 10 deletions .github/workflows/mac-cpu-arm64-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
ORT_PACKAGE_NAME: "Microsoft.ML.OnnxRuntime"
jobs:
mac-cpu-arm64-build:
runs-on: macos-latest
runs-on: macos-latest # arm64
steps:
- name: Checkout OnnxRuntime GenAI repo
uses: actions/checkout@v4
Expand All @@ -36,26 +36,50 @@ jobs:
mv ${{ env.ORT_PACKAGE_NAME }}/build/native/include ort/
mv ${{ env.ORT_PACKAGE_NAME }}/runtimes/osx-arm64/native/* ort/lib/
- name: Configure CMake
run: |
cmake --preset macos_cpu_release
cmake --preset macos_arm64_cpu_release
- name: Build with CMake
run: |
cmake --build --preset macos_cpu_release --parallel
cmake --build --preset macos_arm64_cpu_release --parallel
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/requirements-macos.txt
python3 -m pip install build/cpu/osx-arm64/wheel/onnxruntime_genai*.whl --no-deps
- 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
ls -l ${{ github.workspace }}/build/cpu/osx-arm64
- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: onnxruntime-genai-mac-cpu-arm64
path: ${{ github.workspace }}/build/**/*.a
# 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 ORTGENAI_LOG_ORT_LIB=1
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"
- 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/test/unit_tests
8 changes: 8 additions & 0 deletions .pipelines/nuget-publishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ parameters:
type: boolean
default: true

- name: enable_macos_cpu
displayName: 'Whether MacOS CPU package is built.'
type: boolean
default: true

- name: ort_version
displayName: 'OnnxRuntime version'
type: string
Expand Down Expand Up @@ -83,6 +88,7 @@ stages:
enable_linux_cuda: ${{ parameters.enable_linux_cuda }}
enable_win_dml: ${{ parameters.enable_win_dml }}
enable_win_arm64: ${{ parameters.enable_win_arm64 }}
enable_macos_cpu: ${{ parameters.enable_macos_cpu }}
ort_version: ${{ parameters.ort_version }}
ort_cuda_version: ${{ parameters.ort_cuda_version }}
ort_dml_version: ${{ parameters.ort_dml_version }}
Expand All @@ -97,6 +103,7 @@ stages:
enable_linux_cuda: ${{ parameters.enable_linux_cuda }}
enable_win_dml: ${{ parameters.enable_win_dml }}
enable_win_arm64: ${{ parameters.enable_win_arm64 }}
enable_macos_cpu: ${{ parameters.enable_macos_cpu }}
ort_version: ${{ parameters.ort_version }}
ort_cuda_version: ${{ parameters.ort_cuda_version }}
ort_dml_version: ${{ parameters.ort_dml_version }}
Expand All @@ -111,6 +118,7 @@ stages:
enable_linux_cuda: ${{ parameters.enable_linux_cuda }}
enable_win_dml: ${{ parameters.enable_win_dml }}
enable_win_arm64: ${{ parameters.enable_win_arm64 }}
enable_macos_cpu: ${{ parameters.enable_macos_cpu }}
ort_version: ${{ parameters.ort_version }}
ort_cuda_version: ${{ parameters.ort_cuda_version }}
ort_dml_version: ${{ parameters.ort_dml_version }}
Expand Down
7 changes: 7 additions & 0 deletions .pipelines/pypl-publishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ parameters:
type: boolean
default: true

- name: enable_macos_cpu
displayName: 'Whether MacOS CPU package is built.'
type: boolean
default: true

- name: ort_version
displayName: 'OnnxRuntime version'
type: string
Expand Down Expand Up @@ -97,6 +102,7 @@ stages:
enable_win_cuda: ${{ parameters.enable_win_cuda }}
enable_win_dml: ${{ parameters.enable_win_dml }}
enable_win_arm64_cpu: ${{ parameters.enable_win_arm64_cpu }}
enable_macos_cpu: ${{ parameters.enable_macos_cpu }}
ort_version: ${{ parameters.ort_version }}
ort_cuda_118_version: ${{ parameters.ort_cuda_118_version }}
ort_cuda_122_version: ${{ parameters.ort_cuda_122_version }}
Expand All @@ -113,6 +119,7 @@ stages:
enable_win_cuda: ${{ parameters.enable_win_cuda }}
enable_win_dml: ${{ parameters.enable_win_dml }}
enable_win_arm64_cpu: ${{ parameters.enable_win_arm64_cpu }}
enable_macos_cpu: ${{ parameters.enable_macos_cpu }}
ort_version: ${{ parameters.ort_version }}
ort_cuda_118_version: ${{ parameters.ort_cuda_118_version }}
ort_cuda_122_version: ${{ parameters.ort_cuda_122_version }}
Expand Down
21 changes: 20 additions & 1 deletion .pipelines/stages/capi-packaging-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ parameters:
type: boolean
- name: enable_linux_cuda
type: boolean
- name: enable_macos_cpu
type: boolean
- name: ort_version
type: string
- name: ort_cuda_version
Expand Down Expand Up @@ -91,4 +93,21 @@ stages:
ep: 'cuda'
ort_version: ${{ parameters.ort_cuda_version }}
os: 'linux'
build_config: ${{ parameters.build_config }}
build_config: ${{ parameters.build_config }}

- ${{ if eq(parameters.enable_macos_cpu, true) }}:
- template: jobs/capi-packaging-job.yml
parameters:
arch: 'x64'
ep: 'cpu'
ort_version: ${{ parameters.ort_version }}
os: 'osx'
build_config: ${{ parameters.build_config }}

- template: jobs/capi-packaging-job.yml
parameters:
arch: 'arm64'
ep: 'cpu'
ort_version: ${{ parameters.ort_version }}
os: 'osx'
build_config: ${{ parameters.build_config }}
13 changes: 13 additions & 0 deletions .pipelines/stages/jobs/capi-packaging-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ parameters:
values:
- 'linux'
- 'win'
- 'osx'
- name: build_config
type: string
default: 'release'
Expand All @@ -33,6 +34,10 @@ jobs:
pool: 'onnxruntime-genai-windows-vs-2022-arm64'
${{ else }}:
pool: 'onnxruntime-Win-CPU-2022'
${{ if eq(parameters.os, 'osx') }}:
pool:
vmImage: 'macOS-latest'

timeoutInMinutes: 180
# set variables here to be used in the template and steps
variables:
Expand Down Expand Up @@ -130,4 +135,12 @@ jobs:
ep: ${{ parameters.ep }}
build_config: ${{ parameters.build_config }}

- ${{ if eq(parameters.os, 'osx') }}:
- template: steps/capi-macos-step.yml
parameters:
target: 'onnxruntime-genai'
arch: ${{ parameters.arch }}
ep: ${{ parameters.ep }}
build_config: ${{ parameters.build_config }}

- template: steps/compliant-and-cleanup-step.yml
17 changes: 17 additions & 0 deletions .pipelines/stages/jobs/nuget-packaging-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ parameters:
type: boolean
default: false

- name: enable_macos_cpu
displayName: 'Whether MacOS CPU package is built.'
type: boolean
default: false

- name: ort_version
type: string

Expand Down Expand Up @@ -130,6 +135,18 @@ jobs:
ArtifactName: onnxruntime-genai-linux-cuda-x64-capi
TargetPath: '$(Build.BinariesDirectory)/artifact-downloads'

- ${{ if eq(parameters.enable_macos_cpu, true) }}:
- template: steps/utils/flex-download-pipeline-artifact.yml
parameters:
StepName: 'Download osx-cpu-x64 capi Artifacts'
ArtifactName: onnxruntime-genai-osx-cpu-x64-capi
TargetPath: '$(Build.BinariesDirectory)/artifact-downloads'
- template: steps/utils/flex-download-pipeline-artifact.yml
parameters:
StepName: 'Download osx-cpu-arm64 capi Artifacts'
ArtifactName: onnxruntime-genai-osx-cpu-arm64-capi
TargetPath: '$(Build.BinariesDirectory)/artifact-downloads'

- checkout: self
path: onnxruntime-genai
clean: true
Expand Down
7 changes: 6 additions & 1 deletion .pipelines/stages/jobs/nuget-validation-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ parameters:
values:
- 'linux'
- 'win'
- 'osx'

jobs:
- job: nuget_${{ parameters.os }}_${{ parameters.ep }}_${{ parameters.arch }}_validation
Expand All @@ -43,6 +44,9 @@ jobs:
pool: 'onnxruntime-genai-windows-vs-2022-arm64'
${{ else }}:
pool: 'onnxruntime-Win-CPU-2022'
${{ if eq(parameters.os, 'osx') }}:
pool:
vmImage: 'macOS-latest'

timeoutInMinutes: 180
# set variables here to be used in the template and steps
Expand Down Expand Up @@ -158,14 +162,15 @@ jobs:
env:
NUGET_PLUGIN_HANDSHAKE_TIMEOUT_IN_SECONDS: 180
NUGET_PLUGIN_REQUEST_TIMEOUT_IN_SECONDS: 180
- ${{ elseif eq(parameters.os, 'linux') }}:
- ${{ elseif or(eq(parameters.os, 'linux'), eq(parameters.os, 'osx')) }}:
- bash: |
dotnet --info
cp $(Build.BinariesDirectory)/nuget/* examples/csharp/HelloPhi/
cd examples/csharp/HelloPhi
mv models/$(prebuild_phi3_mini_model_folder) models/phi-3
dotnet restore -r $(os)-$(arch) /property:Configuration=$(csproj_configuration) --source https://api.nuget.org/v3/index.json --source https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/nuget/v3/index.json --source $PWD --disable-parallel --verbosity detailed
dotnet build ./HelloPhi.csproj -r $(os)-$(arch) /property:Configuration=$(csproj_configuration) --no-restore --self-contained
ls -l ./bin/$(csproj_configuration)/net6.0/$(os)-$(arch)/
displayName: 'Perform dotnet restore & build'
workingDirectory: '$(Build.Repository.LocalPath)'
env:
Expand Down
16 changes: 15 additions & 1 deletion .pipelines/stages/jobs/py-packaging-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ parameters:
values:
- 'linux'
- 'win'
- 'osx'
- name: build_config
type: string
default: 'release'
Expand All @@ -37,9 +38,12 @@ jobs:
pool: 'onnxruntime-genai-windows-vs-2022-arm64'
${{ else }}:
pool: 'onnxruntime-Win-CPU-2022'
${{ if eq(parameters.os, 'osx') }}:
pool:
vmImage: 'macOS-latest'

strategy:
${{ if eq(parameters.arch, 'arm64') }}:
${{ if and(eq(parameters.os, 'win'), eq(parameters.arch, 'arm64')) }}: # Older Python versions don't have official win-arm64 build.
matrix:
Python311:
PyDotVer: '3.11'
Expand Down Expand Up @@ -73,6 +77,8 @@ jobs:
- name: skipComponentGovernanceDetection
${{ if eq(parameters.os, 'linux') }}:
value: true
${{ if eq(parameters.os, 'osx') }}:
value: true
${{ if eq(parameters.os, 'win') }}:
value: false
- name: arch
Expand Down Expand Up @@ -179,5 +185,13 @@ jobs:
ep: ${{ parameters.ep }}
build_config: ${{ parameters.build_config }}

- ${{ if eq(parameters.os, 'osx') }}:
- template: steps/capi-macos-step.yml
parameters:
target: 'python'
arch: ${{ parameters.arch }}
ep: ${{ parameters.ep }}
build_config: ${{ parameters.build_config }}

- template: steps/compliant-and-cleanup-step.yml

Loading

0 comments on commit 39a0da1

Please sign in to comment.