From dc0a3bea95fa7e443b1fbb9c1dd66f492fd99853 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Wed, 27 Mar 2024 17:12:42 +0800 Subject: [PATCH 01/33] Update CI Pipeline (#278) * copy PR 269 Signed-off-by: xiaowuhu * update CI Signed-off-by: xiaowuhu * try something Signed-off-by: xiaowuhu * try Signed-off-by: xiaowuhu * Update linux-conda-CI.yml Signed-off-by: xiaowuhu * Update linux-conda-CI.yml Signed-off-by: xiaowuhu * Update linux-conda-CI.yml Signed-off-by: xiaowuhu * Update win32-conda-CI.yml Signed-off-by: xiaowuhu * Update win32-conda-CI.yml Signed-off-by: xiaowuhu --------- Signed-off-by: xiaowuhu --- .azure-pipelines/linux-conda-CI.yml | 35 +++++++++++++---------------- .azure-pipelines/win32-conda-CI.yml | 14 ++++++------ 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/.azure-pipelines/linux-conda-CI.yml b/.azure-pipelines/linux-conda-CI.yml index 6675d37..7b11e62 100644 --- a/.azure-pipelines/linux-conda-CI.yml +++ b/.azure-pipelines/linux-conda-CI.yml @@ -15,58 +15,55 @@ jobs: matrix: Python381: python.version: '3.8' - ONNX_PATH: onnx==1.7.0 + ONNX_PATH: onnx==1.12 Python382: python.version: '3.8' - ONNX_PATH: onnx==1.8.0 + ONNX_PATH: onnx==1.12 Python391: python.version: '3.9' - ONNX_PATH: onnx==1.9.0 + ONNX_PATH: onnx==1.12 Python392: python.version: '3.9' - ONNX_PATH: onnx==1.10.2 + ONNX_PATH: onnx==1.12 Python393: python.version: '3.9' - ONNX_PATH: onnx==1.12.0 + ONNX_PATH: onnx==1.14 Python310_112: python.version: '3.10' - ONNX_PATH: onnx==1.12.0 + ONNX_PATH: onnx==1.14 maxParallel: 4 steps: - - script: sudo install -d -m 0777 /home/vsts/.conda/envs - displayName: Fix Conda permissions - - task: CondaEnvironment@1 + - task: UsePythonVersion@0 inputs: - createCustomEnvironment: true - environmentName: 'py$(python.version)' - packageSpecs: 'python=$(python.version)' + versionSpec: '$(python.version)' + addToPath: true + architecture: 'x64' + displayName: 'Use Python $(python.version)' - script: | python -m pip install --upgrade pip - conda config --set always_yes yes --set changeps1 no - conda install -c conda-forge numpy - pip install protobuf==3.20.2 + pip install 'protobuf==3.20.2' pip install pytest displayName: 'Install dependencies' - script: | - pip install onnxruntime + pip install onnxruntime==1.15 pip install onnxmltools pip install $(ONNX_PATH) displayName: 'Install onnxruntime, onnxmltools' - - script: | - python -c "import onnxconverter_common" - displayName: 'Check import without onnxruntime' + # - script: | + # python -c "import onnxconverter_common" + # displayName: 'Check import without onnxruntime' - script: | pip install -e . diff --git a/.azure-pipelines/win32-conda-CI.yml b/.azure-pipelines/win32-conda-CI.yml index d0ddffb..81a9e97 100644 --- a/.azure-pipelines/win32-conda-CI.yml +++ b/.azure-pipelines/win32-conda-CI.yml @@ -33,18 +33,18 @@ jobs: versionSpec: '$(python.version)' architecture: 'x64' - - powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" - displayName: Add conda to PATH + # - powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" + # displayName: Add conda to PATH - - script: conda create --yes --quiet --name py$(python.version) -c conda-forge python=$(python.version) numpy - displayName: Create Anaconda environment + # - script: conda create --yes --quiet --name py$(python.version) -c conda-forge python=$(python.version) numpy + # displayName: Create Anaconda environment - script: | call activate py$(python.version) - pip install onnxruntime + pip install onnxruntime==1.15 pip install onnxmltools pip install %ONNX_PATH% - pip install protobuf==3.20.2 + pip install 'protobuf==3.20.2' pip install pytest pip install -e . displayName: 'Install dependencies' @@ -62,6 +62,6 @@ jobs: - task: PublishTestResults@2 inputs: - testResultsFiles: '**/test-results.xml' + testResultsFiles: '**/test-results-onnxutils.xml' testRunTitle: 'Python $(python.version)' condition: succeededOrFailed() From 4ba84d0913525106323307eb3cb3c1b4ea9bbf75 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Thu, 28 Mar 2024 16:52:53 +0800 Subject: [PATCH 02/33] Create github-actions-demo.yml This is only for testing github actions. Will be removed later. --- .github/workflows/github-actions-demo.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/github-actions-demo.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml new file mode 100644 index 0000000..15a61d6 --- /dev/null +++ b/.github/workflows/github-actions-demo.yml @@ -0,0 +1,18 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." From 8ffb59653292e542fd870b34e1a6e6499932569c Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Thu, 28 Mar 2024 17:41:53 +0800 Subject: [PATCH 03/33] Create python-app.yml --- .github/workflows/python-app.yml | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..30a9383 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest tests --doctest-modules --junitxml=junit/test-results-onnxutils.xml From 1027e132f09844466bddac1c9b7ef56d4be1b1f4 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Thu, 28 Mar 2024 17:52:41 +0800 Subject: [PATCH 04/33] Update python-app.yml --- .github/workflows/python-app.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 30a9383..b0f2351 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -28,6 +28,10 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + pip install onnxruntime==1.15 + pip install onnxmltools + pip install onnx==1.14 + pip install -e . - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names From 5b906ae6887a9463432698dc2e0d63e5cb62f8bb Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 14:49:12 +0800 Subject: [PATCH 05/33] Update python-app.yml --- .github/workflows/python-app.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index b0f2351..f4366ac 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -13,16 +13,18 @@ permissions: contents: read jobs: - build: - + example_matrix: runs-on: ubuntu-latest - + strategy: + matrix: + version: ["3.8", "3.9", "3.10"] + steps: - uses: actions/checkout@v3 - - name: Set up Python 3.10 + - name: Set up Python ${{ matrix.version }} uses: actions/setup-python@v3 with: - python-version: "3.10" + python-version: ${{ matrix.version }} - name: Install dependencies run: | python -m pip install --upgrade pip From 9ec952ebc856de708b9d7f7057058b18b25e01d7 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:11:27 +0800 Subject: [PATCH 06/33] Update python-app.yml --- .github/workflows/python-app.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index f4366ac..cd167b5 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -17,14 +17,22 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - version: ["3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10"] + include: + - python-version: 3.8 + onnx_version: 1.12 + - python-version: 3.9 + onnx_version: 1.13 + - python-version: 3.10 + onnx_version: 1.14 + steps: - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.version }} + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: - python-version: ${{ matrix.version }} + python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip @@ -32,7 +40,7 @@ jobs: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi pip install onnxruntime==1.15 pip install onnxmltools - pip install onnx==1.14 + pip install onnx==${{ matrix.onnx-version }} pip install -e . - name: Lint with flake8 run: | From 52e1084875dbe1d152101d1d9abffb9818e26b09 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:14:43 +0800 Subject: [PATCH 07/33] Update python-app.yml --- .github/workflows/python-app.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index cd167b5..af7d65f 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -20,11 +20,11 @@ jobs: python-version: ["3.8", "3.9", "3.10"] include: - python-version: 3.8 - onnx_version: 1.12 + onnx_version: 1.12.0 - python-version: 3.9 - onnx_version: 1.13 + onnx_version: "1.13" - python-version: 3.10 - onnx_version: 1.14 + onnx_version: "1.14.1" steps: From 16771c5dc55b8ca64aaf322f7de6ec8dc735fbc5 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:20:27 +0800 Subject: [PATCH 08/33] Update python-app.yml --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index af7d65f..2552d0e 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -19,7 +19,7 @@ jobs: matrix: python-version: ["3.8", "3.9", "3.10"] include: - - python-version: 3.8 + - python-version: "3.8" onnx_version: 1.12.0 - python-version: 3.9 onnx_version: "1.13" From b879eb026da64af0aa27dec9be9a684c3f43c703 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:21:43 +0800 Subject: [PATCH 09/33] Update python-app.yml --- .github/workflows/python-app.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 2552d0e..fb50fa1 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -21,9 +21,9 @@ jobs: include: - python-version: "3.8" onnx_version: 1.12.0 - - python-version: 3.9 + - python-version: "3.9" onnx_version: "1.13" - - python-version: 3.10 + - python-version: "3.10" onnx_version: "1.14.1" From a7b4094e92d26aa7612c23af85afde9ab03044aa Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:23:28 +0800 Subject: [PATCH 10/33] Update python-app.yml --- .github/workflows/python-app.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index fb50fa1..ef76523 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -17,14 +17,14 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: [3.8, 3.9, 3.10] include: - - python-version: "3.8" - onnx_version: 1.12.0 - - python-version: "3.9" - onnx_version: "1.13" - - python-version: "3.10" - onnx_version: "1.14.1" + - python-version: 3.8 + onnx-version: 1.12.0 + - python-version: 3.9 + onnx-version: 1.13 + - python-version: 3.10 + onnx-version: 1.14.1 steps: From 3015263107425346d107edd688d25fe24d07497c Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:25:40 +0800 Subject: [PATCH 11/33] Update python-app.yml --- .github/workflows/python-app.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index ef76523..ae59eea 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -17,13 +17,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.8, 3.9, 3.10] + python-version: ["3.8", "3.9", "3.10"] include: - - python-version: 3.8 - onnx-version: 1.12.0 - - python-version: 3.9 + - python-version: "3.8" + onnx-version: "1.12.0" + - python-version: "3.9" onnx-version: 1.13 - - python-version: 3.10 + - python-version: "3.10" onnx-version: 1.14.1 From 38d26ed8ed0a953b23c679748f7733fb5d70522e Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:26:39 +0800 Subject: [PATCH 12/33] Delete .github/workflows/github-actions-demo.yml --- .github/workflows/github-actions-demo.yml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 .github/workflows/github-actions-demo.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml deleted file mode 100644 index 15a61d6..0000000 --- a/.github/workflows/github-actions-demo.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: GitHub Actions Demo -run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 -on: [push] -jobs: - Explore-GitHub-Actions: - runs-on: ubuntu-latest - steps: - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code - uses: actions/checkout@v4 - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ github.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." From afdfe56267e5fb48237aa525182cdff661a2c158 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:29:58 +0800 Subject: [PATCH 13/33] Update python-app.yml --- .github/workflows/python-app.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index ae59eea..6c93d7d 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -20,7 +20,7 @@ jobs: python-version: ["3.8", "3.9", "3.10"] include: - python-version: "3.8" - onnx-version: "1.12.0" + onnx-version: 1.12.0 - python-version: "3.9" onnx-version: 1.13 - python-version: "3.10" @@ -28,7 +28,7 @@ jobs: steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: From a5c7ec8fae64130ec87699d723b1792ef0a65c0a Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:32:43 +0800 Subject: [PATCH 14/33] Update python-app.yml --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 6c93d7d..5fe3cd0 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -30,7 +30,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Install dependencies From 86c9a00e83f95135f9e602d33de4767ea534f087 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:49:28 +0800 Subject: [PATCH 15/33] Update python-app.yml --- .github/workflows/python-app.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 5fe3cd0..5d89762 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -13,11 +13,11 @@ permissions: contents: read jobs: - example_matrix: - runs-on: ubuntu-latest + test_matrix: strategy: matrix: python-version: ["3.8", "3.9", "3.10"] + os: [ubuntu-latest, windows-latest] include: - python-version: "3.8" onnx-version: 1.12.0 @@ -25,12 +25,12 @@ jobs: onnx-version: 1.13 - python-version: "3.10" onnx-version: 1.14.1 + runs-on: ${{ matrix.os}} - steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5.1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies From 6d8b95e27946fcb87bc80a4a59cb737d664b8251 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:50:30 +0800 Subject: [PATCH 16/33] Update python-app.yml --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 5d89762..192c261 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -30,7 +30,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5.1 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies From 8ae531cacd74e810c78b7513333b089c85e939e2 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:52:45 +0800 Subject: [PATCH 17/33] Update python-app.yml --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 192c261..ee43c5f 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -37,7 +37,7 @@ jobs: run: | python -m pip install --upgrade pip pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + if ( -f requirements.txt ); then pip install -r requirements.txt; fi pip install onnxruntime==1.15 pip install onnxmltools pip install onnx==${{ matrix.onnx-version }} From 1f027490bdffdb7f110697cb4a360c3d4f78fe2c Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:55:48 +0800 Subject: [PATCH 18/33] Update python-app.yml --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index ee43c5f..df6db11 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: python-version: ["3.8", "3.9", "3.10"] - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] include: - python-version: "3.8" onnx-version: 1.12.0 From ef7b94739d9fa048d5589d05c34c26ae58dc4e5e Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 15:56:02 +0800 Subject: [PATCH 19/33] Update python-app.yml --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index df6db11..2cbb907 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -37,7 +37,7 @@ jobs: run: | python -m pip install --upgrade pip pip install flake8 pytest - if ( -f requirements.txt ); then pip install -r requirements.txt; fi + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi pip install onnxruntime==1.15 pip install onnxmltools pip install onnx==${{ matrix.onnx-version }} From 0e21d6a33c925ebd78843fd0dee744a72064176e Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 16:54:41 +0800 Subject: [PATCH 20/33] Create linux-CI.yml --- .github/workflows/linux-CI.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/workflows/linux-CI.yml diff --git a/.github/workflows/linux-CI.yml b/.github/workflows/linux-CI.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.github/workflows/linux-CI.yml @@ -0,0 +1 @@ + From d97a8a0872ef9af9e3452bcfcb46c816e8300412 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 16:55:51 +0800 Subject: [PATCH 21/33] Update linux-CI.yml --- .github/workflows/linux-CI.yml | 53 ++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/.github/workflows/linux-CI.yml b/.github/workflows/linux-CI.yml index 8b13789..0b48b88 100644 --- a/.github/workflows/linux-CI.yml +++ b/.github/workflows/linux-CI.yml @@ -1 +1,54 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + test_matrix: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10"] + include: + - python-version: "3.8" + onnx-version: 1.12.0 + - python-version: "3.9" + onnx-version: 1.13 + - python-version: "3.10" + onnx-version: 1.14.1 + + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + pip install onnxruntime==1.15 + pip install onnxmltools + pip install onnx==${{ matrix.onnx-version }} + pip install -e . + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest tests --doctest-modules --junitxml=junit/test-results-onnxutils.xml From d2e33df476bffbd80b51e9af7f8fe89d170ed0a9 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 16:56:20 +0800 Subject: [PATCH 22/33] Create windows-CI.yml --- .github/workflows/windows-CI.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/workflows/windows-CI.yml diff --git a/.github/workflows/windows-CI.yml b/.github/workflows/windows-CI.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.github/workflows/windows-CI.yml @@ -0,0 +1 @@ + From c8c6f21e652ac5b3a0347a15f59f1a3a98b683a2 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 17:00:18 +0800 Subject: [PATCH 23/33] Update windows-CI.yml --- .github/workflows/windows-CI.yml | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/.github/workflows/windows-CI.yml b/.github/workflows/windows-CI.yml index 8b13789..467706d 100644 --- a/.github/workflows/windows-CI.yml +++ b/.github/workflows/windows-CI.yml @@ -1 +1,52 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + test_matrix: + runs-on: windows-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10"] + include: + - python-version: "3.8" + onnx-version: 1.12.0 + - python-version: "3.9" + onnx-version: 1.13 + - python-version: "3.10" + onnx-version: 1.14.1 + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + pip install onnxruntime==1.15 + pip install onnxmltools + pip install onnx==${{ matrix.onnx-version }} + pip install -e . + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest tests --doctest-modules --junitxml=junit/test-results-onnxutils.xml From 1986e56ff01414779d701f734b44478b4d862de0 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Fri, 29 Mar 2024 17:00:34 +0800 Subject: [PATCH 24/33] Delete .github/workflows/python-app.yml --- .github/workflows/python-app.yml | 53 -------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index 2cbb907..0000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,53 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Python application - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -permissions: - contents: read - -jobs: - test_matrix: - strategy: - matrix: - python-version: ["3.8", "3.9", "3.10"] - os: [ubuntu-latest] - include: - - python-version: "3.8" - onnx-version: 1.12.0 - - python-version: "3.9" - onnx-version: 1.13 - - python-version: "3.10" - onnx-version: 1.14.1 - runs-on: ${{ matrix.os}} - - steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - pip install onnxruntime==1.15 - pip install onnxmltools - pip install onnx==${{ matrix.onnx-version }} - pip install -e . - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - pytest tests --doctest-modules --junitxml=junit/test-results-onnxutils.xml From de40edcaaf20cad69a959250761f05eb02e5d016 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Mon, 1 Apr 2024 16:18:54 +0800 Subject: [PATCH 25/33] testing pipeline (#280) Signed-off-by: xiaowuhu --- .azure-pipelines/win32-conda-CI.yml | 67 ----------------------------- requirements.txt | 2 +- 2 files changed, 1 insertion(+), 68 deletions(-) delete mode 100644 .azure-pipelines/win32-conda-CI.yml diff --git a/.azure-pipelines/win32-conda-CI.yml b/.azure-pipelines/win32-conda-CI.yml deleted file mode 100644 index 81a9e97..0000000 --- a/.azure-pipelines/win32-conda-CI.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Python package -# Create and test a Python package on multiple Python versions. -# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more: -# https://docs.microsoft.com/azure/devops/pipelines/languages/python - -trigger: -- master - -jobs: - -- job: 'Test' - pool: - vmImage: 'windows-latest' - strategy: - matrix: - Python38: - python.version: '3.8' - ONNX_PATH: onnx==1.11.0 - - Python39: - python.version: '3.9' - ONNX_PATH: onnx==1.12.0 - - Python310: - python.version: '3.10' - ONNX_PATH: onnx==1.13.0 - - maxParallel: 4 - - steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: '$(python.version)' - architecture: 'x64' - - # - powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" - # displayName: Add conda to PATH - - # - script: conda create --yes --quiet --name py$(python.version) -c conda-forge python=$(python.version) numpy - # displayName: Create Anaconda environment - - - script: | - call activate py$(python.version) - pip install onnxruntime==1.15 - pip install onnxmltools - pip install %ONNX_PATH% - pip install 'protobuf==3.20.2' - pip install pytest - pip install -e . - displayName: 'Install dependencies' - - - script: | - call activate py$(python.version) - pip install flake8 - python -m flake8 onnxconverter_common - displayName: 'run flake8 check' - - - script: | - call activate py$(python.version) - pytest tests --doctest-modules --junitxml=junit/test-results-onnxutils.xml - displayName: 'pytest - onnxutils' - - - task: PublishTestResults@2 - inputs: - testResultsFiles: '**/test-results-onnxutils.xml' - testRunTitle: 'Python $(python.version)' - condition: succeededOrFailed() diff --git a/requirements.txt b/requirements.txt index 03a553f..4e27326 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ numpy onnx packaging -protobuf==3.20.2 +protobuf>=3.20.2 From 848f671552546a6d047b51de2306ea3f8829d0df Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Mon, 1 Apr 2024 16:52:01 +0800 Subject: [PATCH 26/33] del old pipeline (#281) Signed-off-by: xiaowuhu --- .azure-pipelines/linux-conda-CI.yml | 86 ----------------------------- .azure-pipelines/nightly-CI.yml | 4 +- 2 files changed, 2 insertions(+), 88 deletions(-) delete mode 100644 .azure-pipelines/linux-conda-CI.yml diff --git a/.azure-pipelines/linux-conda-CI.yml b/.azure-pipelines/linux-conda-CI.yml deleted file mode 100644 index 7b11e62..0000000 --- a/.azure-pipelines/linux-conda-CI.yml +++ /dev/null @@ -1,86 +0,0 @@ -# Python package -# Create and test a Python package on multiple Python versions. -# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more: -# https://docs.microsoft.com/azure/devops/pipelines/languages/python - -trigger: -- master - -jobs: - -- job: 'Test' - pool: - vmImage: 'Ubuntu-latest' - strategy: - matrix: - Python381: - python.version: '3.8' - ONNX_PATH: onnx==1.12 - - Python382: - python.version: '3.8' - ONNX_PATH: onnx==1.12 - - Python391: - python.version: '3.9' - ONNX_PATH: onnx==1.12 - - Python392: - python.version: '3.9' - ONNX_PATH: onnx==1.12 - - Python393: - python.version: '3.9' - ONNX_PATH: onnx==1.14 - - Python310_112: - python.version: '3.10' - ONNX_PATH: onnx==1.14 - - - maxParallel: 4 - - steps: - - - task: UsePythonVersion@0 - inputs: - versionSpec: '$(python.version)' - addToPath: true - architecture: 'x64' - displayName: 'Use Python $(python.version)' - - - script: | - python -m pip install --upgrade pip - pip install 'protobuf==3.20.2' - pip install pytest - displayName: 'Install dependencies' - - - script: | - pip install onnxruntime==1.15 - pip install onnxmltools - pip install $(ONNX_PATH) - displayName: 'Install onnxruntime, onnxmltools' - - # - script: | - # python -c "import onnxconverter_common" - # displayName: 'Check import without onnxruntime' - - - script: | - pip install -e . - displayName: 'Install onnxconverter_common' - - - script: | - pip install flake8 - python -m flake8 onnxconverter_common - displayName: 'run flake8 check' - - - script: | - python -c "import onnxconverter_common" - pytest tests --doctest-modules --junitxml=junit/test-results-onnxutils.xml - displayName: 'pytest - onnxutils' - - - task: PublishTestResults@2 - inputs: - testResultsFiles: '**/test-results.xml' - testRunTitle: 'Python $(python.version)' - condition: succeededOrFailed() diff --git a/.azure-pipelines/nightly-CI.yml b/.azure-pipelines/nightly-CI.yml index 8794db2..4d753ad 100644 --- a/.azure-pipelines/nightly-CI.yml +++ b/.azure-pipelines/nightly-CI.yml @@ -50,7 +50,7 @@ jobs: pip uninstall -y onnxruntime pip install --index-url https://test.pypi.org/simple/ ort-nightly pip install $(ONNX_PATH) - pip install protobuf==3.20.2 + pip install protobuf>=3.20.2 pip install pytest pip install -e . displayName: 'Install dependencies' @@ -117,7 +117,7 @@ jobs: pip uninstall -y onnxruntime pip install --index-url https://test.pypi.org/simple/ ort-nightly pip install %ONNX_PATH% - pip install protobuf==3.20.2 + pip install protobuf>=3.20.2 pip install pytest pip install -e . displayName: 'Install dependencies' From 6c834f51cac8f8ea3929abbebad425c5bb2a7d8f Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Mon, 1 Apr 2024 17:01:04 +0800 Subject: [PATCH 27/33] Update nightly-CI.yml (#282) Signed-off-by: xiaowuhu --- .azure-pipelines/nightly-CI.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.azure-pipelines/nightly-CI.yml b/.azure-pipelines/nightly-CI.yml index 4d753ad..af3271b 100644 --- a/.azure-pipelines/nightly-CI.yml +++ b/.azure-pipelines/nightly-CI.yml @@ -12,15 +12,15 @@ jobs: matrix: Python382: python.version: '3.8' - ONNX_PATH: onnx==1.8.0 + ONNX_PATH: onnx==1.13.0 Python391: python.version: '3.9' - ONNX_PATH: onnx==1.9.0 + ONNX_PATH: onnx==1.13.0 Python392: python.version: '3.9' - ONNX_PATH: onnx==1.10.2 + ONNX_PATH: onnx==1.13.0 Python310: python.version: '3.10' From 00f2ad587095c580d120606a7ffc07ebf93910c0 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Tue, 2 Apr 2024 17:06:45 +0800 Subject: [PATCH 28/33] Fix Conda issue due to it is deprecated (#283) * Update nightly-CI.yml Signed-off-by: xiaowuhu * Update nightly-CI.yml Signed-off-by: xiaowuhu * Update nightly-CI.yml Signed-off-by: xiaowuhu --------- Signed-off-by: xiaowuhu --- .azure-pipelines/nightly-CI.yml | 36 ++++++++++++++------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/.azure-pipelines/nightly-CI.yml b/.azure-pipelines/nightly-CI.yml index af3271b..797f5a3 100644 --- a/.azure-pipelines/nightly-CI.yml +++ b/.azure-pipelines/nightly-CI.yml @@ -32,17 +32,17 @@ jobs: - script: sudo install -d -m 0777 /home/vsts/.conda/envs displayName: Fix Conda permissions - - task: CondaEnvironment@1 + - task: UsePythonVersion@0 inputs: - createCustomEnvironment: true - environmentName: 'py$(python.version)' - packageSpecs: 'python=$(python.version)' + versionSpec: '$(python.version)' + addToPath: true + architecture: 'x64' + displayName: 'Use Python $(python.version)' - script: | python -m pip install --upgrade pip - conda config --set always_yes yes --set changeps1 no - conda install -c conda-forge protobuf - conda install -c conda-forge numpy + pip install protobuf + pip install numpy pip install -r requirements.txt # install ORT dependencies pip install onnxruntime @@ -52,6 +52,7 @@ jobs: pip install $(ONNX_PATH) pip install protobuf>=3.20.2 pip install pytest + pip install onnxmltools pip install -e . displayName: 'Install dependencies' @@ -62,7 +63,7 @@ jobs: - script: | python -c "import onnxconverter_common" - pytest tests --doctest-modules --junitxml=junit/test-results-onnxutils.xml + pytest tests --doctest-modules --junitxml=junit/test-results.xml displayName: 'pytest - onnxutils' - task: PublishTestResults@2 @@ -78,19 +79,19 @@ jobs: matrix: Python382: python.version: '3.8' - ONNX_PATH: onnx==1.8.0 + ONNX_PATH: onnx==1.13 Python391: python.version: '3.9' - ONNX_PATH: onnx==1.9.0 + ONNX_PATH: onnx==1.13 Python392: python.version: '3.9' - ONNX_PATH: onnx==1.10.2 + ONNX_PATH: onnx==1.13 Python310: python.version: '3.10' - ONNX_PATH: onnx==1.14.0 + ONNX_PATH: onnx==1.14 maxParallel: 4 @@ -100,14 +101,7 @@ jobs: versionSpec: '$(python.version)' architecture: 'x64' - - powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" - displayName: Add conda to PATH - - - script: conda create --yes --quiet --name py$(python.version) -c conda-forge python=$(python.version) numpy protobuf - displayName: Create Anaconda environment - - script: | - call activate py$(python.version) python -m pip install --upgrade pip numpy echo Test numpy installation... && python -c "import numpy" pip install -r requirements.txt @@ -119,18 +113,18 @@ jobs: pip install %ONNX_PATH% pip install protobuf>=3.20.2 pip install pytest + pip install onnxmltools pip install -e . displayName: 'Install dependencies' - script: | - call activate py$(python.version) pip install flake8 python -m flake8 onnxconverter_common displayName: 'run flake8 check' - script: | call activate py$(python.version) - pytest tests --doctest-modules --junitxml=junit/test-results-onnxutils.xml + pytest tests --doctest-modules --junitxml=junit/test-results.xml displayName: 'pytest - onnxutils' - task: PublishTestResults@2 From 7d8b4e9cfb860e4d24d636762719e7be6f4bd774 Mon Sep 17 00:00:00 2001 From: atinfinity Date: Tue, 2 Apr 2024 18:14:54 +0900 Subject: [PATCH 29/33] fixed typo (#233) Co-authored-by: xiaowuhu --- onnxconverter_common/perfstats.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/onnxconverter_common/perfstats.py b/onnxconverter_common/perfstats.py index 62361aa..cc04aa5 100644 --- a/onnxconverter_common/perfstats.py +++ b/onnxconverter_common/perfstats.py @@ -9,7 +9,7 @@ Script is standalone and can be downloaded and run as prefstats.py Ex: - python -m onnxconvert_common.perfstats -t -l 5 trace.json # List durations by optype + python -m onnxconverter_common.perfstats -t -l 5 trace.json # List durations by optype (or python perfstats.py -t -l 5 trace.json) Result: @@ -48,11 +48,11 @@ _HELP_TEXT = """ Usage Examples: -python -m onnxconvert_common.perfstats -t trace.json # List results by type -python -m onnxconvert_common.perfstats -n -l 10 trace.json # List top 10 nodes -python -m onnxconvert_common.perfstats -n trace.json -q t=Conv # List conv nodes -python -m onnxconvert_common.perfstats -n trace.json -q t!=Conv # List non-conv nodes -python -m onnxconvert_common.perfstats -n trace.json -q t=Conv;n!=NAME # List conv nodes except NAME +python -m onnxconverter_common.perfstats -t trace.json # List results by type +python -m onnxconverter_common.perfstats -n -l 10 trace.json # List top 10 nodes +python -m onnxconverter_common.perfstats -n trace.json -q t=Conv # List conv nodes +python -m onnxconverter_common.perfstats -n trace.json -q t!=Conv # List non-conv nodes +python -m onnxconverter_common.perfstats -n trace.json -q t=Conv;n!=NAME # List conv nodes except NAME """ From 53211b1d4ee75970a4ffe728f08e1535f9cd2df8 Mon Sep 17 00:00:00 2001 From: Tom Wildenhain <67606533+TomWildenhain-Microsoft@users.noreply.github.com> Date: Tue, 2 Apr 2024 02:21:08 -0700 Subject: [PATCH 30/33] Fix typo and block instance normalization for fp16 (#199) Co-authored-by: xiaowuhu --- onnxconverter_common/auto_mixed_precision.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxconverter_common/auto_mixed_precision.py b/onnxconverter_common/auto_mixed_precision.py index 1ffc632..6d474b4 100644 --- a/onnxconverter_common/auto_mixed_precision.py +++ b/onnxconverter_common/auto_mixed_precision.py @@ -4,7 +4,7 @@ ########################################################################### """ -This tool converts converts a model to mixed precision (float32->float16) while excluding nodes as needed to maintain +This tool converts a model to mixed precision (float32->float16) while excluding nodes as needed to maintain a certain accuracy. Example usage: From 18f795f599a4c15c6f54a5ef4e199c25ab7f4213 Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Tue, 2 Apr 2024 17:58:17 +0800 Subject: [PATCH 31/33] Update pyproject.toml (#284) Signed-off-by: xiaowuhu --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index bc22188..e7c458d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "License :: OSI Approved :: MIT License", ] -dependencies = ["numpy", "onnx", "packaging", "protobuf==3.20.2"] +dependencies = ["numpy", "onnx", "packaging", "protobuf>=3.20.2"] [tool.setuptools.dynamic] version = {attr = "onnxconverter_common.__version__"} From 741f937da91a88014ac69177676ddd02dcb1edbb Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Mon, 22 Apr 2024 18:57:11 +0800 Subject: [PATCH 32/33] Remove useless cast nodes in graph after converting to fp16 model (#286) * update * Update float16.py * Update float16.py * Update float16.py * remove comments * update * upgrade to 1.16 onnx Due to security issue * update * Update float16.py --- .github/workflows/linux-CI.yml | 8 +- .github/workflows/windows-CI.yml | 8 +- .vscode/launch.json | 16 ++++ onnxconverter_common/auto_mixed_precision.py | 6 +- onnxconverter_common/float16.py | 95 ++++++++++++++++++++ 5 files changed, 122 insertions(+), 11 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.github/workflows/linux-CI.yml b/.github/workflows/linux-CI.yml index 0b48b88..00e5fc5 100644 --- a/.github/workflows/linux-CI.yml +++ b/.github/workflows/linux-CI.yml @@ -21,11 +21,11 @@ jobs: python-version: ["3.8", "3.9", "3.10"] include: - python-version: "3.8" - onnx-version: 1.12.0 + onnx-version: 1.16 - python-version: "3.9" - onnx-version: 1.13 + onnx-version: 1.16 - python-version: "3.10" - onnx-version: 1.14.1 + onnx-version: 1.16 steps: @@ -39,7 +39,7 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - pip install onnxruntime==1.15 + pip install onnxruntime pip install onnxmltools pip install onnx==${{ matrix.onnx-version }} pip install -e . diff --git a/.github/workflows/windows-CI.yml b/.github/workflows/windows-CI.yml index 467706d..786bc12 100644 --- a/.github/workflows/windows-CI.yml +++ b/.github/workflows/windows-CI.yml @@ -21,11 +21,11 @@ jobs: python-version: ["3.8", "3.9", "3.10"] include: - python-version: "3.8" - onnx-version: 1.12.0 + onnx-version: 1.16 - python-version: "3.9" - onnx-version: 1.13 + onnx-version: 1.16 - python-version: "3.10" - onnx-version: 1.14.1 + onnx-version: 1.16 steps: - uses: actions/checkout@v4 @@ -37,7 +37,7 @@ jobs: run: | python -m pip install --upgrade pip pip install flake8 pytest - pip install onnxruntime==1.15 + pip install onnxruntime pip install onnxmltools pip install onnx==${{ matrix.onnx-version }} pip install -e . diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..969d736 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": false + } + ] +} \ No newline at end of file diff --git a/onnxconverter_common/auto_mixed_precision.py b/onnxconverter_common/auto_mixed_precision.py index 6d474b4..da422be 100644 --- a/onnxconverter_common/auto_mixed_precision.py +++ b/onnxconverter_common/auto_mixed_precision.py @@ -77,9 +77,6 @@ def run_attempt(node_block_list, return_model=False): print(valid) return valid - if not run_attempt(node_names): - raise ValueError("validation failed for model with all nodes in node_block_list") - print("Sanity checks passed. Starting autoconvert.") segments = SegmentList(node_names) i = 0 while segments.get_largest() is not None: @@ -129,6 +126,9 @@ def get_tensor_values_using_ort(model, input_feed, output_names=None, sess_optio # delayed import to avoid taking a strong dependancy on onnxruntime import onnxruntime as ort if output_names is None: + # Below code is for debug only, keep it for next time use + # sess_options = ort.SessionOptions() + # sess_options.optimized_model_filepath = "d:/optimized_model.onnx" sess = ort.InferenceSession(model.SerializeToString(), sess_options, providers=['CUDAExecutionProvider']) return sess.run(None, input_feed) original_outputs = list(model.graph.output) diff --git a/onnxconverter_common/float16.py b/onnxconverter_common/float16.py index a63572f..b2291d2 100644 --- a/onnxconverter_common/float16.py +++ b/onnxconverter_common/float16.py @@ -302,6 +302,7 @@ def convert_float_to_float16(model, min_positive_val=1e-7, max_finite_val=1e4, break sort_topology(model.graph) + remove_unnecessary_cast_node(model.graph) return model @@ -388,3 +389,97 @@ def sort_topology(graph_proto): for g in attr.graphs: if isinstance(g, onnx_proto.GraphProto): sort_topology(g) # sort sub-graph + + +def remove_unnecessary_cast_node(graph_proto): + # 1. find all cast nodes in the graph + cast_node_list = [] + input_name_to_cast_node_dict = {} + output_name_to_cast_node_dict = {} + # using name as key to point to a node. because node cannot be key + name_to_node_dict = {} + for node in graph_proto.node: + if node.op_type == 'Cast': + if node.name not in ["graph_input_cast0", "graph_output_cast0"]: + cast_node_list.append(node) + + name_to_node_dict[node.name] = node + for input_name in node.input: + input_name_to_cast_node_dict[input_name] = node + for output_name in node.output: + output_name_to_cast_node_dict[output_name] = node + + # 2. find upstream and downstream node of the cast node + cast_node_upstream_dict = {} # mapping cast node(name) to its upstream node + cast_node_downstream_dict = {} # mapping cast node(name) to its downstream node + for current_node in graph_proto.node: + # find the downstream node(s) + for input_name in current_node.input: + if input_name in output_name_to_cast_node_dict: + # found the downstream node of the cast node, might be multiple + cast_node = output_name_to_cast_node_dict[input_name] + if cast_node.name not in cast_node_downstream_dict: + cast_node_downstream_dict[cast_node.name] = current_node + else: # already exists one downstream node, make it a list + existing_downstream_nodes = cast_node_downstream_dict[cast_node.name] + if isinstance(existing_downstream_nodes, list): + existing_downstream_nodes.append(current_node) + else: # make a list + existing_downstream_nodes = [existing_downstream_nodes, current_node] + cast_node_downstream_dict[cast_node.name] = existing_downstream_nodes + # find the upstream node + for output_name in current_node.output: + if output_name in input_name_to_cast_node_dict: + # found the upstream node of the cast node, should be unique + cast_node = input_name_to_cast_node_dict[output_name] + cast_node_upstream_dict[cast_node.name] = current_node + + # 3. remove the cast node which upstream is 'Constant' + for cast_node_name, upstream_node in cast_node_upstream_dict.items(): + cast_node = name_to_node_dict[cast_node_name] + if upstream_node.op_type == 'Constant': + cast_node_list.remove(cast_node) + + # 4. find the cast(to16) node which downstream is Cast(to32) + remove_candidate = [] + for cast_node_name, downstream_node in cast_node_downstream_dict.items(): + cast_node = name_to_node_dict[cast_node_name] + if isinstance(downstream_node, list): + for dn in downstream_node: + if dn.op_type == 'Cast' and \ + dn.attribute[0].i == 32 and \ + cast_node.attribute[0].i == 16 and \ + dn in cast_node_list and \ + cast_node in cast_node_list: + remove_candidate.append((cast_node, dn)) + else: + if downstream_node.op_type == 'Cast' and \ + cast_node.attribute[0].i == 10 and \ + downstream_node.attribute[0].i == 1 and \ + downstream_node in cast_node_list and \ + cast_node in cast_node_list: + remove_candidate.append((cast_node, downstream_node)) + + # 5. change the connection of "upstream->cast16->cast32->downstream" to "upstream->downstream" + for cast_node_pair in remove_candidate: + first_cast_node = cast_node_pair[0] + second_cast_node = cast_node_pair[1] + upstream_node = cast_node_upstream_dict[first_cast_node.name] + downstream_node = cast_node_downstream_dict[second_cast_node.name] + # find the upstream node's output to first_cast_node + out = None + for output_name in upstream_node.output: + if output_name == first_cast_node.input[0]: + out = output_name + break + # find the downstream node's input as second_cast_node's output + for i, input_name in enumerate(downstream_node.input): + for output_name in second_cast_node.output: + if input_name == output_name: + # change the input as the upstream node's output + downstream_node.input[i] = out + + # 6. remove the cast node pair + for cast_node_pair in remove_candidate: + graph_proto.node.remove(cast_node_pair[0]) + graph_proto.node.remove(cast_node_pair[1]) From efc2b673930a01dc1120c908327a9aa84a8c271a Mon Sep 17 00:00:00 2001 From: xiaowuhu Date: Mon, 13 May 2024 17:14:38 +0800 Subject: [PATCH 33/33] Fix fp16 converter bug (#288) * update the change * Update __init__.py --- README.md | 4 ++++ onnxconverter_common/__init__.py | 2 +- requirements.txt | 4 +--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 14dc132..6b463d0 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,7 @@ provided by the bot. You will only need to do this once across all repos using o This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + +# Document + +Please reference the simple [document](https://onnxruntime.ai/docs/performance/model-optimizations/float16.html) here. diff --git a/onnxconverter_common/__init__.py b/onnxconverter_common/__init__.py index 146bf5d..b4de8b1 100644 --- a/onnxconverter_common/__init__.py +++ b/onnxconverter_common/__init__.py @@ -8,7 +8,7 @@ This framework performs optimization for ONNX models and includes common utilities for ONNX converters. """ -__version__ = "1.14.0" +__version__ = "1.16.0" __author__ = "Microsoft" __producer__ = "OnnxMLTools" __producer_version__ = __version__ diff --git a/requirements.txt b/requirements.txt index 4e27326..3d3395b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,2 @@ -numpy -onnx +onnx>=1.16 packaging -protobuf>=3.20.2