From b769831e4c2627f6d8c11f6e0cdaf3e09a4cabe6 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:42:12 +0800 Subject: [PATCH 01/55] Init --- .pipelines/pypl-publishing.yml | 6 + .pipelines/stages/jobs/py-packaging-job.yml | 4 + .../stages/jobs/steps/capi-macos-job.yml | 133 ++++++++++++++++++ .pipelines/stages/py-packaging-stage.yml | 19 ++- cmake/presets/CMakeMacOSBuildPresets.json | 8 +- cmake/presets/CMakeMacOSConfigPresets.json | 24 +++- 6 files changed, 188 insertions(+), 6 deletions(-) create mode 100644 .pipelines/stages/jobs/steps/capi-macos-job.yml diff --git a/.pipelines/pypl-publishing.yml b/.pipelines/pypl-publishing.yml index 6ecbc938e..144238045 100644 --- a/.pipelines/pypl-publishing.yml +++ b/.pipelines/pypl-publishing.yml @@ -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 @@ -90,6 +95,7 @@ trigger: none stages: - template: stages/py-packaging-stage.yml parameters: + enable_macos_cpu: ${{ parameters.enable_macos_cpu }} enable_linux_cpu: ${{ parameters.enable_linux_cpu }} enable_linux_cuda: ${{ parameters.enable_linux_cuda }} enable_linux_rocm: ${{ parameters.enable_linux_rocm }} diff --git a/.pipelines/stages/jobs/py-packaging-job.yml b/.pipelines/stages/jobs/py-packaging-job.yml index 99582c9f1..889138d4b 100644 --- a/.pipelines/stages/jobs/py-packaging-job.yml +++ b/.pipelines/stages/jobs/py-packaging-job.yml @@ -37,6 +37,8 @@ jobs: pool: 'onnxruntime-genai-windows-vs-2022-arm64' ${{ else }}: pool: 'onnxruntime-Win-CPU-2022' + ${{ if eq(parameters.os, 'osx')}}: + pool: 'macOS-latest' strategy: ${{ if eq(parameters.arch, 'arm64') }}: @@ -73,6 +75,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 diff --git a/.pipelines/stages/jobs/steps/capi-macos-job.yml b/.pipelines/stages/jobs/steps/capi-macos-job.yml new file mode 100644 index 000000000..bf174e2ca --- /dev/null +++ b/.pipelines/stages/jobs/steps/capi-macos-job.yml @@ -0,0 +1,133 @@ +parameters: +- name: target + type: string +- name: ep + type: string + default: 'cpu' +- name: arch + type: string + default: 'x64' +- name: build_config + type: string + default: 'release' + +steps: + +- checkout: self + clean: true + path: onnxruntime-genai + submodules: recursive + +- checkout: manylinux + clean: true + path: onnxruntime-genai/manylinux + submodules: recursive + +- script: | + set -e -x + echo "$(Build.SourcesDirectory)" + echo "$(Build.Repository.LocalPath)" + ls $(Build.SourcesDirectory) -R + displayName: 'List files from SourceDirectory' + +- template: utils/set-nightly-build-option-variable.yml + +- bash: | + echo "arch=$(arch)" + echo "ort_filename=$(ort_filename)" + echo "ort_version=$(ort_version)" + echo "ep=$(ep)" + echo "cuda_version=$(cuda_version)" + echo "target=${{ parameters.target }}" + echo "build_config=${{ parameters.build_config }}" + displayName: 'Print Parameters' + +- template: utils/download-ort.yml + parameters: + archiveType: 'tgz' + +- powershell: | + cmake --preset macos_$(arch)_$(ep)_$(build_config) + displayName: 'Configure CMake C API' + workingDirectory: '$(Build.Repository.LocalPath)' + +- powershell: | + cmake --build --preset macos_$(arch)_$(ep)_$(build_config) --parallel --target ${{ parameters.target }} + displayName: 'Build C API' + workingDirectory: '$(Build.Repository.LocalPath)' + +- ${{ if eq(parameters.target, 'onnxruntime-genai') }}: + - template: compliant/win-esrp-dll-step.yml + parameters: + FolderPath: '$(Build.Repository.LocalPath)\$(buildDir)' + DisplayName: 'ESRP - Sign C++ dlls' + Pattern: '*genai.dll' + + - task: BinSkim@4 + displayName: 'Run BinSkim' + inputs: + AnalyzeTargetGlob: '$(Build.Repository.LocalPath)\**\*genai.dll' + continueOnError: true + + - powershell: | + python -m pip install wheel + displayName: 'Install wheel' + + - powershell: | + cmake --build --preset macos_$(arch)_$(ep)_$(build_config) --target package + displayName: 'Package C/C++ API' + workingDirectory: '$(Build.Repository.LocalPath)' + + - task: PublishBuildArtifacts@1 + displayName: 'Publish Artifact: ONNXRuntime Genai capi' + inputs: + ArtifactName: $(artifactName)-capi + PathtoPublish: '$(Build.Repository.LocalPath)\build\$(ep)\$(os)-$(arch)\package' + +- ${{ if eq(parameters.target, 'python') }}: + - task: BinSkim@4 + displayName: 'Run BinSkim' + inputs: + AnalyzeTargetGlob: '$(Build.Repository.LocalPath)\**\*.pyd' + continueOnError: true + + - template: compliant/win-esrp-dll-step.yml + parameters: + FolderPath: '$(Build.Repository.LocalPath)\build\$(ep)\$(os)-$(arch)\wheel\onnxruntime_genai' + DisplayName: 'ESRP - PYD Sign' + DoEsrp: true + Pattern: '*.pyd' + + - powershell: | + python -m pip install wheel + displayName: 'Install wheel' + + - powershell: | + cmake --build --preset macos_$(arch)_$(ep)_$(build_config) --parallel --PyPackageBuild + displayName: 'Build Python Wheel' + + - powershell: | + Get-ChildItem -Path $(Build.Repository.LocalPath) -Recurse + displayName: 'List all files in the repo for debugging' + + - task: CopyFiles@2 + displayName: 'Copy Python Wheel to: $(Build.ArtifactStagingDirectory)' + inputs: + SourceFolder: '$(Build.Repository.LocalPath)\build\$(ep)\$(os)-$(arch)\wheel' + Contents: '*.whl' + TargetFolder: '$(Build.ArtifactStagingDirectory)\wheel' + + - task: PublishBuildArtifacts@1 + displayName: 'Publish Artifact: ONNXRuntime python wheel' + inputs: + ArtifactName: $(artifactName)-wheel + PathtoPublish: '$(Build.ArtifactStagingDirectory)\wheel' + + - task: PublishSymbols@2 + displayName: 'Publish Build Symbols' + condition: and(succeeded(), eq(variables['build_config'], 'relwithdebinfo')) + inputs: + SymbolsFolder: '$(Build.Repository.LocalPath)\build\$(ep)\$(os)-$(arch)\src\python\RelWithDebInfo\' + SearchPattern: 'onnxruntime_genai.pdb' + SymbolServerType: teamServices + SymbolExpirationInDays: 365 diff --git a/.pipelines/stages/py-packaging-stage.yml b/.pipelines/stages/py-packaging-stage.yml index d43868ed0..d7bab62c8 100644 --- a/.pipelines/stages/py-packaging-stage.yml +++ b/.pipelines/stages/py-packaging-stage.yml @@ -13,6 +13,8 @@ parameters: type: boolean - name: enable_linux_rocm type: boolean +- name: enable_macos_cpu + type: boolean - name: ort_version type: string - name: ort_cuda_118_version @@ -121,5 +123,18 @@ stages: ort_version: ${{ parameters.ort_rocm_version }} os: 'linux' build_config: ${{ parameters.build_config }} - - + - ${{ if eq(parameters.enable_macos_cpu, true) }}: + - template: jobs/py-packaging-job.yml + parameters: + arch: 'x64' + ep: 'cpu' + ort_version: ${{ parameters.ort_version }} + os: 'osx' + build_config: ${{ parameters.build_config }} + - template: jobs/py-packaging-job.yml + parameters: + arch: 'arm64' + ep: 'cpu' + ort_version: ${{ parameters.ort_version }} + os: 'osx' + build_config: ${{ parameters.build_config }} diff --git a/cmake/presets/CMakeMacOSBuildPresets.json b/cmake/presets/CMakeMacOSBuildPresets.json index e27635e9c..d3634c3d2 100644 --- a/cmake/presets/CMakeMacOSBuildPresets.json +++ b/cmake/presets/CMakeMacOSBuildPresets.json @@ -5,8 +5,12 @@ ], "buildPresets": [ { - "name": "macos_cpu_release", - "configurePreset": "macos_cpu_release" + "name": "macos_x64_cpu_release", + "configurePreset": "macos_x64_cpu_release" + }, + { + "name": "macos_arm64_cpu_release", + "configurePreset": "macos_arm64_cpu_release" }, { "name": "macos_cpu_debug", diff --git a/cmake/presets/CMakeMacOSConfigPresets.json b/cmake/presets/CMakeMacOSConfigPresets.json index a425dc595..54e891d1b 100644 --- a/cmake/presets/CMakeMacOSConfigPresets.json +++ b/cmake/presets/CMakeMacOSConfigPresets.json @@ -4,13 +4,13 @@ "CMakeLinuxDefaultConfigPresets.json" ], "configurePresets": [ - { + { "name": "macos_default", "generator": "Unix Makefiles", "binaryDir": "${sourceDir}/build/cpu", + "architecture": "arm64", "cacheVariables": { "CMAKE_POSITION_INDEPENDENT_CODE": "ON", - "CMAKE_OSX_ARCHITECTURES": "arm64", "USE_CUDA": "OFF", "USE_ROCM": "OFF" }, @@ -87,6 +87,26 @@ "macos_default", "macos_minsizerel_default" ] + }, + { + "name": "macos_x64_cpu_release", + "inherits": [ + "macos_release_default", + "macos_default" + ], + "architecture": "x64", + "displayName": "macos x64 cpu release", + "binaryDir": "${sourceDir}/build/cpu/osx-x64" + }, + { + "name": "macos_arm64_cpu_release", + "inherits": [ + "macos_release_default", + "macos_default" + ], + "architecture": "arm64", + "displayName": "macos x64 cpu release", + "binaryDir": "${sourceDir}/build/cpu/osx-x64" } ] } \ No newline at end of file From 34e98f9772761562b018796f987c36c3293c5e2e Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:44:00 +0800 Subject: [PATCH 02/55] choice --- .pipelines/stages/jobs/py-packaging-job.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pipelines/stages/jobs/py-packaging-job.yml b/.pipelines/stages/jobs/py-packaging-job.yml index 889138d4b..1175e2799 100644 --- a/.pipelines/stages/jobs/py-packaging-job.yml +++ b/.pipelines/stages/jobs/py-packaging-job.yml @@ -16,6 +16,7 @@ parameters: values: - 'linux' - 'win' + - 'osx' - name: build_config type: string default: 'release' From 1d1447d692dba59873a2c06af8c682b7fb8f05c2 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:44:50 +0800 Subject: [PATCH 03/55] Fix --- .pipelines/stages/jobs/py-packaging-job.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.pipelines/stages/jobs/py-packaging-job.yml b/.pipelines/stages/jobs/py-packaging-job.yml index 1175e2799..ddd30a3b1 100644 --- a/.pipelines/stages/jobs/py-packaging-job.yml +++ b/.pipelines/stages/jobs/py-packaging-job.yml @@ -184,5 +184,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 From b70a9771a3d209c455cb6946e1573509bc96972f Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:45:52 +0800 Subject: [PATCH 04/55] Rename --- .../stages/jobs/steps/{capi-macos-job.yml => capi-macos-step.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .pipelines/stages/jobs/steps/{capi-macos-job.yml => capi-macos-step.yml} (100%) diff --git a/.pipelines/stages/jobs/steps/capi-macos-job.yml b/.pipelines/stages/jobs/steps/capi-macos-step.yml similarity index 100% rename from .pipelines/stages/jobs/steps/capi-macos-job.yml rename to .pipelines/stages/jobs/steps/capi-macos-step.yml From 14fe5b5fe96c11b55d40247b6c7d1a54dcc3876c Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:48:16 +0800 Subject: [PATCH 05/55] Pool --- .pipelines/stages/jobs/py-packaging-job.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pipelines/stages/jobs/py-packaging-job.yml b/.pipelines/stages/jobs/py-packaging-job.yml index ddd30a3b1..35db3c372 100644 --- a/.pipelines/stages/jobs/py-packaging-job.yml +++ b/.pipelines/stages/jobs/py-packaging-job.yml @@ -39,7 +39,8 @@ jobs: ${{ else }}: pool: 'onnxruntime-Win-CPU-2022' ${{ if eq(parameters.os, 'osx')}}: - pool: 'macOS-latest' + pool: + vmImage: 'macOS-latest' strategy: ${{ if eq(parameters.arch, 'arm64') }}: From a5af4e3ced0fd949de313029948f3e55770affc3 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:52:21 +0800 Subject: [PATCH 06/55] Well... --- .pipelines/stages/jobs/steps/capi-macos-step.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.pipelines/stages/jobs/steps/capi-macos-step.yml b/.pipelines/stages/jobs/steps/capi-macos-step.yml index bf174e2ca..b19157227 100644 --- a/.pipelines/stages/jobs/steps/capi-macos-step.yml +++ b/.pipelines/stages/jobs/steps/capi-macos-step.yml @@ -23,13 +23,6 @@ steps: path: onnxruntime-genai/manylinux submodules: recursive -- script: | - set -e -x - echo "$(Build.SourcesDirectory)" - echo "$(Build.Repository.LocalPath)" - ls $(Build.SourcesDirectory) -R - displayName: 'List files from SourceDirectory' - - template: utils/set-nightly-build-option-variable.yml - bash: | From 21aad541288c14be8fabfa76f9f9c1f305f62fe9 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:59:24 +0800 Subject: [PATCH 07/55] zip --- .pipelines/stages/jobs/steps/capi-macos-step.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pipelines/stages/jobs/steps/capi-macos-step.yml b/.pipelines/stages/jobs/steps/capi-macos-step.yml index b19157227..706760f5d 100644 --- a/.pipelines/stages/jobs/steps/capi-macos-step.yml +++ b/.pipelines/stages/jobs/steps/capi-macos-step.yml @@ -37,7 +37,7 @@ steps: - template: utils/download-ort.yml parameters: - archiveType: 'tgz' + archiveType: 'zip' - powershell: | cmake --preset macos_$(arch)_$(ep)_$(build_config) From dbfe071c50f6af8cda52e9b3c9aedec3ae052b1b Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:11:50 +0800 Subject: [PATCH 08/55] arch --- cmake/presets/CMakeMacOSConfigPresets.json | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cmake/presets/CMakeMacOSConfigPresets.json b/cmake/presets/CMakeMacOSConfigPresets.json index 54e891d1b..16b1e70ad 100644 --- a/cmake/presets/CMakeMacOSConfigPresets.json +++ b/cmake/presets/CMakeMacOSConfigPresets.json @@ -8,7 +8,6 @@ "name": "macos_default", "generator": "Unix Makefiles", "binaryDir": "${sourceDir}/build/cpu", - "architecture": "arm64", "cacheVariables": { "CMAKE_POSITION_INDEPENDENT_CODE": "ON", "USE_CUDA": "OFF", @@ -91,22 +90,24 @@ { "name": "macos_x64_cpu_release", "inherits": [ - "macos_release_default", - "macos_default" + "macos_cpu_release" ], - "architecture": "x64", + "cacheVariables": { + "CMAKE_OSX_ARCHITECTURES": "x64" + }, "displayName": "macos x64 cpu release", "binaryDir": "${sourceDir}/build/cpu/osx-x64" }, { "name": "macos_arm64_cpu_release", "inherits": [ - "macos_release_default", - "macos_default" + "macos_cpu_release" ], - "architecture": "arm64", + "cacheVariables": { + "CMAKE_OSX_ARCHITECTURES": "arm64" + }, "displayName": "macos x64 cpu release", - "binaryDir": "${sourceDir}/build/cpu/osx-x64" + "binaryDir": "${sourceDir}/build/cpu/osx-arm64" } ] } \ No newline at end of file From da8894ace84e14322110977982f45a8b89a47f17 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:22:38 +0800 Subject: [PATCH 09/55] x86_64 --- cmake/presets/CMakeMacOSConfigPresets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/presets/CMakeMacOSConfigPresets.json b/cmake/presets/CMakeMacOSConfigPresets.json index 16b1e70ad..5b337464a 100644 --- a/cmake/presets/CMakeMacOSConfigPresets.json +++ b/cmake/presets/CMakeMacOSConfigPresets.json @@ -93,7 +93,7 @@ "macos_cpu_release" ], "cacheVariables": { - "CMAKE_OSX_ARCHITECTURES": "x64" + "CMAKE_OSX_ARCHITECTURES": "x86_64" }, "displayName": "macos x64 cpu release", "binaryDir": "${sourceDir}/build/cpu/osx-x64" From 1c4690f0a122d02250ccde6e70535147c2bfcce9 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:38:18 +0800 Subject: [PATCH 10/55] Working dir --- .pipelines/stages/jobs/steps/capi-macos-step.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.pipelines/stages/jobs/steps/capi-macos-step.yml b/.pipelines/stages/jobs/steps/capi-macos-step.yml index 706760f5d..16bdda3af 100644 --- a/.pipelines/stages/jobs/steps/capi-macos-step.yml +++ b/.pipelines/stages/jobs/steps/capi-macos-step.yml @@ -98,10 +98,12 @@ steps: - powershell: | cmake --build --preset macos_$(arch)_$(ep)_$(build_config) --parallel --PyPackageBuild displayName: 'Build Python Wheel' + workingDirectory: '$(Build.Repository.LocalPath)' - powershell: | Get-ChildItem -Path $(Build.Repository.LocalPath) -Recurse displayName: 'List all files in the repo for debugging' + workingDirectory: '$(Build.Repository.LocalPath)' - task: CopyFiles@2 displayName: 'Copy Python Wheel to: $(Build.ArtifactStagingDirectory)' @@ -115,12 +117,3 @@ steps: inputs: ArtifactName: $(artifactName)-wheel PathtoPublish: '$(Build.ArtifactStagingDirectory)\wheel' - - - task: PublishSymbols@2 - displayName: 'Publish Build Symbols' - condition: and(succeeded(), eq(variables['build_config'], 'relwithdebinfo')) - inputs: - SymbolsFolder: '$(Build.Repository.LocalPath)\build\$(ep)\$(os)-$(arch)\src\python\RelWithDebInfo\' - SearchPattern: 'onnxruntime_genai.pdb' - SymbolServerType: teamServices - SymbolExpirationInDays: 365 From 1122debeb230a27475296d00d389f868c878f794 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:52:34 +0800 Subject: [PATCH 11/55] Slash --- .pipelines/stages/jobs/steps/capi-macos-step.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pipelines/stages/jobs/steps/capi-macos-step.yml b/.pipelines/stages/jobs/steps/capi-macos-step.yml index 16bdda3af..dc1294720 100644 --- a/.pipelines/stages/jobs/steps/capi-macos-step.yml +++ b/.pipelines/stages/jobs/steps/capi-macos-step.yml @@ -108,12 +108,12 @@ steps: - task: CopyFiles@2 displayName: 'Copy Python Wheel to: $(Build.ArtifactStagingDirectory)' inputs: - SourceFolder: '$(Build.Repository.LocalPath)\build\$(ep)\$(os)-$(arch)\wheel' + SourceFolder: '$(Build.Repository.LocalPath)/build/$(ep)/$(os)-$(arch)/wheel' Contents: '*.whl' - TargetFolder: '$(Build.ArtifactStagingDirectory)\wheel' + TargetFolder: '$(Build.ArtifactStagingDirectory)/wheel' - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: ONNXRuntime python wheel' inputs: ArtifactName: $(artifactName)-wheel - PathtoPublish: '$(Build.ArtifactStagingDirectory)\wheel' + PathtoPublish: '$(Build.ArtifactStagingDirectory)/wheel' From 41ea7999e38fcebd36b4aa7e1f65abf986102034 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:53:47 +0800 Subject: [PATCH 12/55] Unused --- .pipelines/stages/jobs/steps/capi-macos-step.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.pipelines/stages/jobs/steps/capi-macos-step.yml b/.pipelines/stages/jobs/steps/capi-macos-step.yml index dc1294720..7096ff504 100644 --- a/.pipelines/stages/jobs/steps/capi-macos-step.yml +++ b/.pipelines/stages/jobs/steps/capi-macos-step.yml @@ -18,11 +18,6 @@ steps: path: onnxruntime-genai submodules: recursive -- checkout: manylinux - clean: true - path: onnxruntime-genai/manylinux - submodules: recursive - - template: utils/set-nightly-build-option-variable.yml - bash: | From e9093c6bbe702aec1d201664b73ebad30c3bff82 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 19:52:48 +0800 Subject: [PATCH 13/55] python wheel host platform --- .pipelines/stages/jobs/steps/capi-macos-step.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.pipelines/stages/jobs/steps/capi-macos-step.yml b/.pipelines/stages/jobs/steps/capi-macos-step.yml index 7096ff504..48e0b47e2 100644 --- a/.pipelines/stages/jobs/steps/capi-macos-step.yml +++ b/.pipelines/stages/jobs/steps/capi-macos-step.yml @@ -91,6 +91,15 @@ steps: displayName: 'Install wheel' - powershell: | + # From: https://github.com/pypa/cibuildwheel/blob/93542c397cfe940bcbb8f1eff5c37d345ea16653/cibuildwheel/macos.py#L247-L260 + if ("$(arch)" -eq "arm64") { + $env:_PYTHON_HOST_PLATFORM = "macosx-12.0-arm64" + $env:ARCHFLAGS = "-arch arm64" + } + else { + $env:_PYTHON_HOST_PLATFORM = "macosx-12.0-x86_64" + $env:ARCHFLAGS = "-arch x86_64" + } cmake --build --preset macos_$(arch)_$(ep)_$(build_config) --parallel --PyPackageBuild displayName: 'Build Python Wheel' workingDirectory: '$(Build.Repository.LocalPath)' From 8672a21eadb312d062c1cf6665dff1a39b830e77 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 19:54:10 +0800 Subject: [PATCH 14/55] deployment target --- .pipelines/stages/jobs/steps/capi-macos-step.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pipelines/stages/jobs/steps/capi-macos-step.yml b/.pipelines/stages/jobs/steps/capi-macos-step.yml index 48e0b47e2..37f3df454 100644 --- a/.pipelines/stages/jobs/steps/capi-macos-step.yml +++ b/.pipelines/stages/jobs/steps/capi-macos-step.yml @@ -35,6 +35,7 @@ steps: archiveType: 'zip' - powershell: | + $env:MACOSX_DEPLOYMENT_TARGET = "12.0" # Monterey cmake --preset macos_$(arch)_$(ep)_$(build_config) displayName: 'Configure CMake C API' workingDirectory: '$(Build.Repository.LocalPath)' From c7233339311c7a8f83f0d37e60415d8c5596def4 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 20:00:19 +0800 Subject: [PATCH 15/55] package.cmake --- cmake/package.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/package.cmake b/cmake/package.cmake index 87ad79345..5939b1078 100644 --- a/cmake/package.cmake +++ b/cmake/package.cmake @@ -47,7 +47,11 @@ elseif (LINUX) set(CPACK_PACKAGE_FILE_NAME "onnxruntime-genai-${VERSION_INFO}-linux-arm64") endif () elseif (APPLE) - set(CPACK_PACKAGE_FILE_NAME "onnxruntime-genai-${VERSION_INFO}-osx-arm64") + if (CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64") + set(CPACK_PACKAGE_FILE_NAME "onnxruntime-genai-${VERSION_INFO}-osx-x64") + else () + set(CPACK_PACKAGE_FILE_NAME "onnxruntime-genai-${VERSION_INFO}-osx-arm64") + endif() endif () if (WIN32) From 18c906cb04465bba2fa5d22616bcd161bf406a23 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 20 Aug 2024 20:14:45 +0800 Subject: [PATCH 16/55] matrix --- .pipelines/stages/jobs/py-packaging-job.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pipelines/stages/jobs/py-packaging-job.yml b/.pipelines/stages/jobs/py-packaging-job.yml index 35db3c372..100e2bae4 100644 --- a/.pipelines/stages/jobs/py-packaging-job.yml +++ b/.pipelines/stages/jobs/py-packaging-job.yml @@ -43,7 +43,7 @@ jobs: 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' From 44b5aa3ffc1bc02878f884591cfe7058fe579718 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Wed, 21 Aug 2024 08:30:45 +0800 Subject: [PATCH 17/55] Guardian not available on macOS --- .../stages/jobs/steps/capi-macos-step.yml | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/.pipelines/stages/jobs/steps/capi-macos-step.yml b/.pipelines/stages/jobs/steps/capi-macos-step.yml index 37f3df454..59a518c1e 100644 --- a/.pipelines/stages/jobs/steps/capi-macos-step.yml +++ b/.pipelines/stages/jobs/steps/capi-macos-step.yml @@ -46,18 +46,6 @@ steps: workingDirectory: '$(Build.Repository.LocalPath)' - ${{ if eq(parameters.target, 'onnxruntime-genai') }}: - - template: compliant/win-esrp-dll-step.yml - parameters: - FolderPath: '$(Build.Repository.LocalPath)\$(buildDir)' - DisplayName: 'ESRP - Sign C++ dlls' - Pattern: '*genai.dll' - - - task: BinSkim@4 - displayName: 'Run BinSkim' - inputs: - AnalyzeTargetGlob: '$(Build.Repository.LocalPath)\**\*genai.dll' - continueOnError: true - - powershell: | python -m pip install wheel displayName: 'Install wheel' @@ -74,19 +62,6 @@ steps: PathtoPublish: '$(Build.Repository.LocalPath)\build\$(ep)\$(os)-$(arch)\package' - ${{ if eq(parameters.target, 'python') }}: - - task: BinSkim@4 - displayName: 'Run BinSkim' - inputs: - AnalyzeTargetGlob: '$(Build.Repository.LocalPath)\**\*.pyd' - continueOnError: true - - - template: compliant/win-esrp-dll-step.yml - parameters: - FolderPath: '$(Build.Repository.LocalPath)\build\$(ep)\$(os)-$(arch)\wheel\onnxruntime_genai' - DisplayName: 'ESRP - PYD Sign' - DoEsrp: true - Pattern: '*.pyd' - - powershell: | python -m pip install wheel displayName: 'Install wheel' From 5065c668f91bc41be8adb2c5f393c3ec6a36f855 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:07:19 +0800 Subject: [PATCH 18/55] CredScan not available on macOS --- .pipelines/stages/jobs/steps/compliant-and-cleanup-step.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pipelines/stages/jobs/steps/compliant-and-cleanup-step.yml b/.pipelines/stages/jobs/steps/compliant-and-cleanup-step.yml index aa2f7b547..19ee48dcc 100644 --- a/.pipelines/stages/jobs/steps/compliant-and-cleanup-step.yml +++ b/.pipelines/stages/jobs/steps/compliant-and-cleanup-step.yml @@ -4,6 +4,7 @@ steps: inputs: debugMode: false continueOnError: true + condition: ne(variables['os'], 'osx') # Not available on macOS. See https://eng.ms/docs/products/credential-risk-exposure-defense/solutions/credscan_client/overview - task: TSAUpload@2 displayName: 'TSA upload' From ac5635efedbe1320e4cf6f64e3a16cffe4a537ec Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:50:47 +0800 Subject: [PATCH 19/55] macOS nuget --- .pipelines/nuget-publishing.yml | 6 ++++++ .pipelines/stages/capi-packaging-stage.yml | 21 ++++++++++++++++++- .pipelines/stages/jobs/capi-packaging-job.yml | 8 +++++++ .../stages/jobs/nuget-packaging-job.yml | 17 +++++++++++++++ .pipelines/stages/nuget-packaging-stage.yml | 3 ++- 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/.pipelines/nuget-publishing.yml b/.pipelines/nuget-publishing.yml index 137e2c36f..7784cfefb 100644 --- a/.pipelines/nuget-publishing.yml +++ b/.pipelines/nuget-publishing.yml @@ -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 @@ -97,6 +102,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 }} diff --git a/.pipelines/stages/capi-packaging-stage.yml b/.pipelines/stages/capi-packaging-stage.yml index 1b9021a72..2da3971a8 100644 --- a/.pipelines/stages/capi-packaging-stage.yml +++ b/.pipelines/stages/capi-packaging-stage.yml @@ -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 @@ -91,4 +93,21 @@ stages: ep: 'cuda' ort_version: ${{ parameters.ort_cuda_version }} os: 'linux' - build_config: ${{ parameters.build_config }} \ No newline at end of file + 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 }} diff --git a/.pipelines/stages/jobs/capi-packaging-job.yml b/.pipelines/stages/jobs/capi-packaging-job.yml index 1d936eccb..e73563c57 100644 --- a/.pipelines/stages/jobs/capi-packaging-job.yml +++ b/.pipelines/stages/jobs/capi-packaging-job.yml @@ -130,4 +130,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 diff --git a/.pipelines/stages/jobs/nuget-packaging-job.yml b/.pipelines/stages/jobs/nuget-packaging-job.yml index e01374b9e..a52f5bc21 100644 --- a/.pipelines/stages/jobs/nuget-packaging-job.yml +++ b/.pipelines/stages/jobs/nuget-packaging-job.yml @@ -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 @@ -130,6 +135,18 @@ jobs: ArtifactName: onnxruntime-genai-linux-cuda-x64-capi TargetPath: '$(Build.BinariesDirectory)/artifact-downloads' + - ${{ if and(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 diff --git a/.pipelines/stages/nuget-packaging-stage.yml b/.pipelines/stages/nuget-packaging-stage.yml index 4137b29bd..9ad43ae5b 100644 --- a/.pipelines/stages/nuget-packaging-stage.yml +++ b/.pipelines/stages/nuget-packaging-stage.yml @@ -42,7 +42,7 @@ parameters: stages: - stage: nuget_packaging jobs: - - ${{ if or(eq(parameters.enable_linux_cpu, true), eq(parameters.enable_win_cpu, true)) }}: + - ${{ if or(eq(parameters.enable_linux_cpu, true), eq(parameters.enable_win_cpu, true), eq(parameters.enable_macos_cpu, true)) }}: - template: jobs/nuget-packaging-job.yml parameters: ep: 'cpu' @@ -51,6 +51,7 @@ stages: enable_linux_cpu: ${{ parameters.enable_linux_cpu }} enable_win_cpu: ${{ parameters.enable_win_cpu }} enable_win_arm64: ${{ parameters.enable_win_arm64 }} + enable_macos_cpu: ${{ parameters.enable_macos_cpu }} - ${{ if or(eq(parameters.enable_linux_cuda, true), eq(parameters.enable_win_cuda, true)) }}: - template: jobs/nuget-packaging-job.yml parameters: From 3831ffa86b941265da6617893992d126b1374dae Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:53:15 +0800 Subject: [PATCH 20/55] parameter --- .pipelines/nuget-publishing.yml | 1 + cmake/presets/CMakeMacOSConfigPresets.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.pipelines/nuget-publishing.yml b/.pipelines/nuget-publishing.yml index 7784cfefb..f6eb7320a 100644 --- a/.pipelines/nuget-publishing.yml +++ b/.pipelines/nuget-publishing.yml @@ -88,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 }} diff --git a/cmake/presets/CMakeMacOSConfigPresets.json b/cmake/presets/CMakeMacOSConfigPresets.json index 5b337464a..7de4f39a9 100644 --- a/cmake/presets/CMakeMacOSConfigPresets.json +++ b/cmake/presets/CMakeMacOSConfigPresets.json @@ -106,7 +106,7 @@ "cacheVariables": { "CMAKE_OSX_ARCHITECTURES": "arm64" }, - "displayName": "macos x64 cpu release", + "displayName": "macos arm64 cpu release", "binaryDir": "${sourceDir}/build/cpu/osx-arm64" } ] From 980f74f066edbb141073d2287f940f001713ce94 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:55:10 +0800 Subject: [PATCH 21/55] parameter value --- .pipelines/stages/jobs/capi-packaging-job.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pipelines/stages/jobs/capi-packaging-job.yml b/.pipelines/stages/jobs/capi-packaging-job.yml index e73563c57..8d16ae826 100644 --- a/.pipelines/stages/jobs/capi-packaging-job.yml +++ b/.pipelines/stages/jobs/capi-packaging-job.yml @@ -13,6 +13,7 @@ parameters: values: - 'linux' - 'win' + - 'osx' - name: build_config type: string default: 'release' From cb0a7a0a1f19ab44659a4580f1e2209a4695d9dc Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:57:07 +0800 Subject: [PATCH 22/55] parameter --- .pipelines/stages/nuget-packaging-stage.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.pipelines/stages/nuget-packaging-stage.yml b/.pipelines/stages/nuget-packaging-stage.yml index 9ad43ae5b..00ad62dd2 100644 --- a/.pipelines/stages/nuget-packaging-stage.yml +++ b/.pipelines/stages/nuget-packaging-stage.yml @@ -29,6 +29,11 @@ parameters: type: boolean default: true +- name: enable_macos_cpu + displayName: 'Whether MacOS CPU package is built.' + type: boolean + default: true + - name: ort_version type: string - name: ort_cuda_version From 75c3d4103b04095ab3bf9b9acb120d0b64d2625c Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:59:29 +0800 Subject: [PATCH 23/55] condition --- .pipelines/stages/jobs/nuget-packaging-job.yml | 2 +- .pipelines/stages/jobs/py-packaging-job.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pipelines/stages/jobs/nuget-packaging-job.yml b/.pipelines/stages/jobs/nuget-packaging-job.yml index a52f5bc21..8599ee207 100644 --- a/.pipelines/stages/jobs/nuget-packaging-job.yml +++ b/.pipelines/stages/jobs/nuget-packaging-job.yml @@ -135,7 +135,7 @@ jobs: ArtifactName: onnxruntime-genai-linux-cuda-x64-capi TargetPath: '$(Build.BinariesDirectory)/artifact-downloads' - - ${{ if and(eq(parameters.enable_macos_cpu, true)) }}: + - ${{ if eq(parameters.enable_macos_cpu, true) }}: - template: steps/utils/flex-download-pipeline-artifact.yml parameters: StepName: 'Download osx-cpu-x64 capi Artifacts' diff --git a/.pipelines/stages/jobs/py-packaging-job.yml b/.pipelines/stages/jobs/py-packaging-job.yml index 100e2bae4..db39b9afb 100644 --- a/.pipelines/stages/jobs/py-packaging-job.yml +++ b/.pipelines/stages/jobs/py-packaging-job.yml @@ -38,7 +38,7 @@ jobs: pool: 'onnxruntime-genai-windows-vs-2022-arm64' ${{ else }}: pool: 'onnxruntime-Win-CPU-2022' - ${{ if eq(parameters.os, 'osx')}}: + ${{ if eq(parameters.os, 'osx') }}: pool: vmImage: 'macOS-latest' From 035d610a316f2a2fe6775cd1364a5a90bef000df Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:03:21 +0800 Subject: [PATCH 24/55] pool --- .pipelines/stages/jobs/capi-packaging-job.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pipelines/stages/jobs/capi-packaging-job.yml b/.pipelines/stages/jobs/capi-packaging-job.yml index 8d16ae826..aa9e9efa4 100644 --- a/.pipelines/stages/jobs/capi-packaging-job.yml +++ b/.pipelines/stages/jobs/capi-packaging-job.yml @@ -34,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: From fb867dcc1c400ca3f79b47989578ed305d7797cb Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:17:03 +0800 Subject: [PATCH 25/55] publish --- .pipelines/stages/jobs/steps/capi-macos-step.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pipelines/stages/jobs/steps/capi-macos-step.yml b/.pipelines/stages/jobs/steps/capi-macos-step.yml index 59a518c1e..73818fdaf 100644 --- a/.pipelines/stages/jobs/steps/capi-macos-step.yml +++ b/.pipelines/stages/jobs/steps/capi-macos-step.yml @@ -59,7 +59,7 @@ steps: displayName: 'Publish Artifact: ONNXRuntime Genai capi' inputs: ArtifactName: $(artifactName)-capi - PathtoPublish: '$(Build.Repository.LocalPath)\build\$(ep)\$(os)-$(arch)\package' + PathtoPublish: '$(Build.Repository.LocalPath)/build/$(ep)/$(os)-$(arch)/package' - ${{ if eq(parameters.target, 'python') }}: - powershell: | From 23b9b98e2483b0064d9b44908ca7b74a2cc4c5c4 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:49:32 +0800 Subject: [PATCH 26/55] nuget --- .../stages/jobs/nuget-validation-job.yml | 5 +++- .pipelines/stages/jobs/py-validation-job.yml | 28 ++++++++----------- .../stages/jobs/steps/capi-linux-step.yml | 2 +- examples/csharp/HelloPhi/HelloPhi.csproj | 6 ++-- .../nuget/generate_nuspec_for_native_nuget.py | 4 ++- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/.pipelines/stages/jobs/nuget-validation-job.yml b/.pipelines/stages/jobs/nuget-validation-job.yml index e382a3ca7..8be1872ae 100644 --- a/.pipelines/stages/jobs/nuget-validation-job.yml +++ b/.pipelines/stages/jobs/nuget-validation-job.yml @@ -43,6 +43,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 @@ -158,7 +161,7 @@ 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/ diff --git a/.pipelines/stages/jobs/py-validation-job.yml b/.pipelines/stages/jobs/py-validation-job.yml index 6e3bd6625..0e452531e 100644 --- a/.pipelines/stages/jobs/py-validation-job.yml +++ b/.pipelines/stages/jobs/py-validation-job.yml @@ -46,6 +46,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: 240 workspace: @@ -147,22 +150,13 @@ jobs: addToPath: true architecture: $(arch) - - ${{ if eq(parameters.os, 'linux') }}: - - template: steps/utils/flex-download-pipeline-artifact.yml - parameters: - StepName: 'Download Python Wheel Artifacts' - ArtifactName: $(ArtifactName) - TargetPath: '$(Build.BinariesDirectory)/wheel' - SpecificArtifact: ${{ parameters.specificArtifact }} - BuildId: ${{ parameters.BuildId }} - - ${{ if eq(parameters.os, 'win') }}: - - template: steps/utils/flex-download-pipeline-artifact.yml - parameters: - StepName: 'Download Python Wheel Artifacts' - ArtifactName: $(ArtifactName)-wheel - TargetPath: '$(Build.BinariesDirectory)/wheel' - SpecificArtifact: ${{ parameters.specificArtifact }} - BuildId: ${{ parameters.BuildId }} + - template: steps/utils/flex-download-pipeline-artifact.yml + parameters: + StepName: 'Download Python Wheel Artifacts' + ArtifactName: $(ArtifactName)-wheel + TargetPath: '$(Build.BinariesDirectory)/wheel' + SpecificArtifact: ${{ parameters.specificArtifact }} + BuildId: ${{ parameters.BuildId }} - template: steps/utils/download-huggingface-model.yml parameters: @@ -174,7 +168,7 @@ jobs: HuggingFaceToken: $(HF_TOKEN) os: ${{ parameters.os }} - - ${{ if eq(parameters.os, 'linux') }}: + - ${{ if or(eq(parameters.os, 'linux'), eq(parameters.os, 'osx')) }}: - ${{ if eq(parameters.ep, 'cuda') }}: - bash: | set -e -x diff --git a/.pipelines/stages/jobs/steps/capi-linux-step.yml b/.pipelines/stages/jobs/steps/capi-linux-step.yml index c3074f607..de7e5ae6c 100644 --- a/.pipelines/stages/jobs/steps/capi-linux-step.yml +++ b/.pipelines/stages/jobs/steps/capi-linux-step.yml @@ -169,7 +169,7 @@ steps: - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: ONNXRuntime python wheel' inputs: - ArtifactName: $(artifactName) + ArtifactName: $(artifactName)-wheel PathtoPublish: '$(Build.ArtifactStagingDirectory)/wheel' - script: | diff --git a/examples/csharp/HelloPhi/HelloPhi.csproj b/examples/csharp/HelloPhi/HelloPhi.csproj index 083a2d89e..e6f288cc6 100644 --- a/examples/csharp/HelloPhi/HelloPhi.csproj +++ b/examples/csharp/HelloPhi/HelloPhi.csproj @@ -9,9 +9,9 @@ - - - + + + diff --git a/tools/nuget/generate_nuspec_for_native_nuget.py b/tools/nuget/generate_nuspec_for_native_nuget.py index 5ea725e17..1d4686e80 100644 --- a/tools/nuget/generate_nuspec_for_native_nuget.py +++ b/tools/nuget/generate_nuspec_for_native_nuget.py @@ -122,7 +122,7 @@ def add_native_artifact_if_exists(xml_lines, runtime, artifact): f'' ) - runtimes = ["win-x64", "win-arm64", "linux-x64"] + runtimes = ["win-x64", "win-arm64", "linux-x64", "osx-x64", "osx-arm64"] for runtime in runtimes: if runtime.startswith("win"): add_native_artifact_if_exists(lines, runtime, "onnxruntime-genai.lib") @@ -130,6 +130,8 @@ def add_native_artifact_if_exists(xml_lines, runtime, artifact): add_native_artifact_if_exists(lines, runtime, "d3d12core.dll") if runtime.startswith("linux"): add_native_artifact_if_exists(lines, runtime, "libonnxruntime-genai.so") + if runtime.startswith("osx"): + add_native_artifact_if_exists(lines, runtime, "libonnxruntime-genai.dylib") # targets for dotnet in ["netstandard2.0", "net8.0", "native"]: From e632c1e50344d0d5ef151e26a1b3e8ad8e00e2eb Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:51:02 +0800 Subject: [PATCH 27/55] syntax --- tools/nuget/generate_nuspec_for_native_nuget.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/nuget/generate_nuspec_for_native_nuget.py b/tools/nuget/generate_nuspec_for_native_nuget.py index 1d4686e80..ba464add6 100644 --- a/tools/nuget/generate_nuspec_for_native_nuget.py +++ b/tools/nuget/generate_nuspec_for_native_nuget.py @@ -131,7 +131,7 @@ def add_native_artifact_if_exists(xml_lines, runtime, artifact): if runtime.startswith("linux"): add_native_artifact_if_exists(lines, runtime, "libonnxruntime-genai.so") if runtime.startswith("osx"): - add_native_artifact_if_exists(lines, runtime, "libonnxruntime-genai.dylib") + add_native_artifact_if_exists(lines, runtime, "libonnxruntime-genai.dylib") # targets for dotnet in ["netstandard2.0", "net8.0", "native"]: From cfe1948fd3b2ddea94e009604a20abd5d7ec0f06 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:57:06 +0800 Subject: [PATCH 28/55] validation pipeline --- .pipelines/nuget-publishing.yml | 1 + .pipelines/pypl-publishing.yml | 3 ++- .pipelines/stages/nuget-validation-stage.yml | 12 ++++++++++++ .pipelines/stages/py-validation-stage.yml | 12 ++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.pipelines/nuget-publishing.yml b/.pipelines/nuget-publishing.yml index f6eb7320a..726493826 100644 --- a/.pipelines/nuget-publishing.yml +++ b/.pipelines/nuget-publishing.yml @@ -118,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 }} diff --git a/.pipelines/pypl-publishing.yml b/.pipelines/pypl-publishing.yml index 144238045..099679cc3 100644 --- a/.pipelines/pypl-publishing.yml +++ b/.pipelines/pypl-publishing.yml @@ -95,7 +95,6 @@ trigger: none stages: - template: stages/py-packaging-stage.yml parameters: - enable_macos_cpu: ${{ parameters.enable_macos_cpu }} enable_linux_cpu: ${{ parameters.enable_linux_cpu }} enable_linux_cuda: ${{ parameters.enable_linux_cuda }} enable_linux_rocm: ${{ parameters.enable_linux_rocm }} @@ -103,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 }} @@ -119,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 }} diff --git a/.pipelines/stages/nuget-validation-stage.yml b/.pipelines/stages/nuget-validation-stage.yml index 380fda54b..b5bf85a88 100644 --- a/.pipelines/stages/nuget-validation-stage.yml +++ b/.pipelines/stages/nuget-validation-stage.yml @@ -19,6 +19,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 @@ -104,3 +106,13 @@ stages: os: 'linux' SpecificArtifact: ${{ parameters.SpecificArtifact }} BuildId: ${{ parameters.BuildId }} + + - ${{ if eq(parameters.enable_macos_cpu, true) }}: + - template: jobs/nuget-validation-job.yml + parameters: + arch: 'arm64' + ep: 'cpu' + ort_version: ${{ parameters.ort_version }} + os: 'osx' + SpecificArtifact: ${{ parameters.SpecificArtifact }} + BuildId: ${{ parameters.BuildId }} \ No newline at end of file diff --git a/.pipelines/stages/py-validation-stage.yml b/.pipelines/stages/py-validation-stage.yml index d619c3acb..5a51174be 100644 --- a/.pipelines/stages/py-validation-stage.yml +++ b/.pipelines/stages/py-validation-stage.yml @@ -19,6 +19,8 @@ parameters: type: boolean - name: enable_linux_cuda type: boolean +- name: enable_macos_cpu + type: boolean - name: ort_version type: string - name: ort_cuda_118_version @@ -123,3 +125,13 @@ stages: os: 'linux' SpecificArtifact: ${{ parameters.SpecificArtifact }} BuildId: ${{ parameters.BuildId }} + + - ${{ if eq(parameters.enable_macos_cpu, true) }}: + - template: jobs/py-validation-job.yml + parameters: + arch: 'arm64' + ep: 'cpu' + ort_version: ${{ parameters.ort_version }} + os: 'osx' + SpecificArtifact: ${{ parameters.SpecificArtifact }} + BuildId: ${{ parameters.BuildId }} \ No newline at end of file From 80459fdd5e3651deadaf7a3dab427049fb377dcd Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:00:34 +0800 Subject: [PATCH 29/55] validation pipeline --- .pipelines/stages/jobs/nuget-validation-job.yml | 1 + .pipelines/stages/jobs/py-validation-job.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.pipelines/stages/jobs/nuget-validation-job.yml b/.pipelines/stages/jobs/nuget-validation-job.yml index 8be1872ae..e8c01bc5f 100644 --- a/.pipelines/stages/jobs/nuget-validation-job.yml +++ b/.pipelines/stages/jobs/nuget-validation-job.yml @@ -21,6 +21,7 @@ parameters: values: - 'linux' - 'win' + - 'osx' jobs: - job: nuget_${{ parameters.os }}_${{ parameters.ep }}_${{ parameters.arch }}_validation diff --git a/.pipelines/stages/jobs/py-validation-job.yml b/.pipelines/stages/jobs/py-validation-job.yml index 0e452531e..bbd19f3de 100644 --- a/.pipelines/stages/jobs/py-validation-job.yml +++ b/.pipelines/stages/jobs/py-validation-job.yml @@ -24,6 +24,7 @@ parameters: values: - 'linux' - 'win' + - 'osx' jobs: - job: python_${{ parameters.os }}_${{ parameters.ep }}${{ parameters.cuda_display_version }}_${{ parameters.arch }}_validation From 140d60cfee9fd17dd1f97b3c387abdf4ab8c6265 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:52:09 +0800 Subject: [PATCH 30/55] It's all x64 mac --- .pipelines/stages/nuget-validation-stage.yml | 2 +- .pipelines/stages/py-validation-stage.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pipelines/stages/nuget-validation-stage.yml b/.pipelines/stages/nuget-validation-stage.yml index b5bf85a88..d8c8b3ca4 100644 --- a/.pipelines/stages/nuget-validation-stage.yml +++ b/.pipelines/stages/nuget-validation-stage.yml @@ -110,7 +110,7 @@ stages: - ${{ if eq(parameters.enable_macos_cpu, true) }}: - template: jobs/nuget-validation-job.yml parameters: - arch: 'arm64' + arch: 'x64' ep: 'cpu' ort_version: ${{ parameters.ort_version }} os: 'osx' diff --git a/.pipelines/stages/py-validation-stage.yml b/.pipelines/stages/py-validation-stage.yml index 5a51174be..0b6abda5a 100644 --- a/.pipelines/stages/py-validation-stage.yml +++ b/.pipelines/stages/py-validation-stage.yml @@ -129,7 +129,7 @@ stages: - ${{ if eq(parameters.enable_macos_cpu, true) }}: - template: jobs/py-validation-job.yml parameters: - arch: 'arm64' + arch: 'x64' ep: 'cpu' ort_version: ${{ parameters.ort_version }} os: 'osx' From 32802f487d138693379b86e4112048c647134934 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:39:56 +0800 Subject: [PATCH 31/55] debugging --- .pipelines/stages/jobs/nuget-validation-job.yml | 2 ++ .../stages/jobs/steps/utils/download-huggingface-model.yml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.pipelines/stages/jobs/nuget-validation-job.yml b/.pipelines/stages/jobs/nuget-validation-job.yml index e8c01bc5f..a45bb3441 100644 --- a/.pipelines/stages/jobs/nuget-validation-job.yml +++ b/.pipelines/stages/jobs/nuget-validation-job.yml @@ -170,6 +170,7 @@ jobs: 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)/HelloPhi displayName: 'Perform dotnet restore & build' workingDirectory: '$(Build.Repository.LocalPath)' env: @@ -202,6 +203,7 @@ jobs: - ${{ elseif eq(parameters.ep, 'cpu') }}: - bash: | export ORTGENAI_LOG_ORT_LIB=1 + export DYLD_PRINT_LIBRARIES=1 cd examples/csharp/HelloPhi dotnet run -r $(os)-$(arch) --configuration $(csproj_configuration) --no-build --verbosity normal -- -m ./models/phi-3 displayName: 'Run Example With Artifact' diff --git a/.pipelines/stages/jobs/steps/utils/download-huggingface-model.yml b/.pipelines/stages/jobs/steps/utils/download-huggingface-model.yml index 30014e6ff..0dc5a8fc1 100644 --- a/.pipelines/stages/jobs/steps/utils/download-huggingface-model.yml +++ b/.pipelines/stages/jobs/steps/utils/download-huggingface-model.yml @@ -15,7 +15,7 @@ parameters: type: string steps: - - ${{ if eq(parameters.os, 'linux') }}: + - ${{ if or(eq(parameters.os, 'linux'), eq(parameters.os, 'osx')) }}: - bash: | python -m pip install "huggingface_hub[cli]" huggingface-cli login --token $HF_TOKEN From 04f14234fdfb18086c4c85fe4f5bd26e2fc8de4a Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:04:59 +0800 Subject: [PATCH 32/55] dlopen on mac --- .../stages/jobs/nuget-validation-job.yml | 2 +- CMakeLists.txt | 2 +- src/models/onnxruntime_api.h | 21 ++++++++++++++----- src/python/CMakeLists.txt | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.pipelines/stages/jobs/nuget-validation-job.yml b/.pipelines/stages/jobs/nuget-validation-job.yml index a45bb3441..7eaabd786 100644 --- a/.pipelines/stages/jobs/nuget-validation-job.yml +++ b/.pipelines/stages/jobs/nuget-validation-job.yml @@ -170,7 +170,7 @@ jobs: 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)/HelloPhi + ls -l ./bin/$(csproj_configuration)/net6.0/$(os)-$(arch)/ displayName: 'Perform dotnet restore & build' workingDirectory: '$(Build.Repository.LocalPath)' env: diff --git a/CMakeLists.txt b/CMakeLists.txt index 06d196d7b..b9c341f4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,7 @@ target_link_directories(onnxruntime-genai PRIVATE ${ORT_LIB_DIR}) # we keep the shared libraries disconnected on Android as they will come from separate AARs and we don't want to force # the ORT version to match in both. -if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux")) +if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")) target_link_libraries(onnxruntime-genai PRIVATE ${ONNXRUNTIME_LIB}) endif() diff --git a/src/models/onnxruntime_api.h b/src/models/onnxruntime_api.h index ddc617f79..36a1bd3ef 100644 --- a/src/models/onnxruntime_api.h +++ b/src/models/onnxruntime_api.h @@ -89,6 +89,12 @@ p_session_->Run(nullptr, input_names, inputs, std::size(inputs), output_names, o #elif defined(__linux__) #include +#elif defined(__APPLE__) +#include "TargetConditionals.h" + #if TARGET_OS_MAC + #include + #endif +#endif #ifndef PATH_MAX #define PATH_MAX (4096) @@ -103,7 +109,6 @@ p_session_->Run(nullptr, input_names, inputs, std::size(inputs), output_names, o #define LOG_ERROR(...) LOG_WHEN_ENABLED(Generators::Log("error", __VA_ARGS__)) #define LOG_FATAL(...) LOG_WHEN_ENABLED(Generators::Log("fatal", __VA_ARGS__)) -#endif /** \brief Free functions and a few helpers are defined inside this namespace. Otherwise all types are the C API types * @@ -115,7 +120,7 @@ using OrtApiBaseFn = const OrtApiBase* (*)(void); /// Before using this C++ wrapper API, you MUST call Ort::InitApi to set the below 'api' variable inline const OrtApi* api{}; -#if defined(__linux__) +#if defined(__linux__) || defined(TARGET_OS_MAC) inline std::string GetCurrentModuleDir() { Dl_info dl_info; dladdr((void*)GetCurrentModuleDir, &dl_info); @@ -142,7 +147,7 @@ inline void* LoadDynamicLibraryIfExists(const std::string& path) { ort_lib_handle = dlopen(local_path.c_str(), RTLD_NOW | RTLD_LOCAL); } if (ort_lib_handle) { -#if !defined(__ANDROID__) // RTLD_DI_ORIGIN not available on Android +#if !defined(__ANDROID__) && !defined(TARGET_OS_MAC) // RTLD_DI_ORIGIN not available on Android/Darwin char pathname[PATH_MAX]; dlinfo((void*)ort_lib_handle, RTLD_DI_ORIGIN, &pathname); LOG_INFO("Loaded native library at %s", pathname); @@ -196,7 +201,7 @@ inline void InitApi() { Generators::SetLogBool("ort_lib", true); } -#if defined(__linux__) +#if defined(__linux__) || defined(TARGET_OS_MAC) // If the GenAI library links against the onnxruntime library, it will have a dependency on a specific // version of OrtGetApiBase. // @@ -218,14 +223,20 @@ inline void InitApi() { // any libonnxruntime.so that supports one of those versions. // +#if defined(__linux__) const std::string path = "libonnxruntime.so"; // "libonnxruntime4j_jni.so" is also an option if we have issues void* ort_lib_handle = LoadDynamicLibraryIfExists(path); - #if !defined(__ANDROID__) if (ort_lib_handle == nullptr) { ort_lib_handle = LoadDynamicLibraryIfExists("libonnxruntime.so.1"); } #endif +#endif + +#if defined(TARGET_OS_MAC) + const std::string path = "libonnxruntime.dylib"; + void* ort_lib_handle = LoadDynamicLibraryIfExists(path); +#endif if (ort_lib_handle == nullptr) { throw std::runtime_error(std::string("Failed to load onnxruntime. Set ORTGENAI_LOG_ORT_LIB envvar to enable detailed logging.")); diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 6472fe3a8..94e5b985b 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -9,7 +9,7 @@ target_include_directories(python PRIVATE ${ORT_HEADER_DIR}) target_link_directories(python PRIVATE ${ORT_LIB_DIR}) target_link_libraries(python PRIVATE onnxruntime-genai-static) -if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux")) +if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")) target_link_libraries(python PRIVATE ${ONNXRUNTIME_LIB}) endif() From 74238e7189ecfe22744d0d8c68f5df98aa6cca1f Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:45:05 +0800 Subject: [PATCH 33/55] dlopen on mac --- .pipelines/stages/jobs/nuget-validation-job.yml | 1 - src/models/onnxruntime_api.h | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.pipelines/stages/jobs/nuget-validation-job.yml b/.pipelines/stages/jobs/nuget-validation-job.yml index 7eaabd786..c5498e12e 100644 --- a/.pipelines/stages/jobs/nuget-validation-job.yml +++ b/.pipelines/stages/jobs/nuget-validation-job.yml @@ -203,7 +203,6 @@ jobs: - ${{ elseif eq(parameters.ep, 'cpu') }}: - bash: | export ORTGENAI_LOG_ORT_LIB=1 - export DYLD_PRINT_LIBRARIES=1 cd examples/csharp/HelloPhi dotnet run -r $(os)-$(arch) --configuration $(csproj_configuration) --no-build --verbosity normal -- -m ./models/phi-3 displayName: 'Run Example With Artifact' diff --git a/src/models/onnxruntime_api.h b/src/models/onnxruntime_api.h index 36a1bd3ef..df130a037 100644 --- a/src/models/onnxruntime_api.h +++ b/src/models/onnxruntime_api.h @@ -75,10 +75,11 @@ p_session_->Run(nullptr, input_names, inputs, std::size(inputs), output_names, o #include "../logging.h" #include "env_utils.h" -#if defined(__ANDROID__) -#include +#if defined(__linux__) #include +#if defined(__ANDROID__) +#include #define TAG "GenAI" #define LOG_DEBUG(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) @@ -86,9 +87,8 @@ p_session_->Run(nullptr, input_names, inputs, std::size(inputs), output_names, o #define LOG_WARN(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__) #define LOG_ERROR(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__) #define LOG_FATAL(...) __android_log_print(ANDROID_LOG_FATAL, TAG, __VA_ARGS__) +#endif -#elif defined(__linux__) -#include #elif defined(__APPLE__) #include "TargetConditionals.h" #if TARGET_OS_MAC From 0d7ec643b462ab9a3ee32e81a36506862d3aa791 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:46:44 +0800 Subject: [PATCH 34/55] min_length --- examples/csharp/HelloPhi/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/csharp/HelloPhi/Program.cs b/examples/csharp/HelloPhi/Program.cs index 82576c1ad..26e20a353 100644 --- a/examples/csharp/HelloPhi/Program.cs +++ b/examples/csharp/HelloPhi/Program.cs @@ -76,6 +76,7 @@ void PrintUsage() var sequences = tokenizer.Encode($"<|user|>{prompt}<|end|><|assistant|>"); using GeneratorParams generatorParams = new GeneratorParams(model); + generatorParams.SetSearchOption("min_length", 50); generatorParams.SetSearchOption("max_length", 200); generatorParams.SetInputSequences(sequences); if (option == 1) // Complete Output From 1e2947c19239962e088c2beebd2d3c3a2eb78e96 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:22:33 +0800 Subject: [PATCH 35/55] Clean up --- .github/workflows/mac-cpu-arm64-build.yml | 4 ++-- src/models/onnxruntime_api.h | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/mac-cpu-arm64-build.yml b/.github/workflows/mac-cpu-arm64-build.yml index 9f861a96d..5726b77f0 100644 --- a/.github/workflows/mac-cpu-arm64-build.yml +++ b/.github/workflows/mac-cpu-arm64-build.yml @@ -39,11 +39,11 @@ jobs: - 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: Verify Build Artifacts diff --git a/src/models/onnxruntime_api.h b/src/models/onnxruntime_api.h index df130a037..d55b90563 100644 --- a/src/models/onnxruntime_api.h +++ b/src/models/onnxruntime_api.h @@ -91,9 +91,9 @@ p_session_->Run(nullptr, input_names, inputs, std::size(inputs), output_names, o #elif defined(__APPLE__) #include "TargetConditionals.h" - #if TARGET_OS_MAC - #include - #endif +#if TARGET_OS_OSX +#include +#endif #endif #ifndef PATH_MAX @@ -120,7 +120,7 @@ using OrtApiBaseFn = const OrtApiBase* (*)(void); /// Before using this C++ wrapper API, you MUST call Ort::InitApi to set the below 'api' variable inline const OrtApi* api{}; -#if defined(__linux__) || defined(TARGET_OS_MAC) +#if defined(__linux__) || TARGET_OS_OSX inline std::string GetCurrentModuleDir() { Dl_info dl_info; dladdr((void*)GetCurrentModuleDir, &dl_info); @@ -147,7 +147,7 @@ inline void* LoadDynamicLibraryIfExists(const std::string& path) { ort_lib_handle = dlopen(local_path.c_str(), RTLD_NOW | RTLD_LOCAL); } if (ort_lib_handle) { -#if !defined(__ANDROID__) && !defined(TARGET_OS_MAC) // RTLD_DI_ORIGIN not available on Android/Darwin +#if !defined(__ANDROID__) && !defined(__APPLE__) // RTLD_DI_ORIGIN not available on Android & Darwin char pathname[PATH_MAX]; dlinfo((void*)ort_lib_handle, RTLD_DI_ORIGIN, &pathname); LOG_INFO("Loaded native library at %s", pathname); @@ -201,7 +201,7 @@ inline void InitApi() { Generators::SetLogBool("ort_lib", true); } -#if defined(__linux__) || defined(TARGET_OS_MAC) +#if defined(__linux__) || TARGET_OS_OSX // If the GenAI library links against the onnxruntime library, it will have a dependency on a specific // version of OrtGetApiBase. // @@ -226,6 +226,7 @@ inline void InitApi() { #if defined(__linux__) const std::string path = "libonnxruntime.so"; // "libonnxruntime4j_jni.so" is also an option if we have issues void* ort_lib_handle = LoadDynamicLibraryIfExists(path); + #if !defined(__ANDROID__) if (ort_lib_handle == nullptr) { ort_lib_handle = LoadDynamicLibraryIfExists("libonnxruntime.so.1"); @@ -233,7 +234,7 @@ inline void InitApi() { #endif #endif -#if defined(TARGET_OS_MAC) +#if TARGET_OS_OSX const std::string path = "libonnxruntime.dylib"; void* ort_lib_handle = LoadDynamicLibraryIfExists(path); #endif @@ -249,11 +250,11 @@ inline void InitApi() { } InitApiWithDynamicFn(ort_api_base_fn); -#else // defined(__linux__) +#else // defined(__linux__) || TARGET_OS_OSX api = OrtGetApiBase()->GetApi(ORT_API_VERSION); if (!api) throw std::runtime_error("Onnxruntime is installed but is too old, please install a newer version"); -#endif // defined(__linux__) +#endif // defined(__linux__) || TARGET_OS_OSX } /** \brief All C++ methods that can fail will throw an exception of this type From f6ade1904d3ea3a784af9aa6690810b1307a594f Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:37:30 +0800 Subject: [PATCH 36/55] macos arm64 test on GHA --- .github/workflows/mac-cpu-arm64-build.yml | 34 +++++++++++++++++++++-- src/models/onnxruntime_api.h | 1 - 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.github/workflows/mac-cpu-arm64-build.yml b/.github/workflows/mac-cpu-arm64-build.yml index 5726b77f0..d855cfc46 100644 --- a/.github/workflows/mac-cpu-arm64-build.yml +++ b/.github/workflows/mac-cpu-arm64-build.yml @@ -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 @@ -36,7 +36,6 @@ 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_arm64_cpu_release @@ -46,11 +45,40 @@ jobs: cmake --build --preset macos_arm64_cpu_release --parallel continue-on-error: false + - name: Install the python wheel and test dependencies + run: | + python3 -m pip install -r test/python/requirements.txt --user + python3 -m pip install -r test/python/requirements-cpu.txt --user + python3 -m pip install build/cpu/wheel/onnxruntime_genai*.whl --user + + - name: Get HuggingFace Token + run: | + az login --identity --username 63b63039-6328-442f-954b-5a64d124e5b4 + HF_TOKEN=$(az keyvault secret show --vault-name anubissvcsecret --name ANUBIS-HUGGINGFACE-TOKEN --query value) + echo "::add-mask::$HF_TOKEN" + echo "HF_TOKEN=$HF_TOKEN" >> $GITHUB_ENV + + - name: Remove the ort lib and header files + run: | + rm -rf ort + + # 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: | + python3 test/python/test_onnxruntime_genai.py --cwd test/python --test_models test/test_models + - name: Verify Build Artifacts if: always() continue-on-error: true run: | - ls -l ${{ github.workspace }}/build + ls -l ${{ github.workspace }}/build/cpu + + - name: Run tests + run: | + set -e -x + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build/cpu/ + ./build/cpu/osx-arm64/test/unit_tests - name: Upload Build Artifacts uses: actions/upload-artifact@v3 diff --git a/src/models/onnxruntime_api.h b/src/models/onnxruntime_api.h index d55b90563..af8f40bd3 100644 --- a/src/models/onnxruntime_api.h +++ b/src/models/onnxruntime_api.h @@ -109,7 +109,6 @@ p_session_->Run(nullptr, input_names, inputs, std::size(inputs), output_names, o #define LOG_ERROR(...) LOG_WHEN_ENABLED(Generators::Log("error", __VA_ARGS__)) #define LOG_FATAL(...) LOG_WHEN_ENABLED(Generators::Log("fatal", __VA_ARGS__)) - /** \brief Free functions and a few helpers are defined inside this namespace. Otherwise all types are the C API types * */ From 4e6f31d1bc08ecd056e25edf0b450f2d9a2e346c Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:55:19 +0800 Subject: [PATCH 37/55] Try fix macos arm64 test on GHA --- .github/workflows/mac-cpu-arm64-build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/mac-cpu-arm64-build.yml b/.github/workflows/mac-cpu-arm64-build.yml index d855cfc46..799940ea1 100644 --- a/.github/workflows/mac-cpu-arm64-build.yml +++ b/.github/workflows/mac-cpu-arm64-build.yml @@ -47,6 +47,8 @@ jobs: - 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 --user python3 -m pip install -r test/python/requirements-cpu.txt --user python3 -m pip install build/cpu/wheel/onnxruntime_genai*.whl --user @@ -77,7 +79,7 @@ jobs: - name: Run tests run: | set -e -x - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build/cpu/ + export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GITHUB_WORKSPACE/build/cpu/osx-arm64 ./build/cpu/osx-arm64/test/unit_tests - name: Upload Build Artifacts From eaeace80f884fe27060f62dd52bb9134ae2a1657 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:07:56 +0800 Subject: [PATCH 38/55] User site-packages are not visible in this virtualenv --- .github/workflows/mac-cpu-arm64-build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/mac-cpu-arm64-build.yml b/.github/workflows/mac-cpu-arm64-build.yml index 799940ea1..3be378bfe 100644 --- a/.github/workflows/mac-cpu-arm64-build.yml +++ b/.github/workflows/mac-cpu-arm64-build.yml @@ -49,9 +49,9 @@ jobs: run: | python3 -m venv genai-macos-venv source genai-macos-venv/bin/activate - python3 -m pip install -r test/python/requirements.txt --user - python3 -m pip install -r test/python/requirements-cpu.txt --user - python3 -m pip install build/cpu/wheel/onnxruntime_genai*.whl --user + python3 -m pip install -r test/python/requirements.txt + python3 -m pip install -r test/python/requirements-cpu.txt + python3 -m pip install build/cpu/wheel/onnxruntime_genai*.whl - name: Get HuggingFace Token run: | From 425a3afab7fca1f26b89b750fe334864fb212406 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:24:28 +0800 Subject: [PATCH 39/55] requirements-macos.txt --- .github/workflows/mac-cpu-arm64-build.yml | 2 +- test/python/requirements-macos.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/python/requirements-macos.txt diff --git a/.github/workflows/mac-cpu-arm64-build.yml b/.github/workflows/mac-cpu-arm64-build.yml index 3be378bfe..b0cd3171b 100644 --- a/.github/workflows/mac-cpu-arm64-build.yml +++ b/.github/workflows/mac-cpu-arm64-build.yml @@ -50,7 +50,7 @@ jobs: 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-cpu.txt + python3 -m pip install -r test/python/requirements-macos.txt python3 -m pip install build/cpu/wheel/onnxruntime_genai*.whl - name: Get HuggingFace Token diff --git a/test/python/requirements-macos.txt b/test/python/requirements-macos.txt new file mode 100644 index 000000000..83d4b7e6d --- /dev/null +++ b/test/python/requirements-macos.txt @@ -0,0 +1,4 @@ +-f https://download.pytorch.org/whl/torch_stable.html +-i https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ +torch==2.2.1 +ort-nightly==1.20.0.dev20240805004 From 4e9f2fe0db591f39489ba4ce783071c7dcf548f2 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:53:54 +0800 Subject: [PATCH 40/55] Pip --- .github/workflows/mac-cpu-arm64-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mac-cpu-arm64-build.yml b/.github/workflows/mac-cpu-arm64-build.yml index b0cd3171b..0f4429d82 100644 --- a/.github/workflows/mac-cpu-arm64-build.yml +++ b/.github/workflows/mac-cpu-arm64-build.yml @@ -51,7 +51,7 @@ jobs: 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/wheel/onnxruntime_genai*.whl + python3 -m pip install build/cpu/osx-arm64/wheel/onnxruntime_genai*.whl - name: Get HuggingFace Token run: | @@ -74,7 +74,7 @@ jobs: if: always() continue-on-error: true run: | - ls -l ${{ github.workspace }}/build/cpu + ls -l ${{ github.workspace }}/build/cpu/osx-arm64 - name: Run tests run: | From 5760c7d05abfda4477afd1015e8cf3acc43787b1 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:11:11 +0800 Subject: [PATCH 41/55] Unused --- .github/workflows/mac-cpu-arm64-build.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/mac-cpu-arm64-build.yml b/.github/workflows/mac-cpu-arm64-build.yml index 0f4429d82..d0b24a052 100644 --- a/.github/workflows/mac-cpu-arm64-build.yml +++ b/.github/workflows/mac-cpu-arm64-build.yml @@ -53,13 +53,6 @@ jobs: python3 -m pip install -r test/python/requirements-macos.txt python3 -m pip install build/cpu/osx-arm64/wheel/onnxruntime_genai*.whl - - name: Get HuggingFace Token - run: | - az login --identity --username 63b63039-6328-442f-954b-5a64d124e5b4 - HF_TOKEN=$(az keyvault secret show --vault-name anubissvcsecret --name ANUBIS-HUGGINGFACE-TOKEN --query value) - echo "::add-mask::$HF_TOKEN" - echo "HF_TOKEN=$HF_TOKEN" >> $GITHUB_ENV - - name: Remove the ort lib and header files run: | rm -rf ort From fd0258c11fe3050f3e8f861ebed985a951805a2f Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:24:13 +0800 Subject: [PATCH 42/55] Unused --- .github/workflows/mac-cpu-arm64-build.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/mac-cpu-arm64-build.yml b/.github/workflows/mac-cpu-arm64-build.yml index d0b24a052..11fcba7dc 100644 --- a/.github/workflows/mac-cpu-arm64-build.yml +++ b/.github/workflows/mac-cpu-arm64-build.yml @@ -61,6 +61,7 @@ jobs: # 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 python3 test/python/test_onnxruntime_genai.py --cwd test/python --test_models test/test_models - name: Verify Build Artifacts @@ -74,11 +75,3 @@ jobs: set -e -x export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GITHUB_WORKSPACE/build/cpu/osx-arm64 ./build/cpu/osx-arm64/test/unit_tests - - - name: Upload Build Artifacts - uses: actions/upload-artifact@v3 - with: - name: onnxruntime-genai-mac-cpu-arm64 - path: ${{ github.workspace }}/build/**/*.a - - From 1bc6aac0c136a09865cc55ba3a6959198461cc41 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:17:35 +0800 Subject: [PATCH 43/55] enable dylib only on python --- CMakeLists.txt | 2 +- src/models/onnxruntime_api.h | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9c341f4a..1cbcbfc9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,7 @@ target_link_directories(onnxruntime-genai PRIVATE ${ORT_LIB_DIR}) # we keep the shared libraries disconnected on Android as they will come from separate AARs and we don't want to force # the ORT version to match in both. -if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")) +if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux" OR (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND ENABLE_PYTHON))) target_link_libraries(onnxruntime-genai PRIVATE ${ONNXRUNTIME_LIB}) endif() diff --git a/src/models/onnxruntime_api.h b/src/models/onnxruntime_api.h index af8f40bd3..887e2cd1c 100644 --- a/src/models/onnxruntime_api.h +++ b/src/models/onnxruntime_api.h @@ -91,7 +91,8 @@ p_session_->Run(nullptr, input_names, inputs, std::size(inputs), output_names, o #elif defined(__APPLE__) #include "TargetConditionals.h" -#if TARGET_OS_OSX +#if TARGET_OS_OSX && ENABLE_PYTHON +#define MACOS_USE_DLOPEN #include #endif #endif @@ -119,7 +120,7 @@ using OrtApiBaseFn = const OrtApiBase* (*)(void); /// Before using this C++ wrapper API, you MUST call Ort::InitApi to set the below 'api' variable inline const OrtApi* api{}; -#if defined(__linux__) || TARGET_OS_OSX +#if defined(__linux__) || defined(MACOS_USE_DLOPEN) inline std::string GetCurrentModuleDir() { Dl_info dl_info; dladdr((void*)GetCurrentModuleDir, &dl_info); @@ -200,7 +201,7 @@ inline void InitApi() { Generators::SetLogBool("ort_lib", true); } -#if defined(__linux__) || TARGET_OS_OSX +#if defined(__linux__) || defined(MACOS_USE_DLOPEN) // If the GenAI library links against the onnxruntime library, it will have a dependency on a specific // version of OrtGetApiBase. // @@ -233,7 +234,7 @@ inline void InitApi() { #endif #endif -#if TARGET_OS_OSX +#if MACOS_USE_DLOPEN const std::string path = "libonnxruntime.dylib"; void* ort_lib_handle = LoadDynamicLibraryIfExists(path); #endif @@ -249,11 +250,11 @@ inline void InitApi() { } InitApiWithDynamicFn(ort_api_base_fn); -#else // defined(__linux__) || TARGET_OS_OSX +#else // defined(__linux__) || defined(MACOS_USE_DLOPEN) api = OrtGetApiBase()->GetApi(ORT_API_VERSION); if (!api) throw std::runtime_error("Onnxruntime is installed but is too old, please install a newer version"); -#endif // defined(__linux__) || TARGET_OS_OSX +#endif // defined(__linux__) || defined(MACOS_USE_DLOPEN) } /** \brief All C++ methods that can fail will throw an exception of this type From 5f799d48c884cc319df6076c5847da38ca01c836 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Mon, 2 Sep 2024 13:13:39 +0800 Subject: [PATCH 44/55] compiler definition --- CMakeLists.txt | 2 ++ src/models/onnxruntime_api.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cbcbfc9c..a7df9d79e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,8 @@ target_link_directories(onnxruntime-genai PRIVATE ${ORT_LIB_DIR}) # the ORT version to match in both. if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux" OR (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND ENABLE_PYTHON))) target_link_libraries(onnxruntime-genai PRIVATE ${ONNXRUNTIME_LIB}) +else() +add_compile_definitions(_ORT_GENAI_USE_DLOPEN) endif() set_target_properties(onnxruntime-genai PROPERTIES FOLDER "Sources") diff --git a/src/models/onnxruntime_api.h b/src/models/onnxruntime_api.h index 887e2cd1c..7d7effa49 100644 --- a/src/models/onnxruntime_api.h +++ b/src/models/onnxruntime_api.h @@ -91,7 +91,7 @@ p_session_->Run(nullptr, input_names, inputs, std::size(inputs), output_names, o #elif defined(__APPLE__) #include "TargetConditionals.h" -#if TARGET_OS_OSX && ENABLE_PYTHON +#if TARGET_OS_OSX && _ORT_GENAI_USE_DLOPEN #define MACOS_USE_DLOPEN #include #endif @@ -234,7 +234,7 @@ inline void InitApi() { #endif #endif -#if MACOS_USE_DLOPEN +#if defined(MACOS_USE_DLOPEN) const std::string path = "libonnxruntime.dylib"; void* ort_lib_handle = LoadDynamicLibraryIfExists(path); #endif From 2a627cf556253f1a85f228339fba08f5873b8dbf Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Mon, 2 Sep 2024 13:23:27 +0800 Subject: [PATCH 45/55] invert --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7df9d79e..ff40742c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,10 +84,10 @@ target_link_directories(onnxruntime-genai PRIVATE ${ORT_LIB_DIR}) # we keep the shared libraries disconnected on Android as they will come from separate AARs and we don't want to force # the ORT version to match in both. -if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux" OR (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND ENABLE_PYTHON))) -target_link_libraries(onnxruntime-genai PRIVATE ${ONNXRUNTIME_LIB}) -else() +if(CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux" OR (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND ENABLE_PYTHON)) add_compile_definitions(_ORT_GENAI_USE_DLOPEN) +else() +target_link_libraries(onnxruntime-genai PRIVATE ${ONNXRUNTIME_LIB}) endif() set_target_properties(onnxruntime-genai PROPERTIES FOLDER "Sources") From 12abaa7f8293656023abafc3b4e3a76462e94ad8 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 5 Sep 2024 10:50:55 +0800 Subject: [PATCH 46/55] fix --- .github/workflows/mac-cpu-arm64-build.yml | 2 ++ test/python/requirements-macos.txt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/mac-cpu-arm64-build.yml b/.github/workflows/mac-cpu-arm64-build.yml index 11fcba7dc..dcf547721 100644 --- a/.github/workflows/mac-cpu-arm64-build.yml +++ b/.github/workflows/mac-cpu-arm64-build.yml @@ -62,6 +62,7 @@ jobs: - 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: Verify Build Artifacts @@ -73,5 +74,6 @@ jobs: - 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 diff --git a/test/python/requirements-macos.txt b/test/python/requirements-macos.txt index 83d4b7e6d..dcf4c3d97 100644 --- a/test/python/requirements-macos.txt +++ b/test/python/requirements-macos.txt @@ -1,4 +1,4 @@ -f https://download.pytorch.org/whl/torch_stable.html -i https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ torch==2.2.1 -ort-nightly==1.20.0.dev20240805004 +ort-nightly==1.20.0.dev20240903006 From b89d9bcfe30fa58de29bda92f21b2ca7c340b679 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 5 Sep 2024 11:19:10 +0800 Subject: [PATCH 47/55] find dylib on macos --- src/python/py/_dll_directory.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/python/py/_dll_directory.py b/src/python/py/_dll_directory.py index 0e47dbdce..25ccaf620 100644 --- a/src/python/py/_dll_directory.py +++ b/src/python/py/_dll_directory.py @@ -12,6 +12,10 @@ def _is_linux(): return sys.platform.startswith("linux") +def _is_macos(): + return sys.platform.startswith("darwin") + + def add_onnxruntime_dependency(package_id: str): """Add the onnxruntime shared library dependency. @@ -38,7 +42,7 @@ def add_onnxruntime_dependency(package_id: str): import ctypes _ = ctypes.CDLL(dml_path) - elif _is_linux(): + elif _is_linux() or _is_macos(): import importlib.util import ctypes import glob @@ -50,7 +54,10 @@ def add_onnxruntime_dependency(package_id: str): # Load the onnxruntime shared library here since we can find the path in python with ease. # This avoids needing to know the exact path of the shared library from native code. ort_package_path = ort_package.submodule_search_locations[0] - ort_lib_path = glob.glob(os.path.join(ort_package_path, "capi", "libonnxruntime.so*")) + if _is_linux(): + ort_lib_path = glob.glob(os.path.join(ort_package_path, "capi", "libonnxruntime.so*")) + elif _is_macos(): + ort_lib_path = glob.glob(os.path.join(ort_package_path, "capi", "libonnxruntime*.dylib")) if not ort_lib_path: raise ImportError("Could not find the onnxruntime shared library.") From 7d40b304a8b25b604a561aa9db2bdca6d44443ec Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:17:45 +0800 Subject: [PATCH 48/55] pass ort_lib_path using envvar --- src/models/onnxruntime_api.h | 36 ++++++++++++++++++++++----------- src/python/py/_dll_directory.py | 5 ++++- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/models/onnxruntime_api.h b/src/models/onnxruntime_api.h index 7d7effa49..0ee638f4c 100644 --- a/src/models/onnxruntime_api.h +++ b/src/models/onnxruntime_api.h @@ -140,11 +140,13 @@ inline void* LoadDynamicLibraryIfExists(const std::string& path) { if (ort_lib_handle == nullptr) { char* err = dlerror(); LOG_WARN("Error while dlopen: %s", (err != nullptr ? err : "Unknown")); - // Trying current dir - std::string current_module_dir = GetCurrentModuleDir(); - std::string local_path{current_module_dir + "/" + path}; - LOG_INFO("Attempting to dlopen %s", local_path.c_str()); - ort_lib_handle = dlopen(local_path.c_str(), RTLD_NOW | RTLD_LOCAL); + if (!path.starts_with("/")) { + // If not absolute path, try search for current dir + std::string current_module_dir = GetCurrentModuleDir(); + std::string local_path{current_module_dir + "/" + path}; + LOG_INFO("Attempting to dlopen %s", local_path.c_str()); + ort_lib_handle = dlopen(local_path.c_str(), RTLD_NOW | RTLD_LOCAL); + } } if (ort_lib_handle) { #if !defined(__ANDROID__) && !defined(__APPLE__) // RTLD_DI_ORIGIN not available on Android & Darwin @@ -223,20 +225,30 @@ inline void InitApi() { // any libonnxruntime.so that supports one of those versions. // -#if defined(__linux__) - const std::string path = "libonnxruntime.so"; // "libonnxruntime4j_jni.so" is also an option if we have issues - void* ort_lib_handle = LoadDynamicLibraryIfExists(path); + void* ort_lib_handle = nullptr; + const char *ort_lib_path = std::getenv("ORT_LIB_PATH"); + if (ort_lib_path) { + ort_lib_handle = LoadDynamicLibraryIfExists(ort_lib_path); + } -#if !defined(__ANDROID__) +#if defined(__ANDROID__) if (ort_lib_handle == nullptr) { - ort_lib_handle = LoadDynamicLibraryIfExists("libonnxruntime.so.1"); + // "libonnxruntime4j_jni.so" is also an option on Android if we have issues + ort_lib_handle = LoadDynamicLibraryIfExists("libonnxruntime.so"); } #endif + +#if defined(__linux__) + if (ort_lib_handle == nullptr) { + // On Linux it's just `.1`. See: https://github.com/microsoft/onnxruntime/pull/21339 + ort_lib_handle = LoadDynamicLibraryIfExists("libonnxruntime.so.1"); + } #endif #if defined(MACOS_USE_DLOPEN) - const std::string path = "libonnxruntime.dylib"; - void* ort_lib_handle = LoadDynamicLibraryIfExists(path); + if (ort_lib_handle == nullptr) { + void* ort_lib_handle = LoadDynamicLibraryIfExists("libonnxruntime.dylib); + } #endif if (ort_lib_handle == nullptr) { diff --git a/src/python/py/_dll_directory.py b/src/python/py/_dll_directory.py index 25ccaf620..1b09994c0 100644 --- a/src/python/py/_dll_directory.py +++ b/src/python/py/_dll_directory.py @@ -61,7 +61,10 @@ def add_onnxruntime_dependency(package_id: str): if not ort_lib_path: raise ImportError("Could not find the onnxruntime shared library.") - _ = ctypes.CDLL(ort_lib_path[0]) + target_lib_path = ort_lib_path[0] + os.environ["ORT_LIB_PATH"] = target_lib_path + + _ = ctypes.CDLL(target_lib_path) def add_cuda_dependency(): From 9bd4f8bf1ef873543c33c81393a684795d64e284 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:45:18 +0800 Subject: [PATCH 49/55] starts_with not available --- .github/workflows/linux-cpu-x64-build.yml | 1 + .github/workflows/linux-gpu-x64-build.yml | 2 +- src/models/onnxruntime_api.h | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux-cpu-x64-build.yml b/.github/workflows/linux-cpu-x64-build.yml index 6f970fdc0..e90a15675 100644 --- a/.github/workflows/linux-cpu-x64-build.yml +++ b/.github/workflows/linux-cpu-x64-build.yml @@ -102,5 +102,6 @@ jobs: - 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 diff --git a/.github/workflows/linux-gpu-x64-build.yml b/.github/workflows/linux-gpu-x64-build.yml index 857d54fd1..a675b1037 100644 --- a/.github/workflows/linux-gpu-x64-build.yml +++ b/.github/workflows/linux-gpu-x64-build.yml @@ -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" diff --git a/src/models/onnxruntime_api.h b/src/models/onnxruntime_api.h index 0ee638f4c..4f67cfb83 100644 --- a/src/models/onnxruntime_api.h +++ b/src/models/onnxruntime_api.h @@ -140,7 +140,7 @@ inline void* LoadDynamicLibraryIfExists(const std::string& path) { if (ort_lib_handle == nullptr) { char* err = dlerror(); LOG_WARN("Error while dlopen: %s", (err != nullptr ? err : "Unknown")); - if (!path.starts_with("/")) { + if (path.front() != '/') { // If not absolute path, try search for current dir std::string current_module_dir = GetCurrentModuleDir(); std::string local_path{current_module_dir + "/" + path}; @@ -247,7 +247,7 @@ inline void InitApi() { #if defined(MACOS_USE_DLOPEN) if (ort_lib_handle == nullptr) { - void* ort_lib_handle = LoadDynamicLibraryIfExists("libonnxruntime.dylib); + void* ort_lib_handle = LoadDynamicLibraryIfExists("libonnxruntime.dylib"); } #endif From cd4bdacb696f98e8789c332a928d29681da5b5d0 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:14:08 +0800 Subject: [PATCH 50/55] fix --- .github/workflows/linux-cpu-x64-build.yml | 14 ++++++++------ .github/workflows/mac-cpu-arm64-build.yml | 12 ++++++------ src/models/onnxruntime_api.h | 2 +- test/CMakeLists.txt | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/linux-cpu-x64-build.yml b/.github/workflows/linux-cpu-x64-build.yml index e90a15675..5594cc5e1 100644 --- a/.github/workflows/linux-cpu-x64-build.yml +++ b/.github/workflows/linux-cpu-x64-build.yml @@ -82,23 +82,25 @@ 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 diff --git a/.github/workflows/mac-cpu-arm64-build.yml b/.github/workflows/mac-cpu-arm64-build.yml index dcf547721..a9bf1e204 100644 --- a/.github/workflows/mac-cpu-arm64-build.yml +++ b/.github/workflows/mac-cpu-arm64-build.yml @@ -57,6 +57,12 @@ jobs: run: | rm -rf ort + - name: Verify Build Artifacts + if: always() + continue-on-error: true + run: | + ls -l ${{ github.workspace }}/build/cpu/osx-arm64 + # 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 @@ -65,12 +71,6 @@ jobs: export ORTGENAI_LOG_ORT_LIB=1 python3 test/python/test_onnxruntime_genai.py --cwd test/python --test_models test/test_models - - name: Verify Build Artifacts - if: always() - continue-on-error: true - run: | - ls -l ${{ github.workspace }}/build/cpu/osx-arm64 - - name: Run tests run: | set -e -x diff --git a/src/models/onnxruntime_api.h b/src/models/onnxruntime_api.h index 4f67cfb83..c954eed8f 100644 --- a/src/models/onnxruntime_api.h +++ b/src/models/onnxruntime_api.h @@ -226,7 +226,7 @@ inline void InitApi() { // void* ort_lib_handle = nullptr; - const char *ort_lib_path = std::getenv("ORT_LIB_PATH"); + const char* ort_lib_path = std::getenv("ORT_LIB_PATH"); if (ort_lib_path) { ort_lib_handle = LoadDynamicLibraryIfExists(ort_lib_path); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index da3502bb4..cb5967171 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,7 +26,7 @@ target_link_libraries(unit_tests PRIVATE GTest::gtest_main ) -if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux")) +if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")) target_link_libraries(unit_tests PRIVATE ${ONNXRUNTIME_LIB}) endif() From 63df69ac79d29ecc7f0d96007d56a49e8bc8fd41 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:43:43 +0800 Subject: [PATCH 51/55] Fix so loading on linux --- src/models/onnxruntime_api.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/models/onnxruntime_api.h b/src/models/onnxruntime_api.h index c954eed8f..5466c7cb7 100644 --- a/src/models/onnxruntime_api.h +++ b/src/models/onnxruntime_api.h @@ -231,23 +231,22 @@ inline void InitApi() { ort_lib_handle = LoadDynamicLibraryIfExists(ort_lib_path); } -#if defined(__ANDROID__) +#if defined(__linux__) if (ort_lib_handle == nullptr) { + // For Android and NuGet Linux package, the file name is libonnxruntime.so // "libonnxruntime4j_jni.so" is also an option on Android if we have issues ort_lib_handle = LoadDynamicLibraryIfExists("libonnxruntime.so"); } -#endif -#if defined(__linux__) if (ort_lib_handle == nullptr) { - // On Linux it's just `.1`. See: https://github.com/microsoft/onnxruntime/pull/21339 + // On Linux it can also be `libonnxruntime.so.1`. See: https://github.com/microsoft/onnxruntime/pull/21339 ort_lib_handle = LoadDynamicLibraryIfExists("libonnxruntime.so.1"); } #endif #if defined(MACOS_USE_DLOPEN) if (ort_lib_handle == nullptr) { - void* ort_lib_handle = LoadDynamicLibraryIfExists("libonnxruntime.dylib"); + ort_lib_handle = LoadDynamicLibraryIfExists("libonnxruntime.dylib"); } #endif From 0fbefbee90e877bf6dac2643af161ace58e2e33a Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:34:22 +0800 Subject: [PATCH 52/55] [skip ci] validation pipeline --- .pipelines/stages/jobs/py-validation-job.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.pipelines/stages/jobs/py-validation-job.yml b/.pipelines/stages/jobs/py-validation-job.yml index bbd19f3de..2282f8f77 100644 --- a/.pipelines/stages/jobs/py-validation-job.yml +++ b/.pipelines/stages/jobs/py-validation-job.yml @@ -199,7 +199,12 @@ jobs: - bash: | export ORTGENAI_LOG_ORT_LIB=1 python -m pip install -r test/python/requirements.txt - python -m pip install -r test/python/requirements-cpu.txt + if [[ "$(os)" == "linux" ]]; then + python -m pip install -r test/python/requirements-cpu.txt + fi + if [[ "$(os)" == "osx" ]]; then + python -m pip install -r test/python/requirements-macos.txt + fi cd examples/python python -m pip install --no-index --find-links=$(Build.BinariesDirectory)/wheel $(pip_package_name) python model-generate.py -m ./models/$(prebuild_phi3_mini_model_folder) --min_length 25 --max_length 50 --verbose From 2a3cbbd5b0793b1ae0f90ba01d49e7ad50e24c43 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 5 Sep 2024 16:40:48 +0800 Subject: [PATCH 53/55] mac os dotnet test on GHA --- .github/workflows/mac-cpu-arm64-build.yml | 6 ++++++ CMakeLists.txt | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/mac-cpu-arm64-build.yml b/.github/workflows/mac-cpu-arm64-build.yml index a9bf1e204..e85a1b6c9 100644 --- a/.github/workflows/mac-cpu-arm64-build.yml +++ b/.github/workflows/mac-cpu-arm64-build.yml @@ -71,6 +71,12 @@ jobs: 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index ff40742c3..a35772f4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,10 +84,10 @@ target_link_directories(onnxruntime-genai PRIVATE ${ORT_LIB_DIR}) # we keep the shared libraries disconnected on Android as they will come from separate AARs and we don't want to force # the ORT version to match in both. -if(CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux" OR (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND ENABLE_PYTHON)) -add_compile_definitions(_ORT_GENAI_USE_DLOPEN) +if(CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux" OR (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND (NOT BUILD_APPLE_FRAMEWORK))) + add_compile_definitions(_ORT_GENAI_USE_DLOPEN) else() -target_link_libraries(onnxruntime-genai PRIVATE ${ONNXRUNTIME_LIB}) + target_link_libraries(onnxruntime-genai PRIVATE ${ONNXRUNTIME_LIB}) endif() set_target_properties(onnxruntime-genai PROPERTIES FOLDER "Sources") From 37983723275c3d77a24a341c90962865a3482f47 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Thu, 5 Sep 2024 16:59:49 +0800 Subject: [PATCH 54/55] mac os dotnet test on GHA --- test/csharp/Microsoft.ML.OnnxRuntimeGenAI.Tests.csproj | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/csharp/Microsoft.ML.OnnxRuntimeGenAI.Tests.csproj b/test/csharp/Microsoft.ML.OnnxRuntimeGenAI.Tests.csproj index 7d6c8ea74..711719a34 100644 --- a/test/csharp/Microsoft.ML.OnnxRuntimeGenAI.Tests.csproj +++ b/test/csharp/Microsoft.ML.OnnxRuntimeGenAI.Tests.csproj @@ -63,6 +63,16 @@ false + + + PreserveNewest + false + + + PreserveNewest + false + + PreserveNewest false From ce7f7011f49700bf4833f844c72031b2cbd72817 Mon Sep 17 00:00:00 2001 From: Chester Liu <4710575+skyline75489@users.noreply.github.com> Date: Wed, 11 Sep 2024 14:51:43 +0800 Subject: [PATCH 55/55] Review --- .github/workflows/mac-cpu-arm64-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mac-cpu-arm64-build.yml b/.github/workflows/mac-cpu-arm64-build.yml index e85a1b6c9..a5f969284 100644 --- a/.github/workflows/mac-cpu-arm64-build.yml +++ b/.github/workflows/mac-cpu-arm64-build.yml @@ -51,7 +51,7 @@ jobs: 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 + python3 -m pip install build/cpu/osx-arm64/wheel/onnxruntime_genai*.whl --no-deps - name: Remove the ort lib and header files run: |