Make AzureEP default for python and c# packaging (#17025)

Make AzureEP default for python and c# packaging, with UT.

---------

Co-authored-by: Randy Shuai <rashuai@microsoft.com>
This commit is contained in:
RandySheriffH 2023-08-09 12:36:52 -07:00 committed by GitHub
parent 2c5d4dce77
commit a7542f48d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 68 additions and 130 deletions

View file

@ -5,7 +5,9 @@ using Microsoft.ML.OnnxRuntime.Tensors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
@ -2100,6 +2102,32 @@ namespace Microsoft.ML.OnnxRuntime.Tests
}
}
}
}
#if USE_AZURE
[Fact(DisplayName = "TestLoadAzureEP")]
private void TestLoadAzureEP()
{
var model = TestDataLoader.LoadModelFromEmbeddedResource("mul_1.onnx");
using (var memInfo = new OrtMemoryInfo(OrtMemoryInfo.allocatorCPU,
OrtAllocatorType.ArenaAllocator, 0, OrtMemType.Default))
using (var arenaCfg = new OrtArenaCfg(0, -1, -1, -1))
{
using (var sessionOptions = new SessionOptions())
{
sessionOptions.AppendExecutionProvider("AZURE");
try {
using (var session1 = new InferenceSession(model, sessionOptions))
{
}
}
catch (Exception) {
Assert.True(false);
}
}
}
}
#endif
}
}

View file

@ -1,107 +1,14 @@
import unittest
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import numpy as np
from helper import get_name
import unittest
import onnxruntime as ort
class TestAmlEndpoint(unittest.TestCase):
# test an endpoint of adding floats
def test_addf(self):
sess_opt = ort.SessionOptions()
sess_opt.add_session_config_entry("azure.endpoint_type", "triton")
sess_opt.add_session_config_entry("azure.uri", "https://endpoint-2930.westus2.inference.ml.azure.com")
sess_opt.add_session_config_entry("azure.model_name", "addf")
sess_opt.add_session_config_entry("azure.model_version", "1")
sess_opt.add_session_config_entry("azure.verbose", "true")
sess = ort.InferenceSession(get_name("azure_models/addf.onnx"), sess_opt, providers=["CPUExecutionProvider"])
run_opt = ort.RunOptions()
run_opt.log_severity_level = 1
run_opt.add_run_config_entry("use_azure", "1")
run_opt.add_run_config_entry("azure.auth_key", "lVUg86Ba7abAZU3GeKAMEtYy1wy9LacX")
x = np.array([1, 2, 3, 4]).astype(np.float32)
y = np.array([4, 3, 2, 1]).astype(np.float32)
z = sess.run(None, {"X": x, "Y": y}, run_opt)[0]
expected_z = np.array([5, 5, 5, 5]).astype(np.float32)
np.testing.assert_allclose(z, expected_z, rtol=1e-05, atol=1e-08)
# test an endpoint of adding doubles
def test_addf8(self):
sess_opt = ort.SessionOptions()
sess_opt.add_session_config_entry("azure.endpoint_type", "triton")
sess_opt.add_session_config_entry("azure.uri", "https://endpoint-1364.westus2.inference.ml.azure.com")
sess_opt.add_session_config_entry("azure.model_name", "addf8")
sess_opt.add_session_config_entry("azure.model_version", "1")
sess_opt.add_session_config_entry("azure.verbose", "true")
sess = ort.InferenceSession(get_name("azure_models/addf8.onnx"), sess_opt, providers=["CPUExecutionProvider"])
run_opt = ort.RunOptions()
run_opt.log_severity_level = 1
run_opt.add_run_config_entry("use_azure", "1")
run_opt.add_run_config_entry("azure.auth_key", "bUxzw3kZxJMjUbntLcVU3Duqq1nc87m5")
x = np.array([1, 2, 3, 4]).astype(np.double)
y = np.array([4, 3, 2, 1]).astype(np.double)
z = sess.run(None, {"X": x, "Y": y}, run_opt)[0]
expected_z = np.array([5, 5, 5, 5]).astype(np.double)
np.testing.assert_allclose(z, expected_z, rtol=1e-05, atol=1e-08)
# test an endpoint of adding int
def test_addi4(self):
sess_opt = ort.SessionOptions()
sess_opt.add_session_config_entry("azure.endpoint_type", "triton")
sess_opt.add_session_config_entry("azure.uri", "https://endpoint-9879.westus2.inference.ml.azure.com")
sess_opt.add_session_config_entry("azure.model_name", "addi4")
sess_opt.add_session_config_entry("azure.model_version", "1")
sess_opt.add_session_config_entry("azure.verbose", "true")
sess = ort.InferenceSession(get_name("azure_models/addi4.onnx"), sess_opt, providers=["CPUExecutionProvider"])
run_opt = ort.RunOptions()
run_opt.log_severity_level = 1
run_opt.add_run_config_entry("use_azure", "1")
run_opt.add_run_config_entry("azure.auth_key", "hRflo7KIj1DoOdfLw5R8PphBiMBOY4C8")
x = np.array([1, 2, 3, 4]).astype(np.int32)
y = np.array([4, 3, 2, 1]).astype(np.int32)
z = sess.run(None, {"X": x, "Y": y}, run_opt)[0]
expected_z = np.array([5, 5, 5, 5]).astype(np.int32)
np.testing.assert_allclose(z, expected_z, rtol=1e-05, atol=1e-08)
# test an endpoint of "And"
def test_and(self):
sess_opt = ort.SessionOptions()
sess_opt.add_session_config_entry("azure.endpoint_type", "triton")
sess_opt.add_session_config_entry("azure.uri", "https://endpoint-6811.westus2.inference.ml.azure.com")
sess_opt.add_session_config_entry("azure.model_name", "and")
sess_opt.add_session_config_entry("azure.model_version", "1")
sess_opt.add_session_config_entry("azure.verbose", "true")
sess = ort.InferenceSession(get_name("azure_models/and.onnx"), sess_opt, providers=["CPUExecutionProvider"])
run_opt = ort.RunOptions()
run_opt.log_severity_level = 1
run_opt.add_run_config_entry("use_azure", "1")
run_opt.add_run_config_entry("azure.auth_key", "fdCZuuoHEimRb4ukWZhtLhbcwzyKYgUu")
x = np.array([True, False]).astype(bool)
y = np.array([True, True]).astype(bool)
z = sess.run(None, {"X": x, "Y": y}, run_opt)[0]
expected_z = np.array([True, False]).astype(bool)
np.testing.assert_allclose(z, expected_z, rtol=1e-05, atol=1e-08)
class TestAzureEP(unittest.TestCase):
def test_availability(self):
self.assertIn("AzureExecutionProvider", ort.get_available_providers())
if __name__ == "__main__":

View file

@ -58,7 +58,7 @@ parameters:
- name: AdditionalBuildFlag
displayName: Build flags to append to build command
type: string
default: 'NONE'
default: '--use_azure'
resources:
repositories:
@ -117,10 +117,7 @@ stages:
${{ else }}:
OrtNugetPackageId: 'Microsoft.ML.OnnxRuntime${{ parameters.NugetPackageSuffix }}'
AdditionalBuildFlags: ''
${{ if eq(parameters.AdditionalBuildFlag, 'NONE') }}:
AdditionalWinBuildFlags: '--enable_onnx_tests --enable_wcos'
${{ else }}:
AdditionalWinBuildFlags: '--enable_onnx_tests --enable_wcos ${{parameters.AdditionalBuildFlag}}'
AdditionalWinBuildFlags: '--enable_onnx_tests --enable_wcos ${{parameters.AdditionalBuildFlag}}'
BuildVariant: 'default'
SpecificArtifact: ${{ parameters.SpecificArtifact }}
BuildId: ${{ parameters.BuildId }}
@ -198,7 +195,7 @@ stages:
buildArch: x64
msbuildPlatform: x64
packageName: x64-cuda
buildparameter: --use_cuda --cuda_version=11.8 --cuda_home=$(Agent.TempDirectory)\v11.8 --enable_onnx_tests --enable_wcos --build_java --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=52;60;61;70;75;80"
buildparameter: --use_cuda --cuda_version=11.8 --cuda_home=$(Agent.TempDirectory)\v11.8 --enable_onnx_tests --enable_wcos --build_java --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=52;60;61;70;75;80" ${{parameters.AdditionalBuildFlag}}
runTests: ${{ parameters.RunOnnxRuntimeTests }}
buildJava: true
java_artifact_id: onnxruntime_gpu

View file

@ -42,7 +42,7 @@ parameters:
- name: build_py_parameters
displayName: 'Specify extra build parameters'
type: string
default: 'NONE'
default: '--use_azure'
trigger: none
@ -65,5 +65,4 @@ stages:
enable_mac_cpu: ${{ parameters.enable_mac_cpu }}
enable_mac_silicon: ${{ parameters.enable_mac_silicon }}
enable_linux_arm: ${{ parameters.enable_linux_arm }}
${{ if not(eq(parameters.build_py_parameters, 'NONE')) }}:
build_py_parameters: ${{ parameters.build_py_parameters }}
build_py_parameters: ${{ parameters.build_py_parameters }}

View file

@ -5,6 +5,10 @@ parameters:
- name: machine_pool
type: string
- name: extra_build_arg
type: string
default: ''
jobs:
- job: Linux_py_GPU_Wheels_${{ parameters.arch }}
timeoutInMinutes: 240
@ -35,7 +39,7 @@ jobs:
targetType: filePath
filePath: tools/ci_build/github/linux/run_python_dockerbuild.sh
# please check ONNXRUNTIME_CUDA_VERSION in tools/ci_build/github/linux/build_linux_arm64_python_package.sh
arguments: -i onnxruntimecuda118xtrt86build${{ parameters.arch }} -x "-d GPU"
arguments: -i onnxruntimecuda118xtrt86build${{ parameters.arch }} -d "GPU" -x "${{ parameters.extra_build_arg }}"
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: ONNXRuntime python wheel'

View file

@ -19,12 +19,16 @@ parameters:
- name: device
type: string
default: '-d CPU'
default: 'CPU'
- name: with_cache
type: boolean
default: false
- name: extra_build_arg
type: string
default: ''
jobs:
- job: Linux_py_Wheels_${{ parameters.arch }}
timeoutInMinutes: 240
@ -69,7 +73,7 @@ jobs:
inputs:
targetType: filePath
filePath: tools/ci_build/github/linux/run_python_dockerbuild.sh
arguments: -i onnxruntimecpubuilpython${{ parameters.arch }} -x "${{ parameters.device }}"
arguments: -i onnxruntimecpubuilpython${{ parameters.arch }} -d "${{ parameters.device }}" -x "${{ parameters.extra_build_arg }}"
${{ if eq(parameters.with_cache, 'true') }}:
env:
ADDITIONAL_DOCKER_PARAMETER: "--volume $(ORT_CACHE_DIR):/cache -e CCACHE_DIR=/cache -e ORT_BUILD_WITH_CACHE=1"

View file

@ -495,8 +495,7 @@ stages:
devtoolset_rootpath: /opt/rh/devtoolset-10/root
ld_library_path_arg: /opt/rh/devtoolset-10/root/usr/lib64:/opt/rh/devtoolset-10/root/usr/lib:/opt/rh/devtoolset-10/root/usr/lib64/dyninst:/opt/rh/devtoolset-10/root/usr/lib/dyninst:/usr/local/lib64
prepend_path: '/opt/rh/devtoolset-10/root/usr/bin:'
${{ if contains(parameters.build_py_parameters, '--use_azure') }}:
device: '-d AZURE'
extra_build_arg: ${{ parameters.build_py_parameters }}
- ${{ if eq(parameters.enable_linux_cpu, true) }}:
- template: py-linux.yml
@ -507,8 +506,7 @@ stages:
devtoolset_rootpath: /opt/rh/devtoolset-11/root
ld_library_path_arg: /opt/rh/devtoolset-11/root/usr/lib64:/opt/rh/devtoolset-11/root/usr/lib:/opt/rh/devtoolset-11/root/usr/lib64/dyninst:/opt/rh/devtoolset-11/root/usr/lib/dyninst:/usr/local/lib64
prepend_path: '/opt/rh/devtoolset-11/root/usr/bin:'
${{ if contains(parameters.build_py_parameters, '--use_azure') }}:
device: '-d AZURE'
extra_build_arg: ${{ parameters.build_py_parameters }}
- ${{ if eq(parameters.enable_linux_gpu, true) }}:
@ -516,5 +514,4 @@ stages:
parameters:
arch: 'x86_64'
machine_pool: 'onnxruntime-Ubuntu2004-AMD-CPU'
${{ if contains(parameters.build_py_parameters, '--use_azure') }}:
device: '-d AZURE'
extra_build_arg: ${{ parameters.build_py_parameters }}

View file

@ -7,13 +7,16 @@ CXXFLAGS="-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-st
BUILD_DEVICE="CPU"
BUILD_CONFIG="Release"
EXTRA_ARG=""
PYTHON_EXES=("/opt/python/cp38-cp38/bin/python3.8" "/opt/python/cp39-cp39/bin/python3.9" "/opt/python/cp310-cp310/bin/python3.10" "/opt/python/cp311-cp311/bin/python3.11")
while getopts "d:p:" parameter_Option
while getopts "d:p:x:" parameter_Option
do case "${parameter_Option}"
in
#GPU or CPU.
d) BUILD_DEVICE=${OPTARG};;
p) PYTHON_EXES=(${OPTARG});;
x) EXTRA_ARG=(${OPTARG});;
esac
done
@ -32,9 +35,15 @@ if [ "$ARCH" == "x86_64" ] && [ "$GCC_VERSION" -ge 9 ]; then
CXXFLAGS="$CXXFLAGS -fcf-protection"
fi
BUILD_ARGS=("--build_dir" "/build" "--config" "$BUILD_CONFIG" "--update" "--build" "--skip_submodule_sync" "--parallel" "--enable_lto" "--build_wheel")
echo "EXTRA_ARG:"
echo $EXTRA_ARG
if [ "$EXTRA_ARG" != "" ]; then
BUILD_ARGS+=("$EXTRA_ARG")
fi
if [ "$ARCH" == "x86_64" ]; then
#ARM build machines do not have the test data yet.
BUILD_ARGS+=("--enable_onnx_tests")
@ -44,14 +53,6 @@ if [ "$BUILD_DEVICE" == "GPU" ]; then
#Enable CUDA and TRT EPs.
ONNXRUNTIME_CUDA_VERSION="11.8"
BUILD_ARGS+=("--use_cuda" "--use_tensorrt" "--cuda_version=$ONNXRUNTIME_CUDA_VERSION" "--tensorrt_home=/usr" "--cuda_home=/usr/local/cuda-$ONNXRUNTIME_CUDA_VERSION" "--cudnn_home=/usr/local/cuda-$ONNXRUNTIME_CUDA_VERSION" "--cmake_extra_defines" "CMAKE_CUDA_ARCHITECTURES=52;60;61;70;75;80")
elif [ "$BUILD_DEVICE" == "AZURE" ]; then
BUILD_ARGS+=("--use_azure")
if [ -f /etc/lsb-release ]; then
# for ubuntu
apt-get install -y libipc-system-simple-perl python3 libssl-dev
else
export PATH=/opt/python/cp38-cp38/bin:$PATH
fi
fi
export CFLAGS

View file

@ -1,9 +1,10 @@
#!/bin/bash
set -e -x
while getopts "x:i:" parameter_Option
while getopts "i:d:x:" parameter_Option
do case "${parameter_Option}"
in
i) DOCKER_IMAGE=${OPTARG};;
d) DEVICE=${OPTARG};;
x) BUILD_EXTR_PAR=${OPTARG};;
esac
done
@ -19,7 +20,7 @@ docker run --rm \
-e NIGHTLY_BUILD \
-e BUILD_BUILDNUMBER \
$ADDITIONAL_DOCKER_PARAMETER \
$DOCKER_IMAGE tools/ci_build/github/linux/build_linux_arm64_python_package.sh $BUILD_EXTR_PAR
$DOCKER_IMAGE tools/ci_build/github/linux/build_linux_arm64_python_package.sh -d $DEVICE -x $BUILD_EXTR_PAR
sudo rm -rf $BUILD_BINARIESDIRECTORY/Release/onnxruntime $BUILD_BINARIESDIRECTORY/Release/pybind11 \
$BUILD_BINARIESDIRECTORY/Release/models $BUILD_BINARIESDIRECTORY/Release/_deps \