From 9bcef5e3c3bfa2c83a4f06b1a55b620278ec7b2d Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Mon, 30 Dec 2024 03:23:46 +0000 Subject: [PATCH 01/26] Try tf 2.18.0 version. Signed-off-by: Jay Zhang --- .github/actions/keras_application_test/action.yml | 3 +++ .github/actions/keras_unit_test/action.yml | 2 ++ .github/actions/unit_test/action.yml | 2 ++ .github/workflows/keras_application_test_ci.yml | 6 +++--- .github/workflows/keras_unit_test_ci.yml | 6 +++--- .github/workflows/pretrained_model_test_ci.yml | 6 +++--- .github/workflows/unit_test_ci.yml | 6 +++--- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index e22d0ad8e..e7e725e03 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -58,6 +58,7 @@ runs: pip install numpy==1.19.0 else pip install transformers + pip install tf_keras pip install "numpy<2" fi @@ -71,5 +72,7 @@ runs: run: | python -c "import onnxruntime" pytest tests/keras2onnx_unit_tests --doctest-modules --junitxml=junit/test-results.xml + + export TF_USE_LEGACY_KERAS=True cd tests/keras2onnx_applications/nightly_build python run_all_v2.py diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index 4c78945f1..4ba0aea8b 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -36,6 +36,7 @@ runs: if [[ ${{ inputs.tf_version }} == 1.* ]]; then pip install numpy==1.19.0 else + pip install tf_keras pip install "numpy<2" fi @@ -48,6 +49,7 @@ runs: shell: bash if: runner.os == 'Linux' run: | + export TF_USE_LEGACY_KERAS=True python -c "import onnxruntime" python -c "import onnxconverter_common" pytest tests/keras2onnx_unit_tests --doctest-modules --junitxml=junit/test-results.xml diff --git a/.github/actions/unit_test/action.yml b/.github/actions/unit_test/action.yml index 00cb28386..ebcad6c80 100644 --- a/.github/actions/unit_test/action.yml +++ b/.github/actions/unit_test/action.yml @@ -46,6 +46,7 @@ runs: export TF2ONNX_SKIP_TFLITE_TESTS=${{ inputs.skip_tflite }} export TF2ONNX_SKIP_TFJS_TESTS=True export TF2ONNX_SKIP_TF_TESTS=False + export TF_USE_LEGACY_KERAS=True python -m pytest --cov=tf2onnx --cov-report=term --disable-pytest-warnings -r s tests --cov-append --junitxml=junit/test-results.xml ls @@ -58,5 +59,6 @@ runs: set TF2ONNX_SKIP_TFLITE_TESTS=${{ inputs.skip_tflite }} set TF2ONNX_SKIP_TFJS_TESTS=True set TF2ONNX_SKIP_TF_TESTS=False + set TF_USE_LEGACY_KERAS=True python -m pytest --cov=tf2onnx --cov-report=term --disable-pytest-warnings -r s tests --cov-append --junitxml=junit/test-results.xml ls diff --git a/.github/workflows/keras_application_test_ci.yml b/.github/workflows/keras_application_test_ci.yml index 1529cbc75..d0dd69c3d 100644 --- a/.github/workflows/keras_application_test_ci.yml +++ b/.github/workflows/keras_application_test_ci.yml @@ -48,10 +48,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Run Tests (Py310-TF2.15) + - name: Run Tests (Py310-TF2.18) uses: ./.github/actions/keras_application_test with: - tf_version: '2.15.0' + tf_version: '2.18.0' python_version: '3.10' ort_version: '1.16.3' onnx_version: '1.16.1' @@ -60,7 +60,7 @@ jobs: if: always() uses: actions/upload-artifact@v3 with: - name: Test Results (Py310-TF2.15-ubuntu) + name: Test Results (Py310-TF2.18-ubuntu) path: ./**/test-results-*.xml Test_py37_with_tf1_15: # Do not change this name because it is used in Ruleset of this repo. diff --git a/.github/workflows/keras_unit_test_ci.yml b/.github/workflows/keras_unit_test_ci.yml index b6702698c..0c2d2e090 100644 --- a/.github/workflows/keras_unit_test_ci.yml +++ b/.github/workflows/keras_unit_test_ci.yml @@ -47,10 +47,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Run Tests (Py310-TF2.15) + - name: Run Tests (Py310-TF2.18) uses: ./.github/actions/keras_unit_test with: - tf_version: '2.15.0' + tf_version: '2.18.0' python_version: '3.10' ort_version: '1.16.3' onnx_version: '1.16.1' @@ -59,7 +59,7 @@ jobs: if: always() uses: actions/upload-artifact@v3 with: - name: Test Results (Py310-TF2.15-ubuntu) + name: Test Results (Py310-TF2.18-ubuntu) path: ./**/test-results-*.xml Test_py37_with_tf1_15: # Do not change this name because it is used in Ruleset of this repo. diff --git a/.github/workflows/pretrained_model_test_ci.yml b/.github/workflows/pretrained_model_test_ci.yml index 96077d68a..34c31d624 100644 --- a/.github/workflows/pretrained_model_test_ci.yml +++ b/.github/workflows/pretrained_model_test_ci.yml @@ -51,11 +51,11 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Run Tests (Py310-TF2.15-18) + - name: Run Tests (Py310-TF2.18-18) uses: ./.github/actions/pretrained_model_test with: os: 'ubuntu-latest' - tf_version: '2.15.0' + tf_version: '2.18.0' python_version: '3.10' ort_version: '1.16.3' onnx_version: '1.16.1' @@ -66,7 +66,7 @@ jobs: if: always() uses: actions/upload-artifact@v3 with: - name: Test Results (Py310-TF2.15-18-ubuntu) + name: Test Results (Py310-TF2.18-18-ubuntu) path: ./**/test-results-*.xml Test_py37_with_tf1_15: # Do not change this name because it is used in 'publish-test-results' section below. diff --git a/.github/workflows/unit_test_ci.yml b/.github/workflows/unit_test_ci.yml index bdfae9277..46d03a9de 100644 --- a/.github/workflows/unit_test_ci.yml +++ b/.github/workflows/unit_test_ci.yml @@ -51,11 +51,11 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Run Tests (Py310-TF2.15-18) + - name: Run Tests (Py310-TF2.18-18) uses: ./.github/actions/unit_test with: os: 'ubuntu-latest' - tf_version: '2.15.0' + tf_version: '2.18.0' python_version: '3.10' ort_version: '1.16.3' onnx_version: '1.16.1' @@ -66,7 +66,7 @@ jobs: if: always() uses: actions/upload-artifact@v3 with: - name: Test Results (Py310-TF2.15-18-ubuntu) + name: Test Results (Py310-TF2.18-18-ubuntu) path: ./**/test-results-*.xml Extra_tests: From 6d1f7892bbb17122a1505df12d0a46dde43f0fd0 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Mon, 30 Dec 2024 05:09:50 +0000 Subject: [PATCH 02/26] Call tf_keras for keras 3.x. Signed-off-by: Jay Zhang --- tests/keras2onnx_unit_tests/conftest.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/keras2onnx_unit_tests/conftest.py b/tests/keras2onnx_unit_tests/conftest.py index 758c31f7f..4745d1f86 100644 --- a/tests/keras2onnx_unit_tests/conftest.py +++ b/tests/keras2onnx_unit_tests/conftest.py @@ -13,6 +13,12 @@ K = keras.backend +def is_keras_3(): + if hasattr(keras, '__version__'): + return keras.__version__.startswith("3.") + + return False + @pytest.fixture(scope='function') def runner(): np.random.seed(42) @@ -25,10 +31,15 @@ def runner(): def runner_func(*args, **kwargs): return run_onnx_runtime(*args, model_files, **kwargs) - # Ensure Keras layer naming is reset for each function - K.reset_uids() - # Reset the TensorFlow session to avoid resource leaking between tests - K.clear_session() + if is_keras_3(): + import tf_keras + tf_keras.backend.reset_uids() + tf_keras.backend.clear_session() + else: + # Ensure Keras layer naming is reset for each function + K.reset_uids() + # Reset the TensorFlow session to avoid resource leaking between tests + K.clear_session() # Provide wrapped run_onnx_runtime function yield runner_func From b75fe783256695dc48c3c412ffe52396d5b50b03 Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Tue, 31 Dec 2024 05:18:50 +0000 Subject: [PATCH 03/26] Check output_names attr as well. Signed-off-by: Jay Zhang --- tf2onnx/convert.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tf2onnx/convert.py b/tf2onnx/convert.py index 6ee66c096..f7ec42add 100644 --- a/tf2onnx/convert.py +++ b/tf2onnx/convert.py @@ -328,7 +328,8 @@ def _rename_duplicate_keras_model_names(model): IMPORTANT: model may be edited. Assign model.output_names to old_out_names to restore. """ old_out_names = None - if model.output_names and len(set(model.output_names)) != len(model.output_names): + if hasattr(model, "output_names") and model.output_names \ + and len(set(model.output_names)) != len(model.output_names): # In very rare cases, keras has a bug where it will give multiple outputs the same name # We must edit the model or the TF trace will fail old_out_names = model.output_names From b2340517dbd7c06018d2c663603e9dc70940e764 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 15:11:38 +0100 Subject: [PATCH 04/26] improve ci Signed-off-by: xadupre --- .../workflows/keras_application_test_ci.yml | 6 +- .github/workflows/keras_unit_test_ci.yml | 54 ++++++++++++++++- .../workflows/pretrained_model_test_ci.yml | 33 +++++++++- .github/workflows/unit_test_ci.yml | 60 ++++++++++++++++++- 4 files changed, 141 insertions(+), 12 deletions(-) diff --git a/.github/workflows/keras_application_test_ci.yml b/.github/workflows/keras_application_test_ci.yml index e5940f0e6..d8325ceeb 100644 --- a/.github/workflows/keras_application_test_ci.yml +++ b/.github/workflows/keras_application_test_ci.yml @@ -15,7 +15,7 @@ concurrency: jobs: - Test_min_py_with_min_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_min_py38_with_min_tf: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -39,7 +39,7 @@ jobs: name: Test Results (Py38-TF2.9-ubuntu) path: ./**/test-results-*.xml - Test_max_py_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_max_py310_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -126,7 +126,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test_min_py_with_min_tf, Test_max_py_with_latest_tf, Test_py37_with_tf1_15, Extra_tests] + needs: [Test_min_py38_with_min_tf, Test_max_py310_with_latest_tf, Test_py37_with_tf1_15, Extra_tests] runs-on: ubuntu-latest permissions: checks: write diff --git a/.github/workflows/keras_unit_test_ci.yml b/.github/workflows/keras_unit_test_ci.yml index 36a33234e..e23add741 100644 --- a/.github/workflows/keras_unit_test_ci.yml +++ b/.github/workflows/keras_unit_test_ci.yml @@ -14,7 +14,7 @@ concurrency: cancel-in-progress: true jobs: - Test_min_py_with_min_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_min_py38_with_min_tf: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -38,7 +38,7 @@ jobs: name: Test Results (Py38-TF2.9-ubuntu) path: ./**/test-results-*.xml - Test_max_py_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_max_py310_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -62,6 +62,54 @@ jobs: name: Test Results (Py310-TF2.18-ubuntu) path: ./**/test-results-*.xml + Test_max_py311_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + strategy: + fail-fast: false + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run Tests (Py311-TF2.18) + uses: ./.github/actions/keras_unit_test + with: + tf_version: '2.18.0' + python_version: '3.11' + ort_version: '1.20.1' + onnx_version: '1.17.0' + + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v4 + with: + name: Test Results (Py311-TF2.18-ubuntu) + path: ./**/test-results-*.xml + + Test_max_py312_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + strategy: + fail-fast: false + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run Tests (Py312-TF2.18) + uses: ./.github/actions/keras_unit_test + with: + tf_version: '2.18.0' + python_version: '3.12' + ort_version: '1.20.1' + onnx_version: '1.17.0' + + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v4 + with: + name: Test Results (Py312-TF2.18-ubuntu) + path: ./**/test-results-*.xml + Test_py37_with_tf1_15: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false @@ -125,7 +173,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test_min_py_with_min_tf, Test_max_py_with_latest_tf, Test_py37_with_tf1_15, Extra_tests] + needs: [Test_min_py38_with_min_tf, Test_max_py310_with_latest_tf, Test_max_py311_with_latest_tf, Test_max_py312_with_latest_tf, Test_py37_with_tf1_15, Extra_tests] runs-on: ubuntu-latest permissions: checks: write diff --git a/.github/workflows/pretrained_model_test_ci.yml b/.github/workflows/pretrained_model_test_ci.yml index 3c2fadcb0..f194b411d 100644 --- a/.github/workflows/pretrained_model_test_ci.yml +++ b/.github/workflows/pretrained_model_test_ci.yml @@ -15,7 +15,7 @@ concurrency: jobs: - Test_min_py_with_min_tf: # Do not change this name because it is used in 'publish-test-results' section below. + Test_min_py38_with_min_tf: # Do not change this name because it is used in 'publish-test-results' section below. strategy: fail-fast: false runs-on: ubuntu-latest @@ -42,7 +42,7 @@ jobs: name: Test Results (Py38-TF2.9-18-ubuntu) path: ./**/test-results-*.xml - Test_max_py_with_latest_tf: # Do not change this name because it is used in 'publish-test-results' section below. + Test_max_py310_with_latest_tf: # Do not change this name because it is used in 'publish-test-results' section below. strategy: fail-fast: false runs-on: ubuntu-latest @@ -69,6 +69,33 @@ jobs: name: Test Results (Py310-TF2.18-18-ubuntu) path: ./**/test-results-*.xml + Test_max_py312_with_latest_tf: # Do not change this name because it is used in 'publish-test-results' section below. + strategy: + fail-fast: false + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run Tests (Py312-TF2.18-18) + uses: ./.github/actions/pretrained_model_test + with: + os: 'ubuntu-latest' + tf_version: '2.18.0' + python_version: '3.12' + ort_version: '1.20.1' + onnx_version: '1.17.0' + opset_version: '18' + skip_tflite: 'False' + + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v4 + with: + name: Test Results (Py312-TF2.18-18-ubuntu) + path: ./**/test-results-*.xml + Test_py37_with_tf1_15: # Do not change this name because it is used in 'publish-test-results' section below. strategy: fail-fast: false @@ -139,7 +166,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test_min_py_with_min_tf, Test_max_py_with_latest_tf, Test_py37_with_tf1_15, Extra_tests] + needs: [Test_min_py38_with_min_tf, Test_max_py310_with_latest_tf, Test_max_py312_with_latest_tf, Test_py37_with_tf1_15, Extra_tests] runs-on: ubuntu-latest permissions: checks: write diff --git a/.github/workflows/unit_test_ci.yml b/.github/workflows/unit_test_ci.yml index a49c84bdf..61f443de2 100644 --- a/.github/workflows/unit_test_ci.yml +++ b/.github/workflows/unit_test_ci.yml @@ -15,7 +15,7 @@ concurrency: jobs: - Test_min_py_with_min_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_min_py38_with_min_tf: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -42,7 +42,7 @@ jobs: name: Test Results (Py38-TF2.9-18-ubuntu) path: ./**/test-results-*.xml - Test_max_py_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_max_py310_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -69,6 +69,60 @@ jobs: name: Test Results (Py310-TF2.18-18-ubuntu) path: ./**/test-results-*.xml + Test_max_py311_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + strategy: + fail-fast: false + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run Tests (Py311-TF2.18-18) + uses: ./.github/actions/unit_test + with: + os: 'ubuntu-latest' + tf_version: '2.18.0' + python_version: '3.11' + ort_version: '1.20.1' + onnx_version: '1.17.0' + opset_version: '18' + skip_tflite: 'False' + + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v4 + with: + name: Test Results (Py311-TF2.18-18-ubuntu) + path: ./**/test-results-*.xml + + Test_max_py312_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + strategy: + fail-fast: false + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run Tests (Py312-TF2.18-18) + uses: ./.github/actions/unit_test + with: + os: 'ubuntu-latest' + tf_version: '2.18.0' + python_version: '3.12' + ort_version: '1.20.1' + onnx_version: '1.17.0' + opset_version: '18' + skip_tflite: 'False' + + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v4 + with: + name: Test Results (Py312-TF2.18-18-ubuntu) + path: ./**/test-results-*.xml + Extra_tests: strategy: fail-fast: false @@ -122,7 +176,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test_min_py_with_min_tf, Test_max_py_with_latest_tf, Extra_tests] + needs: [Test_min_py38_with_min_tf, Test_max_py310_with_latest_tf, Test_max_py311_with_latest_tf, Test_max_py312_with_latest_tf, Extra_tests] runs-on: ubuntu-latest permissions: checks: write From 547557454ee22799f653e8d58470db654f8e6c19 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 15:23:29 +0100 Subject: [PATCH 05/26] update ci Signed-off-by: xadupre --- .github/actions/keras_application_test/action.yml | 3 +-- .github/actions/keras_unit_test/action.yml | 3 +-- .github/workflows/pylint.yml | 2 +- .github/workflows/unit_test_ci.yml | 12 ++++++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index e7e725e03..f19a94cc9 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -58,8 +58,7 @@ runs: pip install numpy==1.19.0 else pip install transformers - pip install tf_keras - pip install "numpy<2" + pip install tf_keras==${{ inputs.tf_version }} fi pip install -e . diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index 4ba0aea8b..30b8a2342 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -36,8 +36,7 @@ runs: if [[ ${{ inputs.tf_version }} == 1.* ]]; then pip install numpy==1.19.0 else - pip install tf_keras - pip install "numpy<2" + pip install tf_keras==${{ inputs.tf_version }} fi pip install -e . diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index ac5631aa3..e8b8e0862 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: 3.9 # Specify the desired Python version (e.g., 3.8, 3.9) + python-version: 3.11 - name: Install dependencies run: pip install pylint==2.4.4 diff --git a/.github/workflows/unit_test_ci.yml b/.github/workflows/unit_test_ci.yml index 61f443de2..7ec3da5e6 100644 --- a/.github/workflows/unit_test_ci.yml +++ b/.github/workflows/unit_test_ci.yml @@ -130,12 +130,24 @@ jobs: name: - 'py38-tf2.13' - 'py39-tf2.15' + - 'py310-tf2.18' + - 'py311-tf2.18' + - 'py312-tf2.18' os: ['ubuntu-latest', 'windows-2022'] opset_version: ['18', '15'] ort_version: ['1.16.3'] onnx_version: ['1.16.1'] skip_tflite: ['False'] include: + - name: 'py312-tf2.18' + tf_version: '2.18.0' + python_version: '3.12' + - name: 'py311-tf2.18' + tf_version: '2.18.0' + python_version: '3.11' + - name: 'py310-tf2.18' + tf_version: '2.18.0' + python_version: '3.10' - name: 'py38-tf2.13' tf_version: '2.13.0' python_version: '3.8' From 177b3dea60a2f278a49c8dcb80f15218314f6090 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 15:30:11 +0100 Subject: [PATCH 06/26] ci Signed-off-by: xadupre --- .github/actions/keras_application_test/action.yml | 2 +- .github/actions/keras_unit_test/action.yml | 2 +- .github/workflows/keras_application_test_ci.yml | 12 ++++++------ .github/workflows/keras_unit_test_ci.yml | 12 ++++++------ .github/workflows/pretrained_model_test_ci.yml | 12 ++++++------ .github/workflows/unit_test_ci.yml | 12 ++++++------ README.md | 6 +++--- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index f19a94cc9..1ed8c9e69 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -26,7 +26,7 @@ runs: pip install onnx==${{ inputs.onnx_version }} pip uninstall -y protobuf pip install "protobuf~=3.20" - pip install h5py==3.7.0 + pip install h5py pip install parameterized pip install timeout-decorator pip install coloredlogs flatbuffers diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index 30b8a2342..b63b85f16 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -24,7 +24,7 @@ runs: python -m pip install --upgrade pip pip install onnxconverter-common pip install onnx==${{ inputs.onnx_version }} - pip install h5py==3.7.0 + pip install h5py pip install parameterized pip install timeout-decorator pip install coloredlogs flatbuffers diff --git a/.github/workflows/keras_application_test_ci.yml b/.github/workflows/keras_application_test_ci.yml index d8325ceeb..195f856b5 100644 --- a/.github/workflows/keras_application_test_ci.yml +++ b/.github/workflows/keras_application_test_ci.yml @@ -29,8 +29,8 @@ jobs: with: tf_version: '2.9.0' python_version: '3.8' - ort_version: '1.16.3' - onnx_version: '1.16.1' + ort_version: '1.20.1' + onnx_version: '1.17.0' - name: Upload Test Results if: always() @@ -53,8 +53,8 @@ jobs: with: tf_version: '2.18.0' python_version: '3.10' - ort_version: '1.16.3' - onnx_version: '1.16.1' + ort_version: '1.20.1' + onnx_version: '1.17.0' - name: Upload Test Results if: always() @@ -95,8 +95,8 @@ jobs: - 'py38-tf2.13' - 'py39-tf2.15' os: ['ubuntu-latest', 'windows-2022'] - ort_version: ['1.16.3'] - onnx_version: ['1.16.1'] + ort_version: ['1.20.1'] + onnx_version: ['1.17.0'] include: - name: 'py38-tf2.13' tf_version: '2.13.0' diff --git a/.github/workflows/keras_unit_test_ci.yml b/.github/workflows/keras_unit_test_ci.yml index e23add741..dbff972ce 100644 --- a/.github/workflows/keras_unit_test_ci.yml +++ b/.github/workflows/keras_unit_test_ci.yml @@ -28,8 +28,8 @@ jobs: with: tf_version: '2.9.0' python_version: '3.8' - ort_version: '1.16.3' - onnx_version: '1.16.1' + ort_version: '1.20.1' + onnx_version: '1.17.0' - name: Upload Test Results if: always() @@ -52,8 +52,8 @@ jobs: with: tf_version: '2.18.0' python_version: '3.10' - ort_version: '1.16.3' - onnx_version: '1.16.1' + ort_version: '1.20.1' + onnx_version: '1.17.0' - name: Upload Test Results if: always() @@ -142,8 +142,8 @@ jobs: - 'py39-tf2.10' - 'py39-tf2.15' os: ['ubuntu-latest', 'windows-2022'] - ort_version: ['1.16.3'] - onnx_version: ['1.16.1'] + ort_version: ['1.20.1'] + onnx_version: ['1.17.0'] include: - name: 'py39-tf2.10' tf_version: '2.10.0' diff --git a/.github/workflows/pretrained_model_test_ci.yml b/.github/workflows/pretrained_model_test_ci.yml index f194b411d..6303f5d1a 100644 --- a/.github/workflows/pretrained_model_test_ci.yml +++ b/.github/workflows/pretrained_model_test_ci.yml @@ -30,8 +30,8 @@ jobs: os: 'ubuntu-latest' tf_version: '2.9.0' python_version: '3.8' - ort_version: '1.16.3' - onnx_version: '1.16.1' + ort_version: '1.20.1' + onnx_version: '1.17.0' opset_version: '18' skip_tflite: 'False' @@ -57,8 +57,8 @@ jobs: os: 'ubuntu-latest' tf_version: '2.18.0' python_version: '3.10' - ort_version: '1.16.3' - onnx_version: '1.16.1' + ort_version: '1.20.1' + onnx_version: '1.17.0' opset_version: '18' skip_tflite: 'False' @@ -131,8 +131,8 @@ jobs: - 'py39-tf2.15' os: ['ubuntu-latest', 'windows-2022'] opset_version: ['18', '15'] - ort_version: ['1.16.3'] - onnx_version: ['1.16.1'] + ort_version: ['1.20.1'] + onnx_version: ['1.17.0'] skip_tflite: ['False'] include: - name: 'py38-tf2.13' diff --git a/.github/workflows/unit_test_ci.yml b/.github/workflows/unit_test_ci.yml index 7ec3da5e6..00f175d99 100644 --- a/.github/workflows/unit_test_ci.yml +++ b/.github/workflows/unit_test_ci.yml @@ -30,8 +30,8 @@ jobs: os: 'ubuntu-latest' tf_version: '2.9.0' python_version: '3.8' - ort_version: '1.16.3' - onnx_version: '1.16.1' + ort_version: '1.20.1' + onnx_version: '1.17.0' opset_version: '18' skip_tflite: 'False' @@ -57,8 +57,8 @@ jobs: os: 'ubuntu-latest' tf_version: '2.18.0' python_version: '3.10' - ort_version: '1.16.3' - onnx_version: '1.16.1' + ort_version: '1.20.1' + onnx_version: '1.17.0' opset_version: '18' skip_tflite: 'False' @@ -135,8 +135,8 @@ jobs: - 'py312-tf2.18' os: ['ubuntu-latest', 'windows-2022'] opset_version: ['18', '15'] - ort_version: ['1.16.3'] - onnx_version: ['1.16.1'] + ort_version: ['1.20.1'] + onnx_version: ['1.17.0'] skip_tflite: ['False'] include: - name: 'py312-tf2.18' diff --git a/README.md b/README.md index 719b99e1b..a2feaa929 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ The common issues we run into we try to document here [Troubleshooting Guide](Tr | Build Type | OS | Python | TensorFlow | ONNX opset | Status | | --- | --- | --- | --- | --- | --- | -| Unit Test - Basic | Linux, Windows | 3.7-3.10 | 1.15, 2.9-2.15 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=16&branchName=main) | -| Unit Test - Full | Linux, Windows | 3.7-3.10 | 1.15, 2.9-2.15 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test-matrix?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=18&branchName=main) | | +| Unit Test - Basic | Linux, Windows | 3.7-3.12 | 1.15, 2.9-2.15 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=16&branchName=main) | +| Unit Test - Full | Linux, Windows | 3.7-3.12 | 1.15, 2.9-2.15 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test-matrix?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=18&branchName=main) | |
## Supported Versions @@ -42,7 +42,7 @@ You can install tf2onnx on top of tf-1.x or tf-2.x. ### Python -We support Python ```3.7-3.10```. +We support Python ```3.7-3.12```. ## Prerequisites From c1cc37ba946e2b888c5d13e143654d414a6efbfe Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 15:44:06 +0100 Subject: [PATCH 07/26] ci Signed-off-by: xadupre --- .../workflows/keras_application_test_ci.yml | 28 ++++++++++++++++--- .github/workflows/keras_unit_test_ci.yml | 4 +-- .../workflows/pretrained_model_test_ci.yml | 28 ++++++++++++++++--- .github/workflows/pylint.yml | 2 +- .github/workflows/unit_test_ci.yml | 16 ++++++++--- tests/utils/setup_test_env.sh | 17 +++++------ 6 files changed, 70 insertions(+), 25 deletions(-) diff --git a/.github/workflows/keras_application_test_ci.yml b/.github/workflows/keras_application_test_ci.yml index 195f856b5..4c5187f6b 100644 --- a/.github/workflows/keras_application_test_ci.yml +++ b/.github/workflows/keras_application_test_ci.yml @@ -29,8 +29,8 @@ jobs: with: tf_version: '2.9.0' python_version: '3.8' - ort_version: '1.20.1' - onnx_version: '1.17.0' + ort_version: '1.16.3' + onnx_version: '1.16.1' - name: Upload Test Results if: always() @@ -94,16 +94,36 @@ jobs: name: - 'py38-tf2.13' - 'py39-tf2.15' + - 'py310-tf2.18' + - 'py311-tf2.18' + - 'py312-tf2.18' os: ['ubuntu-latest', 'windows-2022'] - ort_version: ['1.20.1'] - onnx_version: ['1.17.0'] include: - name: 'py38-tf2.13' tf_version: '2.13.0' python_version: '3.8' + ort_version: '1.16.3' + onnx_version: '1.16.1' - name: 'py39-tf2.15' tf_version: '2.15.0' python_version: '3.9' + ort_version: '1.16.3' + onnx_version: '1.16.1' + - name: 'py310-tf2.18' + tf_version: '2.18.0' + python_version: '3.10' + ort_version: '1.20.1' + onnx_version: '1.17.0' + - name: 'py311-tf2.18' + tf_version: '2.18.0' + python_version: '3.11' + ort_version: '1.20.1' + onnx_version: '1.17.0' + - name: 'py312-tf2.18' + tf_version: '2.18.0' + python_version: '3.12' + ort_version: '1.20.1' + onnx_version: '1.17.0' runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/keras_unit_test_ci.yml b/.github/workflows/keras_unit_test_ci.yml index dbff972ce..7d2154ca9 100644 --- a/.github/workflows/keras_unit_test_ci.yml +++ b/.github/workflows/keras_unit_test_ci.yml @@ -28,8 +28,8 @@ jobs: with: tf_version: '2.9.0' python_version: '3.8' - ort_version: '1.20.1' - onnx_version: '1.17.0' + ort_version: '1.16.3' + onnx_version: '1.16.1' - name: Upload Test Results if: always() diff --git a/.github/workflows/pretrained_model_test_ci.yml b/.github/workflows/pretrained_model_test_ci.yml index 6303f5d1a..7a48a5b86 100644 --- a/.github/workflows/pretrained_model_test_ci.yml +++ b/.github/workflows/pretrained_model_test_ci.yml @@ -30,8 +30,8 @@ jobs: os: 'ubuntu-latest' tf_version: '2.9.0' python_version: '3.8' - ort_version: '1.20.1' - onnx_version: '1.17.0' + ort_version: '1.16.3' + onnx_version: '1.16.1' opset_version: '18' skip_tflite: 'False' @@ -129,18 +129,38 @@ jobs: name: - 'py38-tf2.13' - 'py39-tf2.15' + - 'py310-tf2.18' + - 'py311-tf2.18' + - 'py312-tf2.18' os: ['ubuntu-latest', 'windows-2022'] opset_version: ['18', '15'] - ort_version: ['1.20.1'] - onnx_version: ['1.17.0'] skip_tflite: ['False'] include: - name: 'py38-tf2.13' tf_version: '2.13.0' python_version: '3.8' + ort_version: '1.16.3' + onnx_version: '1.16.1' - name: 'py39-tf2.15' tf_version: '2.15.0' python_version: '3.9' + ort_version: '1.16.3' + onnx_version: '1.16.1' + - name: 'py310-tf2.18' + tf_version: '2.18.0' + python_version: '3.10' + ort_version: '1.20.1' + onnx_version: '1.17.0' + - name: 'py311-tf2.18' + tf_version: '2.18.0' + python_version: '3.11' + ort_version: '1.20.1' + onnx_version: '1.17.0' + - name: 'py312-tf2.18' + tf_version: '2.18.0' + python_version: '3.12' + ort_version: '1.20.1' + onnx_version: '1.17.0' runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index e8b8e0862..5e9377d2e 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -21,7 +21,7 @@ jobs: python-version: 3.11 - name: Install dependencies - run: pip install pylint==2.4.4 + run: pip install pylint - name: Run pylint run: | diff --git a/.github/workflows/unit_test_ci.yml b/.github/workflows/unit_test_ci.yml index 00f175d99..08d922bf3 100644 --- a/.github/workflows/unit_test_ci.yml +++ b/.github/workflows/unit_test_ci.yml @@ -30,8 +30,8 @@ jobs: os: 'ubuntu-latest' tf_version: '2.9.0' python_version: '3.8' - ort_version: '1.20.1' - onnx_version: '1.17.0' + ort_version: '1.16.3' + onnx_version: '1.16.1' opset_version: '18' skip_tflite: 'False' @@ -135,25 +135,33 @@ jobs: - 'py312-tf2.18' os: ['ubuntu-latest', 'windows-2022'] opset_version: ['18', '15'] - ort_version: ['1.20.1'] - onnx_version: ['1.17.0'] skip_tflite: ['False'] include: - name: 'py312-tf2.18' tf_version: '2.18.0' python_version: '3.12' + ort_version: '1.20.1' + onnx_version: '1.17.0' - name: 'py311-tf2.18' tf_version: '2.18.0' python_version: '3.11' + ort_version: '1.20.1' + onnx_version: '1.17.0' - name: 'py310-tf2.18' tf_version: '2.18.0' python_version: '3.10' + ort_version: '1.20.1' + onnx_version: '1.17.0' - name: 'py38-tf2.13' tf_version: '2.13.0' python_version: '3.8' + ort_version: '1.16.3' + onnx_version: '1.16.1' - name: 'py39-tf2.15' tf_version: '2.15.0' python_version: '3.9' + ort_version: '1.16.3' + onnx_version: '1.16.1' - name: 'py37-tf1.15' tf_version: '1.15.5' python_version: '3.7' diff --git a/tests/utils/setup_test_env.sh b/tests/utils/setup_test_env.sh index a14828d05..0d8ad9fb8 100755 --- a/tests/utils/setup_test_env.sh +++ b/tests/utils/setup_test_env.sh @@ -16,17 +16,14 @@ echo "==== ONNXRuntime version: $ORT_VERSION" echo "==== ONNX version: $ONNX_VERSION" pip install pytest pytest-cov pytest-runner coverage graphviz requests pyyaml pillow pandas parameterized sympy coloredlogs flatbuffers timeout-decorator -pip install onnx==$ONNX_VERSION -pip install onnxruntime==$ORT_VERSION -pip install "numpy<2" - -pip install onnxruntime-extensions -pip install "tensorflow-text<=$TF_VERSION" - pip uninstall -y tensorflow -pip install tensorflow==$TF_VERSION -pip uninstall -y protobuf -pip install "protobuf~=3.20" +pip install onnx==$ONNX_VERSION onnxruntime==$ORT_VERSION onnxruntime-extensions "tensorflow-text<=$TF_VERSION" tensorflow==$TF_VERSION + +if [[ $TF_VERSION == 1.* ]]; then + pip install numpy==1.19.0 +else + pip install tf_keras==$TF_VERSION +fi python setup.py install From 0bd3c4e187c73417cde5c1ada9a130c003ef5ef8 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 15:59:07 +0100 Subject: [PATCH 08/26] lint Signed-off-by: xadupre --- .../actions/keras_application_test/action.yml | 8 +++- .github/actions/keras_unit_test/action.yml | 4 +- .../workflows/keras_application_test_ci.yml | 8 ++-- .github/workflows/keras_unit_test_ci.yml | 44 ++++++++++++++----- .../workflows/pretrained_model_test_ci.yml | 10 ++--- .github/workflows/unit_test_ci.yml | 12 ++--- tests/utils/setup_test_env.sh | 4 +- tools/pylintrc | 2 +- 8 files changed, 61 insertions(+), 31 deletions(-) diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index 1ed8c9e69..5bc7651b9 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -50,6 +50,10 @@ runs: pip install keras-self-attention pip install pytest pytest-cov pytest-runner + if [[ ${{ inputs.tf_version }} <= 2.15 ]]; then + pip install "protobuf<3.20" + fi + if [[ ${{ inputs.tf_version }} == 1.* ]]; then pip install keras==2.3.1 pip install transformers==4.2.0 @@ -58,7 +62,9 @@ runs: pip install numpy==1.19.0 else pip install transformers - pip install tf_keras==${{ inputs.tf_version }} + if [[ ${{ inputs.tf_version }} != 2.13 ]]; then + pip install tf_keras==${{ inputs.tf_version }} + fi fi pip install -e . diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index b63b85f16..f597631f4 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -36,7 +36,9 @@ runs: if [[ ${{ inputs.tf_version }} == 1.* ]]; then pip install numpy==1.19.0 else - pip install tf_keras==${{ inputs.tf_version }} + if [[ ${{ inputs.tf_version }} != 2.13 ]]; then + pip install tf_keras==${{ inputs.tf_version }} + fi fi pip install -e . diff --git a/.github/workflows/keras_application_test_ci.yml b/.github/workflows/keras_application_test_ci.yml index 4c5187f6b..d28a23919 100644 --- a/.github/workflows/keras_application_test_ci.yml +++ b/.github/workflows/keras_application_test_ci.yml @@ -15,7 +15,7 @@ concurrency: jobs: - Test_min_py38_with_min_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_min_py38_tf2_9: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -39,7 +39,7 @@ jobs: name: Test Results (Py38-TF2.9-ubuntu) path: ./**/test-results-*.xml - Test_max_py310_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_max_py310_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -87,7 +87,7 @@ jobs: name: Test Results (Py37-TF1.15-ubuntu) path: ./**/test-results-*.xml - Extra_tests: + Extra_tests1: strategy: fail-fast: false matrix: @@ -146,7 +146,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test_min_py38_with_min_tf, Test_max_py310_with_latest_tf, Test_py37_with_tf1_15, Extra_tests] + needs: [Test_min_py38_tf2_9, Test_max_py310_tf2_18, Test_py37_with_tf1_15, Extra_tests] runs-on: ubuntu-latest permissions: checks: write diff --git a/.github/workflows/keras_unit_test_ci.yml b/.github/workflows/keras_unit_test_ci.yml index 7d2154ca9..cc3349044 100644 --- a/.github/workflows/keras_unit_test_ci.yml +++ b/.github/workflows/keras_unit_test_ci.yml @@ -14,7 +14,7 @@ concurrency: cancel-in-progress: true jobs: - Test_min_py38_with_min_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_min_py38_tf2_9: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -38,7 +38,7 @@ jobs: name: Test Results (Py38-TF2.9-ubuntu) path: ./**/test-results-*.xml - Test_max_py310_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_max_py310_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -62,7 +62,7 @@ jobs: name: Test Results (Py310-TF2.18-ubuntu) path: ./**/test-results-*.xml - Test_max_py311_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_max_py311_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -86,7 +86,7 @@ jobs: name: Test Results (Py311-TF2.18-ubuntu) path: ./**/test-results-*.xml - Test_max_py312_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_max_py312_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -134,23 +134,43 @@ jobs: name: Test Results (Py37-TF1.15-ubuntu) path: ./**/test-results-*.xml - Extra_tests: + Extra_tests2: strategy: fail-fast: false matrix: name: - - 'py39-tf2.10' + - 'py38-tf2.13' - 'py39-tf2.15' + - 'py310-tf2.18' + - 'py311-tf2.18' + - 'py312-tf2.18' os: ['ubuntu-latest', 'windows-2022'] - ort_version: ['1.20.1'] - onnx_version: ['1.17.0'] include: - - name: 'py39-tf2.10' - tf_version: '2.10.0' - python_version: '3.9' + - name: 'py38-tf2.13' + tf_version: '2.13.0' + python_version: '3.8' + ort_version: '1.16.3' + onnx_version: '1.16.1' - name: 'py39-tf2.15' tf_version: '2.15.0' python_version: '3.9' + ort_version: '1.16.3' + onnx_version: '1.16.1' + - name: 'py310-tf2.18' + tf_version: '2.18.0' + python_version: '3.10' + ort_version: '1.20.1' + onnx_version: '1.17.0' + - name: 'py311-tf2.18' + tf_version: '2.18.0' + python_version: '3.11' + ort_version: '1.20.1' + onnx_version: '1.17.0' + - name: 'py312-tf2.18' + tf_version: '2.18.0' + python_version: '3.12' + ort_version: '1.20.1' + onnx_version: '1.17.0' runs-on: ${{ matrix.os }} steps: @@ -173,7 +193,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test_min_py38_with_min_tf, Test_max_py310_with_latest_tf, Test_max_py311_with_latest_tf, Test_max_py312_with_latest_tf, Test_py37_with_tf1_15, Extra_tests] + needs: [Test_min_py38_tf2_9, Test_max_py310_tf2_18, Test_max_py311_tf2_18, Test_max_py312_tf2_18, Test_py37_with_tf1_15, Extra_tests] runs-on: ubuntu-latest permissions: checks: write diff --git a/.github/workflows/pretrained_model_test_ci.yml b/.github/workflows/pretrained_model_test_ci.yml index 7a48a5b86..497bf38b5 100644 --- a/.github/workflows/pretrained_model_test_ci.yml +++ b/.github/workflows/pretrained_model_test_ci.yml @@ -15,7 +15,7 @@ concurrency: jobs: - Test_min_py38_with_min_tf: # Do not change this name because it is used in 'publish-test-results' section below. + Test_min_py38_tf2_9: # Do not change this name because it is used in 'publish-test-results' section below. strategy: fail-fast: false runs-on: ubuntu-latest @@ -42,7 +42,7 @@ jobs: name: Test Results (Py38-TF2.9-18-ubuntu) path: ./**/test-results-*.xml - Test_max_py310_with_latest_tf: # Do not change this name because it is used in 'publish-test-results' section below. + Test_max_py310_tf2_18: # Do not change this name because it is used in 'publish-test-results' section below. strategy: fail-fast: false runs-on: ubuntu-latest @@ -69,7 +69,7 @@ jobs: name: Test Results (Py310-TF2.18-18-ubuntu) path: ./**/test-results-*.xml - Test_max_py312_with_latest_tf: # Do not change this name because it is used in 'publish-test-results' section below. + Test_max_py312_tf2_18: # Do not change this name because it is used in 'publish-test-results' section below. strategy: fail-fast: false runs-on: ubuntu-latest @@ -122,7 +122,7 @@ jobs: name: Test Results (Py37-TF1.15-15-ubuntu) path: ./**/test-results-*.xml - Extra_tests: # Do not change this name because it is used in 'publish-test-results' section below. + Extra_tests3: # Do not change this name because it is used in 'publish-test-results' section below. strategy: fail-fast: false matrix: @@ -186,7 +186,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test_min_py38_with_min_tf, Test_max_py310_with_latest_tf, Test_max_py312_with_latest_tf, Test_py37_with_tf1_15, Extra_tests] + needs: [Test_min_py38_tf2_9, Test_max_py310_tf2_18, Test_max_py312_tf2_18, Test_py37_with_tf1_15, Extra_tests] runs-on: ubuntu-latest permissions: checks: write diff --git a/.github/workflows/unit_test_ci.yml b/.github/workflows/unit_test_ci.yml index 08d922bf3..20e629fe4 100644 --- a/.github/workflows/unit_test_ci.yml +++ b/.github/workflows/unit_test_ci.yml @@ -15,7 +15,7 @@ concurrency: jobs: - Test_min_py38_with_min_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_min_py38_tf2_9: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -42,7 +42,7 @@ jobs: name: Test Results (Py38-TF2.9-18-ubuntu) path: ./**/test-results-*.xml - Test_max_py310_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_max_py310_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -69,7 +69,7 @@ jobs: name: Test Results (Py310-TF2.18-18-ubuntu) path: ./**/test-results-*.xml - Test_max_py311_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_max_py311_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -96,7 +96,7 @@ jobs: name: Test Results (Py311-TF2.18-18-ubuntu) path: ./**/test-results-*.xml - Test_max_py312_with_latest_tf: # Do not change this name because it is used in Ruleset of this repo. + Test_max_py312_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -123,7 +123,7 @@ jobs: name: Test Results (Py312-TF2.18-18-ubuntu) path: ./**/test-results-*.xml - Extra_tests: + Extra_tests4: strategy: fail-fast: false matrix: @@ -196,7 +196,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test_min_py38_with_min_tf, Test_max_py310_with_latest_tf, Test_max_py311_with_latest_tf, Test_max_py312_with_latest_tf, Extra_tests] + needs: [Test_min_py38_tf2_9, Test_max_py310_tf2_18, Test_max_py311_tf2_18, Test_max_py312_tf2_18, Extra_tests] runs-on: ubuntu-latest permissions: checks: write diff --git a/tests/utils/setup_test_env.sh b/tests/utils/setup_test_env.sh index 0d8ad9fb8..d768669a4 100755 --- a/tests/utils/setup_test_env.sh +++ b/tests/utils/setup_test_env.sh @@ -22,7 +22,9 @@ pip install onnx==$ONNX_VERSION onnxruntime==$ORT_VERSION onnxruntime-extensions if [[ $TF_VERSION == 1.* ]]; then pip install numpy==1.19.0 else - pip install tf_keras==$TF_VERSION + if [[ ${{ inputs.tf_version }} != 2.13 ]]; then + pip install tf_keras==$TF_VERSION + fi fi python setup.py install diff --git a/tools/pylintrc b/tools/pylintrc index 955e35304..fe80d7bac 100644 --- a/tools/pylintrc +++ b/tools/pylintrc @@ -39,7 +39,7 @@ enable=indexing-exception,old-raise-syntax # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=design,similarities,no-self-use,attribute-defined-outside-init,locally-disabled,star-args,pointless-except,bad-option-value,global-statement,fixme,suppressed-message,useless-suppression,locally-enabled,no-member,no-name-in-module,import-error,unsubscriptable-object,unbalanced-tuple-unpacking,undefined-variable,not-context-manager,useless-object-inheritance +disable=design,similarities,no-self-use,attribute-defined-outside-init,locally-disabled,star-args,pointless-except,bad-option-value,global-statement,fixme,suppressed-message,useless-suppression,locally-enabled,no-member,no-name-in-module,import-error,unsubscriptable-object,unbalanced-tuple-unpacking,undefined-variable,not-context-manager,useless-object-inheritance,consider-using-f-string,unspecified-encoding,unnecessary-lambda-assignment,use-dict-literal # Set the cache size for astng objects. From e9b45bcbdbe03156365710ac5a7ff311027516b6 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 16:03:25 +0100 Subject: [PATCH 09/26] lint Signed-off-by: xadupre --- tools/pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pylintrc b/tools/pylintrc index fe80d7bac..d3aab2d58 100644 --- a/tools/pylintrc +++ b/tools/pylintrc @@ -39,7 +39,7 @@ enable=indexing-exception,old-raise-syntax # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=design,similarities,no-self-use,attribute-defined-outside-init,locally-disabled,star-args,pointless-except,bad-option-value,global-statement,fixme,suppressed-message,useless-suppression,locally-enabled,no-member,no-name-in-module,import-error,unsubscriptable-object,unbalanced-tuple-unpacking,undefined-variable,not-context-manager,useless-object-inheritance,consider-using-f-string,unspecified-encoding,unnecessary-lambda-assignment,use-dict-literal +disable=design,similarities,no-self-use,attribute-defined-outside-init,locally-disabled,star-args,pointless-except,bad-option-value,global-statement,fixme,suppressed-message,useless-suppression,locally-enabled,no-member,no-name-in-module,import-error,unsubscriptable-object,unbalanced-tuple-unpacking,undefined-variable,not-context-manager,useless-object-inheritance,consider-using-f-string,unspecified-encoding,unnecessary-lambda-assignment,use-dict-literal,consider-using-with,wrong-import-order,consider-iterating-dictionary,use-maxsplit-arg,possibly-used-before-assignment,super-with-arguments,redundant-u-string-prefix,use-list-literal,f-string-without-interpolation # Set the cache size for astng objects. From cbede9245bd46dae7c9862a74c1f1d1b9f7b5ffd Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 16:10:44 +0100 Subject: [PATCH 10/26] lint Signed-off-by: xadupre --- tests/run_pretrained_models.py | 2 +- tools/pylintrc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run_pretrained_models.py b/tests/run_pretrained_models.py index a6a952af3..6cec0c415 100644 --- a/tests/run_pretrained_models.py +++ b/tests/run_pretrained_models.py @@ -474,7 +474,7 @@ def run_tflite(): for k in input_names: v = self.input_names[k] inputs[to_rename.get(k, k)] = tf.constant(self.make_input(v)) - tf_func = tf.function(concrete_func) + tf_func = tf.function(self.concrete_function) logger.info("Running TF") tf_results_d = tf_func(**inputs) # If there is only a single output a dict might not be returned diff --git a/tools/pylintrc b/tools/pylintrc index d3aab2d58..c3f41202a 100644 --- a/tools/pylintrc +++ b/tools/pylintrc @@ -39,7 +39,7 @@ enable=indexing-exception,old-raise-syntax # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=design,similarities,no-self-use,attribute-defined-outside-init,locally-disabled,star-args,pointless-except,bad-option-value,global-statement,fixme,suppressed-message,useless-suppression,locally-enabled,no-member,no-name-in-module,import-error,unsubscriptable-object,unbalanced-tuple-unpacking,undefined-variable,not-context-manager,useless-object-inheritance,consider-using-f-string,unspecified-encoding,unnecessary-lambda-assignment,use-dict-literal,consider-using-with,wrong-import-order,consider-iterating-dictionary,use-maxsplit-arg,possibly-used-before-assignment,super-with-arguments,redundant-u-string-prefix,use-list-literal,f-string-without-interpolation +disable=design,similarities,no-self-use,attribute-defined-outside-init,locally-disabled,star-args,pointless-except,bad-option-value,global-statement,fixme,suppressed-message,useless-suppression,locally-enabled,no-member,no-name-in-module,import-error,unsubscriptable-object,unbalanced-tuple-unpacking,undefined-variable,not-context-manager,useless-object-inheritance,consider-using-f-string,unspecified-encoding,unnecessary-lambda-assignment,use-dict-literal,consider-using-with,wrong-import-order,consider-iterating-dictionary,use-maxsplit-arg,possibly-used-before-assignment,super-with-arguments,redundant-u-string-prefix,use-list-literal,f-string-without-interpolation,condition-evals-to-constant,global-variable-not-assigned,consider-using-enumerate,unused-argument,superfluous-parens,use-sequence-for-iteration,useless-return,superfluous-parens,use-a-generator,raise-missing-from,overgeneral-exceptions,condition-evals-to-constant # Set the cache size for astng objects. From 672f7d8ddbf1244e63b1a59d030f731a0c8e1bd7 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 16:16:20 +0100 Subject: [PATCH 11/26] lint Signed-off-by: xadupre --- tools/pylintrc | 67 +------------------------------------------------- 1 file changed, 1 insertion(+), 66 deletions(-) diff --git a/tools/pylintrc b/tools/pylintrc index c3f41202a..645cf5c29 100644 --- a/tools/pylintrc +++ b/tools/pylintrc @@ -8,9 +8,6 @@ # pygtk.require(). #init-hook= -# Profiled execution. -profile=no - # Add files or directories to the blacklist. They should be base names, not # paths. ignore=CVS @@ -39,11 +36,7 @@ enable=indexing-exception,old-raise-syntax # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=design,similarities,no-self-use,attribute-defined-outside-init,locally-disabled,star-args,pointless-except,bad-option-value,global-statement,fixme,suppressed-message,useless-suppression,locally-enabled,no-member,no-name-in-module,import-error,unsubscriptable-object,unbalanced-tuple-unpacking,undefined-variable,not-context-manager,useless-object-inheritance,consider-using-f-string,unspecified-encoding,unnecessary-lambda-assignment,use-dict-literal,consider-using-with,wrong-import-order,consider-iterating-dictionary,use-maxsplit-arg,possibly-used-before-assignment,super-with-arguments,redundant-u-string-prefix,use-list-literal,f-string-without-interpolation,condition-evals-to-constant,global-variable-not-assigned,consider-using-enumerate,unused-argument,superfluous-parens,use-sequence-for-iteration,useless-return,superfluous-parens,use-a-generator,raise-missing-from,overgeneral-exceptions,condition-evals-to-constant - - -# Set the cache size for astng objects. -cache-size=500 +disable=design,similarities,no-self-use,attribute-defined-outside-init,locally-disabled,star-args,pointless-except,bad-option-value,global-statement,fixme,suppressed-message,useless-suppression,locally-enabled,no-member,no-name-in-module,import-error,unsubscriptable-object,unbalanced-tuple-unpacking,undefined-variable,not-context-manager,useless-object-inheritance,consider-using-f-string,unspecified-encoding,unnecessary-lambda-assignment,use-dict-literal,consider-using-with,wrong-import-order,consider-iterating-dictionary,use-maxsplit-arg,possibly-used-before-assignment,super-with-arguments,redundant-u-string-prefix,use-list-literal,f-string-without-interpolation,condition-evals-to-constant,global-variable-not-assigned,consider-using-enumerate,unused-argument,superfluous-parens,use-sequence-for-iteration,useless-return,superfluous-parens,use-a-generator,raise-missing-from,overgeneral-exceptions,condition-evals-to-constant,consider-using-generator,use-yield-from,consider-using-min-builtin,overgeneral-exceptions [REPORTS] @@ -53,11 +46,6 @@ cache-size=500 # mypackage.mymodule.MyReporterClass. output-format=text -# Put messages in a separate file for each module / package specified on the -# command line instead of printing them on stdout. Reports (if any) will be -# written in a file name "pylint_global.[txt|html]". -files-output=no - # Tells whether to display a full report or only the messages reports=no @@ -68,10 +56,6 @@ reports=no # (RP0004). evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) -# Add a comment according to your evaluation note. This is used by the global -# evaluation report (RP0004). -comment=no - # Template used to display messages. This is a python new-style format string # used to format the message information. See doc for all details #msg-template= @@ -87,10 +71,6 @@ ignore-mixin-members=yes # (useful for classes with attributes dynamically set). ignored-classes=SQLObject -# When zope mode is activated, add a predefined set of Zope acquired attributes -# to generated-members. -zope=no - # List of members which are set dynamically and missed by pylint inference # system, and so shouldn't trigger E0201 when accessed. Python regular # expressions are accepted. @@ -117,17 +97,6 @@ additional-builtins= [BASIC] -# Required attributes for module, separated by a comma -required-attributes= - -# List of builtins function names that should not be used, separated by a comma -bad-functions=apply,input,reduce - - -# Disable the report(s) with the given id(s). -# All non-Google reports are disabled by default. -disable-report=R0001,R0002,R0003,R0004,R0101,R0102,R0201,R0202,R0220,R0401,R0402,R0701,R0801,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0914,R0915,R0921,R0922,R0923 - # Regular expression which should only match correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ @@ -187,9 +156,6 @@ ignore-long-lines=^\s*(# )??$ # else. single-line-if-stmt=y -# List of optional constructs for which whitespace checking is disabled -no-space-check= - # Maximum number of lines in a module max-module-lines=99999 @@ -239,10 +205,6 @@ int-import-graph= [CLASSES] -# List of interface methods to ignore, separated by a comma. This is used for -# instance to not check methods defines in Zope's Interface base class. -ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by - # List of method names used to declare (i.e. assign) instance attributes. defining-attr-methods=__init__,__new__,setUp @@ -286,33 +248,6 @@ min-public-methods=2 # Maximum number of public methods for a class (see R0904). max-public-methods=20 - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=Exception,StandardError,BaseException - - -[AST] - -# Maximum line length for lambdas -short-func-length=1 - -# List of module members that should be marked as deprecated. -# All of the string functions are listed in 4.1.4 Deprecated string functions -# in the Python 2.4 docs. -deprecated-members=string.atof,string.atoi,string.atol,string.capitalize,string.expandtabs,string.find,string.rfind,string.index,string.rindex,string.count,string.lower,string.split,string.rsplit,string.splitfields,string.join,string.joinfields,string.lstrip,string.rstrip,string.strip,string.swapcase,string.translate,string.upper,string.ljust,string.rjust,string.center,string.zfill,string.replace,sys.exitfunc - - -[DOCSTRING] - -# List of exceptions that do not need to be mentioned in the Raises section of -# a docstring. -ignore-exceptions=AssertionError,NotImplementedError,StopIteration,TypeError - - - [TOKENS] # Number of spaces of indent required when the last token on the preceding line From ca449a9573a4c0db5b0aae70787ee814626f0d03 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 16:20:49 +0100 Subject: [PATCH 12/26] lint Signed-off-by: xadupre --- tests/run_pretrained_models.py | 2 +- tf2onnx/onnx_opset/nn.py | 1 + tf2onnx/tf_utils.py | 4 ++-- tf2onnx/utils.py | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/run_pretrained_models.py b/tests/run_pretrained_models.py index 6cec0c415..7b74bbc61 100644 --- a/tests/run_pretrained_models.py +++ b/tests/run_pretrained_models.py @@ -492,7 +492,7 @@ def run_tflite(): tf.profiler.experimental.start(self.tf_profile) while time.time() < stop: for _ in range(PERF_STEP): - _ = concrete_func(**inputs) + _ = self.concrete_function(**inputs) n += PERF_STEP if self.tf_profile is not None: tf.profiler.experimental.stop() diff --git a/tf2onnx/onnx_opset/nn.py b/tf2onnx/onnx_opset/nn.py index a06f02cec..1d10bbd66 100644 --- a/tf2onnx/onnx_opset/nn.py +++ b/tf2onnx/onnx_opset/nn.py @@ -1793,6 +1793,7 @@ def version_11(cls, ctx, node, **kwargs): node.type = "Identity" ctx.replace_inputs(node, [data]) return + cond = None if len(conditions) == 1: cond = conditions[0] if len(conditions) == 2: diff --git a/tf2onnx/tf_utils.py b/tf2onnx/tf_utils.py index 16cb76344..d23957fbd 100644 --- a/tf2onnx/tf_utils.py +++ b/tf2onnx/tf_utils.py @@ -351,9 +351,9 @@ def read_tf_node_def_attrs(node_def, input_dtypes, input_shapes): # ignore the following attributes TF_IGNORED_NODE_ATTRS = { "T", "unknown_rank", "_class", "Tshape", "use_cudnn_on_gpu", "Index", "Tpaddings", - "TI", "Tparams", "Tindices", "Tlen", "Tdim", "Tin", "dynamic_size", "Tmultiples", + "TI", "Tparams", "Tindices", "Tlen", "Tdim", "dynamic_size", "Tmultiples", "Tblock_shape", "Tcrops", "index_type", "Taxis", "U", "maxval", - "Tout", "Tlabels", "Tindex", "element_shape", "Targmax", "Tperm", "Tcond", + "Tlabels", "Tindex", "element_shape", "Targmax", "Tperm", "Tcond", "T_threshold", "shape_type", "_lower_using_switch_merge", "parallel_iterations", "_num_original_outputs", "output_types", "output_shapes", "key_dtype", "value_dtype", "Tin", "Tout", "capacity", "component_types", "shapes", diff --git a/tf2onnx/utils.py b/tf2onnx/utils.py index 7f2f53daa..be030d381 100644 --- a/tf2onnx/utils.py +++ b/tf2onnx/utils.py @@ -46,7 +46,7 @@ onnx_pb.TensorProto.UINT32: np.uint32, onnx_pb.TensorProto.UINT64: np.uint64, onnx_pb.TensorProto.INT64: np.int64, - onnx_pb.TensorProto.UINT64: np.uint64, + onnx_pb.TensorProto.INT64: np.int64, onnx_pb.TensorProto.BOOL: bool, onnx_pb.TensorProto.COMPLEX64: np.complex64, onnx_pb.TensorProto.COMPLEX128: np.complex128, From bc1dd9a57ea08b0ed9fe93948d39014ec12af706 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 16:25:34 +0100 Subject: [PATCH 13/26] fix ci Signed-off-by: xadupre --- .github/workflows/keras_application_test_ci.yml | 8 ++++---- .github/workflows/keras_unit_test_ci.yml | 12 ++++++------ .github/workflows/pretrained_model_test_ci.yml | 10 +++++----- .github/workflows/unit_test_ci.yml | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/keras_application_test_ci.yml b/.github/workflows/keras_application_test_ci.yml index d28a23919..a37d4cc7a 100644 --- a/.github/workflows/keras_application_test_ci.yml +++ b/.github/workflows/keras_application_test_ci.yml @@ -15,7 +15,7 @@ concurrency: jobs: - Test_min_py38_tf2_9: # Do not change this name because it is used in Ruleset of this repo. + Test1_py38_tf2_9: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -39,7 +39,7 @@ jobs: name: Test Results (Py38-TF2.9-ubuntu) path: ./**/test-results-*.xml - Test_max_py310_tf2_18: # Do not change this name because it is used in Ruleset of this repo. + Test1_py310_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -63,7 +63,7 @@ jobs: name: Test Results (Py310-TF2.18-ubuntu) path: ./**/test-results-*.xml - Test_py37_with_tf1_15: # Do not change this name because it is used in Ruleset of this repo. + Test1_py37_with_tf1_15: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-22.04 @@ -146,7 +146,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test_min_py38_tf2_9, Test_max_py310_tf2_18, Test_py37_with_tf1_15, Extra_tests] + needs: [Test1_py38_tf2_9, Test1_py310_tf2_18, Test1_py37_with_tf1_15, Extra_tests1] runs-on: ubuntu-latest permissions: checks: write diff --git a/.github/workflows/keras_unit_test_ci.yml b/.github/workflows/keras_unit_test_ci.yml index cc3349044..988e8e3c9 100644 --- a/.github/workflows/keras_unit_test_ci.yml +++ b/.github/workflows/keras_unit_test_ci.yml @@ -14,7 +14,7 @@ concurrency: cancel-in-progress: true jobs: - Test_min_py38_tf2_9: # Do not change this name because it is used in Ruleset of this repo. + Test2_py38_tf2_9: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -38,7 +38,7 @@ jobs: name: Test Results (Py38-TF2.9-ubuntu) path: ./**/test-results-*.xml - Test_max_py310_tf2_18: # Do not change this name because it is used in Ruleset of this repo. + Test2_py310_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -62,7 +62,7 @@ jobs: name: Test Results (Py310-TF2.18-ubuntu) path: ./**/test-results-*.xml - Test_max_py311_tf2_18: # Do not change this name because it is used in Ruleset of this repo. + Test2_py311_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -86,7 +86,7 @@ jobs: name: Test Results (Py311-TF2.18-ubuntu) path: ./**/test-results-*.xml - Test_max_py312_tf2_18: # Do not change this name because it is used in Ruleset of this repo. + Test2_py312_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -110,7 +110,7 @@ jobs: name: Test Results (Py312-TF2.18-ubuntu) path: ./**/test-results-*.xml - Test_py37_with_tf1_15: # Do not change this name because it is used in Ruleset of this repo. + Test2_py37_with_tf1_15: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-22.04 @@ -193,7 +193,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test_min_py38_tf2_9, Test_max_py310_tf2_18, Test_max_py311_tf2_18, Test_max_py312_tf2_18, Test_py37_with_tf1_15, Extra_tests] + needs: [Test2_py38_tf2_9, Test2_py310_tf2_18, Test2_py311_tf2_18, Test2_py312_tf2_18, Test2_py37_with_tf1_15, Extra_tests2] runs-on: ubuntu-latest permissions: checks: write diff --git a/.github/workflows/pretrained_model_test_ci.yml b/.github/workflows/pretrained_model_test_ci.yml index 497bf38b5..967de48eb 100644 --- a/.github/workflows/pretrained_model_test_ci.yml +++ b/.github/workflows/pretrained_model_test_ci.yml @@ -15,7 +15,7 @@ concurrency: jobs: - Test_min_py38_tf2_9: # Do not change this name because it is used in 'publish-test-results' section below. + Test3_py38_tf2_9: # Do not change this name because it is used in 'publish-test-results' section below. strategy: fail-fast: false runs-on: ubuntu-latest @@ -42,7 +42,7 @@ jobs: name: Test Results (Py38-TF2.9-18-ubuntu) path: ./**/test-results-*.xml - Test_max_py310_tf2_18: # Do not change this name because it is used in 'publish-test-results' section below. + Test3_py310_tf2_18: # Do not change this name because it is used in 'publish-test-results' section below. strategy: fail-fast: false runs-on: ubuntu-latest @@ -69,7 +69,7 @@ jobs: name: Test Results (Py310-TF2.18-18-ubuntu) path: ./**/test-results-*.xml - Test_max_py312_tf2_18: # Do not change this name because it is used in 'publish-test-results' section below. + Test3_py312_tf2_18: # Do not change this name because it is used in 'publish-test-results' section below. strategy: fail-fast: false runs-on: ubuntu-latest @@ -96,7 +96,7 @@ jobs: name: Test Results (Py312-TF2.18-18-ubuntu) path: ./**/test-results-*.xml - Test_py37_with_tf1_15: # Do not change this name because it is used in 'publish-test-results' section below. + Test3_py37_with_tf1_15: # Do not change this name because it is used in 'publish-test-results' section below. strategy: fail-fast: false runs-on: ubuntu-22.04 @@ -186,7 +186,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test_min_py38_tf2_9, Test_max_py310_tf2_18, Test_max_py312_tf2_18, Test_py37_with_tf1_15, Extra_tests] + needs: [Test3_py38_tf2_9, Test3_py310_tf2_18, Test3_py312_tf2_18, Test3_py37_with_tf1_15, Extra_tests3] runs-on: ubuntu-latest permissions: checks: write diff --git a/.github/workflows/unit_test_ci.yml b/.github/workflows/unit_test_ci.yml index 20e629fe4..8a4f3c330 100644 --- a/.github/workflows/unit_test_ci.yml +++ b/.github/workflows/unit_test_ci.yml @@ -15,7 +15,7 @@ concurrency: jobs: - Test_min_py38_tf2_9: # Do not change this name because it is used in Ruleset of this repo. + Test4_py38_tf2_9: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -42,7 +42,7 @@ jobs: name: Test Results (Py38-TF2.9-18-ubuntu) path: ./**/test-results-*.xml - Test_max_py310_tf2_18: # Do not change this name because it is used in Ruleset of this repo. + Test4_py310_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -69,7 +69,7 @@ jobs: name: Test Results (Py310-TF2.18-18-ubuntu) path: ./**/test-results-*.xml - Test_max_py311_tf2_18: # Do not change this name because it is used in Ruleset of this repo. + Test4_py311_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -96,7 +96,7 @@ jobs: name: Test Results (Py311-TF2.18-18-ubuntu) path: ./**/test-results-*.xml - Test_max_py312_tf2_18: # Do not change this name because it is used in Ruleset of this repo. + Test4_py312_tf2_18: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false runs-on: ubuntu-latest @@ -196,7 +196,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test_min_py38_tf2_9, Test_max_py310_tf2_18, Test_max_py311_tf2_18, Test_max_py312_tf2_18, Extra_tests] + needs: [Test4_py38_tf2_9, Test4_py310_tf2_18, Test4_py311_tf2_18, Test4_py312_tf2_18, Extra_tests4] runs-on: ubuntu-latest permissions: checks: write From aefc71f1428945f9758a990efbecd8f655ea4de4 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 16:27:30 +0100 Subject: [PATCH 14/26] lint Signed-off-by: xadupre --- tf2onnx/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tf2onnx/utils.py b/tf2onnx/utils.py index be030d381..f6749eb7a 100644 --- a/tf2onnx/utils.py +++ b/tf2onnx/utils.py @@ -38,6 +38,7 @@ onnx_pb.TensorProto.FLOAT: np.float32, onnx_pb.TensorProto.FLOAT16: np.float16, onnx_pb.TensorProto.DOUBLE: np.float64, + onnx_pb.TensorProto.INT64: np.int64, onnx_pb.TensorProto.INT32: np.int32, onnx_pb.TensorProto.INT16: np.int16, onnx_pb.TensorProto.INT8: np.int8, @@ -45,8 +46,6 @@ onnx_pb.TensorProto.UINT16: np.uint16, onnx_pb.TensorProto.UINT32: np.uint32, onnx_pb.TensorProto.UINT64: np.uint64, - onnx_pb.TensorProto.INT64: np.int64, - onnx_pb.TensorProto.INT64: np.int64, onnx_pb.TensorProto.BOOL: bool, onnx_pb.TensorProto.COMPLEX64: np.complex64, onnx_pb.TensorProto.COMPLEX128: np.complex128, From e1ba6d480381184dfe0286273f756e4ec7a8cf48 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 16:37:58 +0100 Subject: [PATCH 15/26] fix cond Signed-off-by: xadupre --- .github/actions/keras_application_test/action.yml | 2 +- .github/actions/keras_unit_test/action.yml | 2 +- tests/utils/setup_test_env.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index 5bc7651b9..c1ee2ff30 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -62,7 +62,7 @@ runs: pip install numpy==1.19.0 else pip install transformers - if [[ ${{ inputs.tf_version }} != 2.13 ]]; then + if [[ ${{ inputs.tf_version }} != 2.13 && ${{ inputs.tf_version }} != 2.9 ]]; then pip install tf_keras==${{ inputs.tf_version }} fi fi diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index f597631f4..a532ea64f 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -36,7 +36,7 @@ runs: if [[ ${{ inputs.tf_version }} == 1.* ]]; then pip install numpy==1.19.0 else - if [[ ${{ inputs.tf_version }} != 2.13 ]]; then + if [[ ${{ inputs.tf_version }} != 2.13 && ${{ inputs.tf_version }} != 2.9 ]]; then pip install tf_keras==${{ inputs.tf_version }} fi fi diff --git a/tests/utils/setup_test_env.sh b/tests/utils/setup_test_env.sh index d768669a4..94fef421d 100755 --- a/tests/utils/setup_test_env.sh +++ b/tests/utils/setup_test_env.sh @@ -22,7 +22,7 @@ pip install onnx==$ONNX_VERSION onnxruntime==$ORT_VERSION onnxruntime-extensions if [[ $TF_VERSION == 1.* ]]; then pip install numpy==1.19.0 else - if [[ ${{ inputs.tf_version }} != 2.13 ]]; then + if [[ ${{ inputs.tf_version }} != 2.13 && ${{ inputs.tf_version }} != 2.9 ]]; then pip install tf_keras==$TF_VERSION fi fi From 4a6b320262e4b942438330c87a28bbe4b816f768 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 16:51:32 +0100 Subject: [PATCH 16/26] ci Signed-off-by: xadupre --- .github/actions/keras_application_test/action.yml | 13 ++++--------- .github/actions/keras_unit_test/action.yml | 8 ++++---- tests/utils/setup_test_env.sh | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index c1ee2ff30..8fa4e4c6c 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -24,13 +24,10 @@ runs: python -m pip install --upgrade pip pip install onnxconverter-common pip install onnx==${{ inputs.onnx_version }} - pip uninstall -y protobuf - pip install "protobuf~=3.20" pip install h5py pip install parameterized pip install timeout-decorator pip install coloredlogs flatbuffers - pip install tensorflow==${{ inputs.tf_version }} pip install onnxruntime==${{ inputs.ort_version }} pip install pillow pip install opencv-python @@ -50,10 +47,6 @@ runs: pip install keras-self-attention pip install pytest pytest-cov pytest-runner - if [[ ${{ inputs.tf_version }} <= 2.15 ]]; then - pip install "protobuf<3.20" - fi - if [[ ${{ inputs.tf_version }} == 1.* ]]; then pip install keras==2.3.1 pip install transformers==4.2.0 @@ -62,8 +55,10 @@ runs: pip install numpy==1.19.0 else pip install transformers - if [[ ${{ inputs.tf_version }} != 2.13 && ${{ inputs.tf_version }} != 2.9 ]]; then - pip install tf_keras==${{ inputs.tf_version }} + if [[ "${{ inputs.tf_version }}" != "2.13" && "${{ inputs.tf_version }}" != "2.9" ]]; then + pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} + else + pip install "protobuf<3.20" tensorflow==${{ inputs.tf_version }} fi fi diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index a532ea64f..24ab49e4c 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -28,16 +28,16 @@ runs: pip install parameterized pip install timeout-decorator pip install coloredlogs flatbuffers - pip install tensorflow==${{ inputs.tf_version }} pip install pytest pytest-cov pytest-runner pip install onnxruntime==${{ inputs.ort_version }} pip uninstall -y protobuf - pip install "protobuf~=3.20" if [[ ${{ inputs.tf_version }} == 1.* ]]; then pip install numpy==1.19.0 else - if [[ ${{ inputs.tf_version }} != 2.13 && ${{ inputs.tf_version }} != 2.9 ]]; then - pip install tf_keras==${{ inputs.tf_version }} + if [[ "${{ inputs.tf_version }}" != "2.13" && "${{ inputs.tf_version }}" != "2.9" ]]; then + pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} + else + pip install "protobuf<3.20" tensorflow==${{ inputs.tf_version }} fi fi diff --git a/tests/utils/setup_test_env.sh b/tests/utils/setup_test_env.sh index 94fef421d..85cf81024 100755 --- a/tests/utils/setup_test_env.sh +++ b/tests/utils/setup_test_env.sh @@ -22,7 +22,7 @@ pip install onnx==$ONNX_VERSION onnxruntime==$ORT_VERSION onnxruntime-extensions if [[ $TF_VERSION == 1.* ]]; then pip install numpy==1.19.0 else - if [[ ${{ inputs.tf_version }} != 2.13 && ${{ inputs.tf_version }} != 2.9 ]]; then + if [[ "$TF_VERSION" != "2.13" && "$TF_VERSION" != "2.9" ]]; then pip install tf_keras==$TF_VERSION fi fi From c27e246075379ec1d4d3964f7f75e0a063b20a25 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 17:00:13 +0100 Subject: [PATCH 17/26] fix script Signed-off-by: xadupre --- .github/actions/keras_application_test/action.yml | 4 +++- .github/actions/keras_unit_test/action.yml | 2 ++ tests/utils/setup_test_env.sh | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index 8fa4e4c6c..44e8ff6a1 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -55,9 +55,11 @@ runs: pip install numpy==1.19.0 else pip install transformers - if [[ "${{ inputs.tf_version }}" != "2.13" && "${{ inputs.tf_version }}" != "2.9" ]]; then + if [[ "${{ inputs.tf_version }}" != "2.13" && "${{ inputs.tf_version }}" != "2.9" ]]; then + echo "-- install-1 TF-KERAS ${{ inputs.tf_version }}" pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} else + echo "-- install-1 TF ${{ inputs.tf_version }}" pip install "protobuf<3.20" tensorflow==${{ inputs.tf_version }} fi fi diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index 24ab49e4c..e4b7d0bff 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -35,8 +35,10 @@ runs: pip install numpy==1.19.0 else if [[ "${{ inputs.tf_version }}" != "2.13" && "${{ inputs.tf_version }}" != "2.9" ]]; then + echo "-- install-2 TF-KERAS ${{ inputs.tf_version }}" pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} else + echo "-- install-2 TF ${{ inputs.tf_version }}" pip install "protobuf<3.20" tensorflow==${{ inputs.tf_version }} fi fi diff --git a/tests/utils/setup_test_env.sh b/tests/utils/setup_test_env.sh index 85cf81024..cad4e3037 100755 --- a/tests/utils/setup_test_env.sh +++ b/tests/utils/setup_test_env.sh @@ -23,7 +23,10 @@ if [[ $TF_VERSION == 1.* ]]; then pip install numpy==1.19.0 else if [[ "$TF_VERSION" != "2.13" && "$TF_VERSION" != "2.9" ]]; then + echo "-- install-3 TF-KERAS ${{ inputs.tf_version }}" pip install tf_keras==$TF_VERSION + else + echo "-- install-3 TF ${{ inputs.tf_version }}" fi fi From 30edd9b608818b1a5f8a85fa99a8a89f820c3bcb Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 17:03:21 +0100 Subject: [PATCH 18/26] fix ci Signed-off-by: xadupre --- .github/actions/keras_application_test/action.yml | 2 +- .github/actions/keras_unit_test/action.yml | 2 +- tests/utils/setup_test_env.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index 44e8ff6a1..ac102d0c0 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -55,7 +55,7 @@ runs: pip install numpy==1.19.0 else pip install transformers - if [[ "${{ inputs.tf_version }}" != "2.13" && "${{ inputs.tf_version }}" != "2.9" ]]; then + if [[ "${{ inputs.tf_version }}" != "2.13.0" && "${{ inputs.tf_version }}" != "2.9.0" ]]; then echo "-- install-1 TF-KERAS ${{ inputs.tf_version }}" pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} else diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index e4b7d0bff..d56c8ab83 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -34,7 +34,7 @@ runs: if [[ ${{ inputs.tf_version }} == 1.* ]]; then pip install numpy==1.19.0 else - if [[ "${{ inputs.tf_version }}" != "2.13" && "${{ inputs.tf_version }}" != "2.9" ]]; then + if [[ "${{ inputs.tf_version }}" != "2.13.0" && "${{ inputs.tf_version }}" != "2.9.0" ]]; then echo "-- install-2 TF-KERAS ${{ inputs.tf_version }}" pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} else diff --git a/tests/utils/setup_test_env.sh b/tests/utils/setup_test_env.sh index cad4e3037..8595f72bd 100755 --- a/tests/utils/setup_test_env.sh +++ b/tests/utils/setup_test_env.sh @@ -22,7 +22,7 @@ pip install onnx==$ONNX_VERSION onnxruntime==$ORT_VERSION onnxruntime-extensions if [[ $TF_VERSION == 1.* ]]; then pip install numpy==1.19.0 else - if [[ "$TF_VERSION" != "2.13" && "$TF_VERSION" != "2.9" ]]; then + if [[ "$TF_VERSION" != "2.13.0" && "$TF_VERSION" != "2.9.0" ]]; then echo "-- install-3 TF-KERAS ${{ inputs.tf_version }}" pip install tf_keras==$TF_VERSION else From 04d0b80b3a5b34c98618b0498899772ab0d80b74 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 17:17:24 +0100 Subject: [PATCH 19/26] remove 3.12 Signed-off-by: xadupre --- .../workflows/keras_application_test_ci.yml | 6 ---- .github/workflows/keras_unit_test_ci.yml | 32 +---------------- .../workflows/pretrained_model_test_ci.yml | 35 +------------------ .github/workflows/unit_test_ci.yml | 35 +------------------ README.md | 6 ++-- setup.py | 6 ++-- tests/test_cudnn_compatible_gru.py | 2 +- tests/test_custom_rnncell.py | 10 +++--- tests/test_gru.py | 8 ++--- tests/test_grublock.py | 2 +- tests/test_lstm.py | 6 ++-- tests/test_lstmblock.py | 2 +- tests/test_seq2seq.py | 10 +++--- tests/test_stacked_lstm.py | 4 +-- 14 files changed, 32 insertions(+), 132 deletions(-) diff --git a/.github/workflows/keras_application_test_ci.yml b/.github/workflows/keras_application_test_ci.yml index a37d4cc7a..d10e23a06 100644 --- a/.github/workflows/keras_application_test_ci.yml +++ b/.github/workflows/keras_application_test_ci.yml @@ -96,7 +96,6 @@ jobs: - 'py39-tf2.15' - 'py310-tf2.18' - 'py311-tf2.18' - - 'py312-tf2.18' os: ['ubuntu-latest', 'windows-2022'] include: - name: 'py38-tf2.13' @@ -119,11 +118,6 @@ jobs: python_version: '3.11' ort_version: '1.20.1' onnx_version: '1.17.0' - - name: 'py312-tf2.18' - tf_version: '2.18.0' - python_version: '3.12' - ort_version: '1.20.1' - onnx_version: '1.17.0' runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/keras_unit_test_ci.yml b/.github/workflows/keras_unit_test_ci.yml index 988e8e3c9..b62f46c0a 100644 --- a/.github/workflows/keras_unit_test_ci.yml +++ b/.github/workflows/keras_unit_test_ci.yml @@ -86,30 +86,6 @@ jobs: name: Test Results (Py311-TF2.18-ubuntu) path: ./**/test-results-*.xml - Test2_py312_tf2_18: # Do not change this name because it is used in Ruleset of this repo. - strategy: - fail-fast: false - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Run Tests (Py312-TF2.18) - uses: ./.github/actions/keras_unit_test - with: - tf_version: '2.18.0' - python_version: '3.12' - ort_version: '1.20.1' - onnx_version: '1.17.0' - - - name: Upload Test Results - if: always() - uses: actions/upload-artifact@v4 - with: - name: Test Results (Py312-TF2.18-ubuntu) - path: ./**/test-results-*.xml - Test2_py37_with_tf1_15: # Do not change this name because it is used in Ruleset of this repo. strategy: fail-fast: false @@ -143,7 +119,6 @@ jobs: - 'py39-tf2.15' - 'py310-tf2.18' - 'py311-tf2.18' - - 'py312-tf2.18' os: ['ubuntu-latest', 'windows-2022'] include: - name: 'py38-tf2.13' @@ -166,11 +141,6 @@ jobs: python_version: '3.11' ort_version: '1.20.1' onnx_version: '1.17.0' - - name: 'py312-tf2.18' - tf_version: '2.18.0' - python_version: '3.12' - ort_version: '1.20.1' - onnx_version: '1.17.0' runs-on: ${{ matrix.os }} steps: @@ -193,7 +163,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test2_py38_tf2_9, Test2_py310_tf2_18, Test2_py311_tf2_18, Test2_py312_tf2_18, Test2_py37_with_tf1_15, Extra_tests2] + needs: [Test2_py38_tf2_9, Test2_py310_tf2_18, Test2_py311_tf2_18, Test2_py37_with_tf1_15, Extra_tests2] runs-on: ubuntu-latest permissions: checks: write diff --git a/.github/workflows/pretrained_model_test_ci.yml b/.github/workflows/pretrained_model_test_ci.yml index 967de48eb..e7cde4b71 100644 --- a/.github/workflows/pretrained_model_test_ci.yml +++ b/.github/workflows/pretrained_model_test_ci.yml @@ -69,33 +69,6 @@ jobs: name: Test Results (Py310-TF2.18-18-ubuntu) path: ./**/test-results-*.xml - Test3_py312_tf2_18: # Do not change this name because it is used in 'publish-test-results' section below. - strategy: - fail-fast: false - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Run Tests (Py312-TF2.18-18) - uses: ./.github/actions/pretrained_model_test - with: - os: 'ubuntu-latest' - tf_version: '2.18.0' - python_version: '3.12' - ort_version: '1.20.1' - onnx_version: '1.17.0' - opset_version: '18' - skip_tflite: 'False' - - - name: Upload Test Results - if: always() - uses: actions/upload-artifact@v4 - with: - name: Test Results (Py312-TF2.18-18-ubuntu) - path: ./**/test-results-*.xml - Test3_py37_with_tf1_15: # Do not change this name because it is used in 'publish-test-results' section below. strategy: fail-fast: false @@ -131,7 +104,6 @@ jobs: - 'py39-tf2.15' - 'py310-tf2.18' - 'py311-tf2.18' - - 'py312-tf2.18' os: ['ubuntu-latest', 'windows-2022'] opset_version: ['18', '15'] skip_tflite: ['False'] @@ -156,11 +128,6 @@ jobs: python_version: '3.11' ort_version: '1.20.1' onnx_version: '1.17.0' - - name: 'py312-tf2.18' - tf_version: '2.18.0' - python_version: '3.12' - ort_version: '1.20.1' - onnx_version: '1.17.0' runs-on: ${{ matrix.os }} steps: @@ -186,7 +153,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test3_py38_tf2_9, Test3_py310_tf2_18, Test3_py312_tf2_18, Test3_py37_with_tf1_15, Extra_tests3] + needs: [Test3_py38_tf2_9, Test3_py310_tf2_18, Test3_py37_with_tf1_15, Extra_tests3] runs-on: ubuntu-latest permissions: checks: write diff --git a/.github/workflows/unit_test_ci.yml b/.github/workflows/unit_test_ci.yml index 8a4f3c330..018fa0262 100644 --- a/.github/workflows/unit_test_ci.yml +++ b/.github/workflows/unit_test_ci.yml @@ -96,33 +96,6 @@ jobs: name: Test Results (Py311-TF2.18-18-ubuntu) path: ./**/test-results-*.xml - Test4_py312_tf2_18: # Do not change this name because it is used in Ruleset of this repo. - strategy: - fail-fast: false - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Run Tests (Py312-TF2.18-18) - uses: ./.github/actions/unit_test - with: - os: 'ubuntu-latest' - tf_version: '2.18.0' - python_version: '3.12' - ort_version: '1.20.1' - onnx_version: '1.17.0' - opset_version: '18' - skip_tflite: 'False' - - - name: Upload Test Results - if: always() - uses: actions/upload-artifact@v4 - with: - name: Test Results (Py312-TF2.18-18-ubuntu) - path: ./**/test-results-*.xml - Extra_tests4: strategy: fail-fast: false @@ -132,16 +105,10 @@ jobs: - 'py39-tf2.15' - 'py310-tf2.18' - 'py311-tf2.18' - - 'py312-tf2.18' os: ['ubuntu-latest', 'windows-2022'] opset_version: ['18', '15'] skip_tflite: ['False'] include: - - name: 'py312-tf2.18' - tf_version: '2.18.0' - python_version: '3.12' - ort_version: '1.20.1' - onnx_version: '1.17.0' - name: 'py311-tf2.18' tf_version: '2.18.0' python_version: '3.11' @@ -196,7 +163,7 @@ jobs: publish-test-results: name: "Publish Tests Results to Github" - needs: [Test4_py38_tf2_9, Test4_py310_tf2_18, Test4_py311_tf2_18, Test4_py312_tf2_18, Extra_tests4] + needs: [Test4_py38_tf2_9, Test4_py310_tf2_18, Test4_py311_tf2_18, Extra_tests4] runs-on: ubuntu-latest permissions: checks: write diff --git a/README.md b/README.md index a2feaa929..cad1cd591 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ The common issues we run into we try to document here [Troubleshooting Guide](Tr | Build Type | OS | Python | TensorFlow | ONNX opset | Status | | --- | --- | --- | --- | --- | --- | -| Unit Test - Basic | Linux, Windows | 3.7-3.12 | 1.15, 2.9-2.15 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=16&branchName=main) | -| Unit Test - Full | Linux, Windows | 3.7-3.12 | 1.15, 2.9-2.15 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test-matrix?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=18&branchName=main) | | +| Unit Test - Basic | Linux, Windows | 3.7-3.11 | 1.15, 2.9-2.15 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=16&branchName=main) | +| Unit Test - Full | Linux, Windows | 3.7-3.11 | 1.15, 2.9-2.15 | 14-18 | [![Build Status](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_apis/build/status/unit_test-matrix?branchName=main)](https://dev.azure.com/tensorflow-onnx/tensorflow-onnx/_build/latest?definitionId=18&branchName=main) | |
## Supported Versions @@ -42,7 +42,7 @@ You can install tf2onnx on top of tf-1.x or tf-2.x. ### Python -We support Python ```3.7-3.12```. +We support Python ```3.7-3.11```. ## Prerequisites diff --git a/setup.py b/setup.py index 85fece3a2..7be0c795a 100644 --- a/setup.py +++ b/setup.py @@ -82,7 +82,7 @@ def run(self): author='ONNX', author_email='onnx-technical-discuss@lists.lfaidata.foundation', url='https://github.com/onnx/tensorflow-onnx', - install_requires=['numpy>=1.14.1', 'onnx>=1.4.1', 'requests', 'six', 'flatbuffers>=1.12', 'protobuf~=3.20'], + install_requires=['numpy>=1.14.1', 'onnx>=1.4.1', 'requests', 'six', 'flatbuffers>=1.12'], classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', @@ -98,5 +98,7 @@ def run(self): 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10'] + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + ] ) diff --git a/tests/test_cudnn_compatible_gru.py b/tests/test_cudnn_compatible_gru.py index ceab5a5ee..f3403a30b 100644 --- a/tests/test_cudnn_compatible_gru.py +++ b/tests/test_cudnn_compatible_gru.py @@ -16,7 +16,7 @@ # pylint: disable=missing-docstring,invalid-name,unused-argument,using-constant-test,cell-var-from-loop if is_tf2(): - MultiRNNCell = tf.compat.v1.nn.rnn_cell.MultiRNNCell + MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) dynamic_rnn = tf.compat.v1.nn.dynamic_rnn bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn else: diff --git a/tests/test_custom_rnncell.py b/tests/test_custom_rnncell.py index b5286c348..55c34d402 100644 --- a/tests/test_custom_rnncell.py +++ b/tests/test_custom_rnncell.py @@ -16,11 +16,11 @@ # pylint: disable=abstract-method,arguments-differ if is_tf2(): - BasicLSTMCell = tf.compat.v1.nn.rnn_cell.BasicLSTMCell - LSTMCell = tf.compat.v1.nn.rnn_cell.LSTMCell - GRUCell = tf.compat.v1.nn.rnn_cell.GRUCell - RNNCell = tf.compat.v1.nn.rnn_cell.RNNCell - MultiRNNCell = tf.compat.v1.nn.rnn_cell.MultiRNNCell + BasicLSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "BasicLSTMCell", None) + LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) + GRUCell = getattr(tf.compat.v1.nn.rnn_cell, "GRUCell", None) + RNNCell = getattr(tf.compat.v1.nn.rnn_cell, "RNNCell", None) + MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) dynamic_rnn = tf.compat.v1.nn.dynamic_rnn bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn else: diff --git a/tests/test_gru.py b/tests/test_gru.py index 88d1f7f7c..a2d891002 100644 --- a/tests/test_gru.py +++ b/tests/test_gru.py @@ -34,10 +34,10 @@ if is_tf2(): # There is no LSTMBlockCell in tf-2.x - BasicLSTMCell = tf.compat.v1.nn.rnn_cell.BasicLSTMCell - LSTMCell = tf.compat.v1.nn.rnn_cell.LSTMCell - GRUCell = tf.compat.v1.nn.rnn_cell.GRUCell - MultiRNNCell = tf.compat.v1.nn.rnn_cell.MultiRNNCell + BasicLSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "BasicLSTMCell", None) + LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) + GRUCell = getattr(tf.compat.v1.nn.rnn_cell, "GRUCell", None) + MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) dynamic_rnn = tf.compat.v1.nn.dynamic_rnn bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn else: diff --git a/tests/test_grublock.py b/tests/test_grublock.py index ebd878680..0fe05b1a9 100644 --- a/tests/test_grublock.py +++ b/tests/test_grublock.py @@ -17,7 +17,7 @@ # pylint: disable=invalid-name if is_tf2(): - MultiRNNCell = tf.compat.v1.nn.rnn_cell.MultiRNNCell + MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) dynamic_rnn = tf.compat.v1.nn.dynamic_rnn bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn else: diff --git a/tests/test_lstm.py b/tests/test_lstm.py index 3f9d41e5b..5cfd0df42 100644 --- a/tests/test_lstm.py +++ b/tests/test_lstm.py @@ -21,9 +21,9 @@ if is_tf2(): # There is no LSTMBlockCell in tf-2.x - BasicLSTMCell = tf.compat.v1.nn.rnn_cell.BasicLSTMCell - LSTMCell = tf.compat.v1.nn.rnn_cell.LSTMCell - MultiRNNCell = tf.compat.v1.nn.rnn_cell.MultiRNNCell + BasicLSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "BasicLSTMCell", None) + LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) + MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) dynamic_rnn = tf.compat.v1.nn.dynamic_rnn bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn else: diff --git a/tests/test_lstmblock.py b/tests/test_lstmblock.py index d44e16ebd..ac846dcae 100644 --- a/tests/test_lstmblock.py +++ b/tests/test_lstmblock.py @@ -16,7 +16,7 @@ if is_tf2(): # There is no LSTMBlockCell in tf-2.x - MultiRNNCell = tf.compat.v1.nn.rnn_cell.MultiRNNCell + MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) dynamic_rnn = tf.compat.v1.nn.dynamic_rnn bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn else: diff --git a/tests/test_seq2seq.py b/tests/test_seq2seq.py index 4a6963467..e47f80341 100644 --- a/tests/test_seq2seq.py +++ b/tests/test_seq2seq.py @@ -13,13 +13,13 @@ # pylint: disable=invalid-name if is_tf2(): - BasicLSTMCell = tf.compat.v1.nn.rnn_cell.BasicLSTMCell - LSTMCell = tf.compat.v1.nn.rnn_cell.LSTMCell - RNNCell = tf.compat.v1.nn.rnn_cell.RNNCell - MultiRNNCell = tf.compat.v1.nn.rnn_cell.MultiRNNCell + BasicLSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "BasicLSTMCell", None) + LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) + RNNCell = getattr(tf.compat.v1.nn.rnn_cell, "RNNCell", None) + MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) dynamic_rnn = tf.compat.v1.nn.dynamic_rnn bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn - LSTMStateTuple = tf.compat.v1.nn.rnn_cell.LSTMStateTuple + LSTMStateTuple = getattr(tf.compat.v1.nn.rnn_cell, "LSTMStateTuple", None) else: LSTMCell = tf.contrib.rnn.LSTMCell LSTMBlockCell = tf.contrib.rnn.LSTMBlockCell diff --git a/tests/test_stacked_lstm.py b/tests/test_stacked_lstm.py index 2cfef9bb1..3a36da678 100644 --- a/tests/test_stacked_lstm.py +++ b/tests/test_stacked_lstm.py @@ -16,8 +16,8 @@ # pylint: disable=invalid-name if is_tf2(): - LSTMCell = tf.compat.v1.nn.rnn_cell.LSTMCell - MultiRNNCell = tf.compat.v1.nn.rnn_cell.MultiRNNCell + LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) + MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) dynamic_rnn = tf.compat.v1.nn.dynamic_rnn else: LSTMCell = tf.contrib.rnn.LSTMCell From e4c34090b935047ec8640b217b8f1c0070d708ae Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 17:31:17 +0100 Subject: [PATCH 20/26] fix unit test --- tests/test_cudnn_compatible_gru.py | 4 +--- tests/test_custom_rnncell.py | 8 +------- tests/test_gru.py | 11 +++++++---- tests/test_grublock.py | 5 ++++- tests/test_lstm.py | 9 ++++++--- tests/test_lstmblock.py | 4 +--- tests/test_seq2seq.py | 8 +------- tests/test_stacked_lstm.py | 7 +++++-- tests/utils/setup_test_env.sh | 4 ++-- 9 files changed, 28 insertions(+), 32 deletions(-) diff --git a/tests/test_cudnn_compatible_gru.py b/tests/test_cudnn_compatible_gru.py index f3403a30b..e01f08e6d 100644 --- a/tests/test_cudnn_compatible_gru.py +++ b/tests/test_cudnn_compatible_gru.py @@ -16,9 +16,7 @@ # pylint: disable=missing-docstring,invalid-name,unused-argument,using-constant-test,cell-var-from-loop if is_tf2(): - MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) - dynamic_rnn = tf.compat.v1.nn.dynamic_rnn - bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn + pass else: GRUBlockCell = tf.contrib.rnn.GRUBlockCell MultiRNNCell = tf.contrib.rnn.MultiRNNCell diff --git a/tests/test_custom_rnncell.py b/tests/test_custom_rnncell.py index 55c34d402..4166c8da2 100644 --- a/tests/test_custom_rnncell.py +++ b/tests/test_custom_rnncell.py @@ -16,13 +16,7 @@ # pylint: disable=abstract-method,arguments-differ if is_tf2(): - BasicLSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "BasicLSTMCell", None) - LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) - GRUCell = getattr(tf.compat.v1.nn.rnn_cell, "GRUCell", None) - RNNCell = getattr(tf.compat.v1.nn.rnn_cell, "RNNCell", None) - MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) - dynamic_rnn = tf.compat.v1.nn.dynamic_rnn - bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn + pass else: LSTMBlockCell = tf.contrib.rnn.LSTMBlockCell LSTMCell = tf.nn.rnn_cell.LSTMCell diff --git a/tests/test_gru.py b/tests/test_gru.py index a2d891002..c127c57dc 100644 --- a/tests/test_gru.py +++ b/tests/test_gru.py @@ -34,10 +34,13 @@ if is_tf2(): # There is no LSTMBlockCell in tf-2.x - BasicLSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "BasicLSTMCell", None) - LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) - GRUCell = getattr(tf.compat.v1.nn.rnn_cell, "GRUCell", None) - MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) + try: + BasicLSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "BasicLSTMCell", None) + LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) + GRUCell = getattr(tf.compat.v1.nn.rnn_cell, "GRUCell", None) + MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) + except ImportError: + pass dynamic_rnn = tf.compat.v1.nn.dynamic_rnn bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn else: diff --git a/tests/test_grublock.py b/tests/test_grublock.py index 0fe05b1a9..7418fc128 100644 --- a/tests/test_grublock.py +++ b/tests/test_grublock.py @@ -17,7 +17,10 @@ # pylint: disable=invalid-name if is_tf2(): - MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) + try: + MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) + except ImportError: + pass dynamic_rnn = tf.compat.v1.nn.dynamic_rnn bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn else: diff --git a/tests/test_lstm.py b/tests/test_lstm.py index 5cfd0df42..675298c44 100644 --- a/tests/test_lstm.py +++ b/tests/test_lstm.py @@ -21,9 +21,12 @@ if is_tf2(): # There is no LSTMBlockCell in tf-2.x - BasicLSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "BasicLSTMCell", None) - LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) - MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) + try: + BasicLSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "BasicLSTMCell", None) + LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) + MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) + except ImportError: + pass dynamic_rnn = tf.compat.v1.nn.dynamic_rnn bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn else: diff --git a/tests/test_lstmblock.py b/tests/test_lstmblock.py index ac846dcae..0b8c9f8e1 100644 --- a/tests/test_lstmblock.py +++ b/tests/test_lstmblock.py @@ -16,9 +16,7 @@ if is_tf2(): # There is no LSTMBlockCell in tf-2.x - MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) - dynamic_rnn = tf.compat.v1.nn.dynamic_rnn - bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn + pass else: LSTMBlockCell = tf.contrib.rnn.LSTMBlockCell MultiRNNCell = tf.contrib.rnn.MultiRNNCell diff --git a/tests/test_seq2seq.py b/tests/test_seq2seq.py index e47f80341..51e1255be 100644 --- a/tests/test_seq2seq.py +++ b/tests/test_seq2seq.py @@ -13,13 +13,7 @@ # pylint: disable=invalid-name if is_tf2(): - BasicLSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "BasicLSTMCell", None) - LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) - RNNCell = getattr(tf.compat.v1.nn.rnn_cell, "RNNCell", None) - MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) - dynamic_rnn = tf.compat.v1.nn.dynamic_rnn - bidirectional_dynamic_rnn = tf.compat.v1.nn.bidirectional_dynamic_rnn - LSTMStateTuple = getattr(tf.compat.v1.nn.rnn_cell, "LSTMStateTuple", None) + pass else: LSTMCell = tf.contrib.rnn.LSTMCell LSTMBlockCell = tf.contrib.rnn.LSTMBlockCell diff --git a/tests/test_stacked_lstm.py b/tests/test_stacked_lstm.py index 3a36da678..2b3f877bc 100644 --- a/tests/test_stacked_lstm.py +++ b/tests/test_stacked_lstm.py @@ -16,8 +16,11 @@ # pylint: disable=invalid-name if is_tf2(): - LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) - MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) + try: + LSTMCell = getattr(tf.compat.v1.nn.rnn_cell, "LSTMCell", None) + MultiRNNCell = getattr(tf.compat.v1.nn.rnn_cell, "MultiRNNCell", None) + except ImportError: + pass dynamic_rnn = tf.compat.v1.nn.dynamic_rnn else: LSTMCell = tf.contrib.rnn.LSTMCell diff --git a/tests/utils/setup_test_env.sh b/tests/utils/setup_test_env.sh index 8595f72bd..5c2b6351c 100755 --- a/tests/utils/setup_test_env.sh +++ b/tests/utils/setup_test_env.sh @@ -23,10 +23,10 @@ if [[ $TF_VERSION == 1.* ]]; then pip install numpy==1.19.0 else if [[ "$TF_VERSION" != "2.13.0" && "$TF_VERSION" != "2.9.0" ]]; then - echo "-- install-3 TF-KERAS ${{ inputs.tf_version }}" + echo "-- install-3 TF-KERAS $TF_VERSION" pip install tf_keras==$TF_VERSION else - echo "-- install-3 TF ${{ inputs.tf_version }}" + echo "-- install-3 TF $TF_VERSION" fi fi From 681cb1d25922d19a6ecd2f836a6aebbb89f0e1f2 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 17:46:39 +0100 Subject: [PATCH 21/26] fix np.cast Signed-off-by: xadupre --- .../actions/keras_application_test/action.yml | 3 +- .github/actions/keras_unit_test/action.yml | 2 +- tests/test_custom_rnncell.py | 80 +++++++++---------- tests/utils/setup_test_env.sh | 6 +- tf2onnx/tfonnx.py | 2 +- 5 files changed, 48 insertions(+), 45 deletions(-) diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index ac102d0c0..9a3803755 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -46,6 +46,7 @@ runs: pip install git+https://github.com/qubvel/efficientnet pip install keras-self-attention pip install pytest pytest-cov pytest-runner + pip uninstall -y protobuf if [[ ${{ inputs.tf_version }} == 1.* ]]; then pip install keras==2.3.1 @@ -60,7 +61,7 @@ runs: pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} else echo "-- install-1 TF ${{ inputs.tf_version }}" - pip install "protobuf<3.20" tensorflow==${{ inputs.tf_version }} + pip install protobuf tensorflow==${{ inputs.tf_version }} fi fi diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index d56c8ab83..1b645b982 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -39,7 +39,7 @@ runs: pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} else echo "-- install-2 TF ${{ inputs.tf_version }}" - pip install "protobuf<3.20" tensorflow==${{ inputs.tf_version }} + pip install protobuf tensorflow==${{ inputs.tf_version }} fi fi diff --git a/tests/test_custom_rnncell.py b/tests/test_custom_rnncell.py index 4166c8da2..8cff2d81e 100644 --- a/tests/test_custom_rnncell.py +++ b/tests/test_custom_rnncell.py @@ -16,6 +16,7 @@ # pylint: disable=abstract-method,arguments-differ if is_tf2(): + # no test for tf2 in this file pass else: LSTMBlockCell = tf.contrib.rnn.LSTMBlockCell @@ -26,6 +27,45 @@ dynamic_rnn = tf.nn.dynamic_rnn bidirectional_dynamic_rnn = tf.nn.bidirectional_dynamic_rnn + class GatedGRUCell(RNNCell): + def __init__(self, hidden_dim, reuse=None): + super().__init__(self, _reuse=reuse) + self._num_units = hidden_dim + self._activation = tf.tanh + + @property + def state_size(self): + return self._num_units + + @property + def output_size(self): + return self._num_units + + def call(self, inputs, state): + # inputs shape: [batch size, time step, input size] = [1, 3, 2] + # num_units: 5 + # W shape: [2, 3 * 5] = [2, 15] + # U shape: [5, 3 * 5] = [5, 15] + # b shape: [1, 3 * 5] = [1, 15] + # state shape: [batch size, state size] = [1, 5] + + input_dim = inputs.get_shape()[-1] + assert input_dim is not None, "input dimension must be defined" + # W = tf.get_variable(name="W", shape=[input_dim, 3 * self._num_units], dtype=tf.float32) + W = np.arange(30.0, dtype=np.float32).reshape((2, 15)) + # U = tf.get_variable(name='U', shape=[self._num_units, 3 * self._num_units], dtype=tf.float32) + U = np.arange(75.0, dtype=np.float32).reshape((5, 15)) + # b = tf.get_variable(name='b', shape=[1, 3 * self._num_units], dtype=tf.float32) + b = np.arange(15.0, dtype=np.float32).reshape((1, 15)) + + xw = tf.split(tf.matmul(inputs, W) + b, 3, 1) + hu = tf.split(tf.matmul(state, U), 3, 1) + r = tf.sigmoid(xw[0] + hu[0]) + z = tf.sigmoid(xw[1] + hu[1]) + h1 = self._activation(xw[2] + r * hu[2]) + next_h = h1 * (1 - z) + state * z + return next_h, next_h + class CustomRnnCellTests(Tf2OnnxBackendTestBase): @check_opset_min_version(8, "Scan") @@ -370,45 +410,5 @@ def func(encoder_x, decoder_x, seq_length): self.run_test_case(func, feed_dict, input_names_with_port, output_names_with_port, 0.1) -class GatedGRUCell(RNNCell): - def __init__(self, hidden_dim, reuse=None): - super().__init__(self, _reuse=reuse) - self._num_units = hidden_dim - self._activation = tf.tanh - - @property - def state_size(self): - return self._num_units - - @property - def output_size(self): - return self._num_units - - def call(self, inputs, state): - # inputs shape: [batch size, time step, input size] = [1, 3, 2] - # num_units: 5 - # W shape: [2, 3 * 5] = [2, 15] - # U shape: [5, 3 * 5] = [5, 15] - # b shape: [1, 3 * 5] = [1, 15] - # state shape: [batch size, state size] = [1, 5] - - input_dim = inputs.get_shape()[-1] - assert input_dim is not None, "input dimension must be defined" - # W = tf.get_variable(name="W", shape=[input_dim, 3 * self._num_units], dtype=tf.float32) - W = np.arange(30.0, dtype=np.float32).reshape((2, 15)) - # U = tf.get_variable(name='U', shape=[self._num_units, 3 * self._num_units], dtype=tf.float32) - U = np.arange(75.0, dtype=np.float32).reshape((5, 15)) - # b = tf.get_variable(name='b', shape=[1, 3 * self._num_units], dtype=tf.float32) - b = np.arange(15.0, dtype=np.float32).reshape((1, 15)) - - xw = tf.split(tf.matmul(inputs, W) + b, 3, 1) - hu = tf.split(tf.matmul(state, U), 3, 1) - r = tf.sigmoid(xw[0] + hu[0]) - z = tf.sigmoid(xw[1] + hu[1]) - h1 = self._activation(xw[2] + r * hu[2]) - next_h = h1 * (1 - z) + state * z - return next_h, next_h - - if __name__ == '__main__': unittest_main() diff --git a/tests/utils/setup_test_env.sh b/tests/utils/setup_test_env.sh index 5c2b6351c..164e55309 100755 --- a/tests/utils/setup_test_env.sh +++ b/tests/utils/setup_test_env.sh @@ -17,16 +17,18 @@ echo "==== ONNX version: $ONNX_VERSION" pip install pytest pytest-cov pytest-runner coverage graphviz requests pyyaml pillow pandas parameterized sympy coloredlogs flatbuffers timeout-decorator pip uninstall -y tensorflow -pip install onnx==$ONNX_VERSION onnxruntime==$ORT_VERSION onnxruntime-extensions "tensorflow-text<=$TF_VERSION" tensorflow==$TF_VERSION +pip install onnx==$ONNX_VERSION onnxruntime==$ORT_VERSION onnxruntime-extensions if [[ $TF_VERSION == 1.* ]]; then pip install numpy==1.19.0 else + pip uninstall -y protobuf if [[ "$TF_VERSION" != "2.13.0" && "$TF_VERSION" != "2.9.0" ]]; then echo "-- install-3 TF-KERAS $TF_VERSION" - pip install tf_keras==$TF_VERSION + pip install tf_keras==$TF_VERSION "tensorflow-text<=$TF_VERSION" else echo "-- install-3 TF $TF_VERSION" + pip install "tensorflow-text<=$TF_VERSION" tensorflow==$TF_VERSION protobuf fi fi diff --git a/tf2onnx/tfonnx.py b/tf2onnx/tfonnx.py index c2c881e77..a5e5c6927 100644 --- a/tf2onnx/tfonnx.py +++ b/tf2onnx/tfonnx.py @@ -74,7 +74,7 @@ def rewrite_constant_fold(g, ops): func_map = { "Add": np.add, "GreaterEqual": np.greater_equal, - "Cast": np.cast, + "Cast": lambda x, dtype: x.astype(dtype), "ConcatV2": np.concatenate, "Less": np.less, "ListDiff": np.setdiff1d, From 0e83b27ac01dde1786232528dee6dca1af5e0634 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 17:50:49 +0100 Subject: [PATCH 22/26] fix install Signed-off-by: xadupre --- tests/utils/setup_test_env.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils/setup_test_env.sh b/tests/utils/setup_test_env.sh index 164e55309..ddcab1225 100755 --- a/tests/utils/setup_test_env.sh +++ b/tests/utils/setup_test_env.sh @@ -25,10 +25,10 @@ else pip uninstall -y protobuf if [[ "$TF_VERSION" != "2.13.0" && "$TF_VERSION" != "2.9.0" ]]; then echo "-- install-3 TF-KERAS $TF_VERSION" - pip install tf_keras==$TF_VERSION "tensorflow-text<=$TF_VERSION" + pip install tensorflow==$TF_VERSION tf_keras==$TF_VERSION tensorflow-text else echo "-- install-3 TF $TF_VERSION" - pip install "tensorflow-text<=$TF_VERSION" tensorflow==$TF_VERSION protobuf + pip install tensorflow-text tensorflow==$TF_VERSION protobuf fi fi From f578b484ef59f10e7861a74bb702481d012afb16 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 17:53:51 +0100 Subject: [PATCH 23/26] fix issue Signed-off-by: xadupre --- .github/actions/keras_application_test/action.yml | 2 +- .github/actions/keras_unit_test/action.yml | 2 +- tests/utils/setup_test_env.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index 9a3803755..3c2bf46e2 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -53,7 +53,7 @@ runs: pip install transformers==4.2.0 pip uninstall -y h5py pip install h5py==2.9.0 - pip install numpy==1.19.0 + pip install numpy==1.19.0 tensorflow==${{ inputs.tf_version }} else pip install transformers if [[ "${{ inputs.tf_version }}" != "2.13.0" && "${{ inputs.tf_version }}" != "2.9.0" ]]; then diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index 1b645b982..5e2331641 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -32,7 +32,7 @@ runs: pip install onnxruntime==${{ inputs.ort_version }} pip uninstall -y protobuf if [[ ${{ inputs.tf_version }} == 1.* ]]; then - pip install numpy==1.19.0 + pip install numpy==1.19.0 tensorflow==${{ inputs.tf_version }} else if [[ "${{ inputs.tf_version }}" != "2.13.0" && "${{ inputs.tf_version }}" != "2.9.0" ]]; then echo "-- install-2 TF-KERAS ${{ inputs.tf_version }}" diff --git a/tests/utils/setup_test_env.sh b/tests/utils/setup_test_env.sh index ddcab1225..9a903dd29 100755 --- a/tests/utils/setup_test_env.sh +++ b/tests/utils/setup_test_env.sh @@ -20,7 +20,7 @@ pip uninstall -y tensorflow pip install onnx==$ONNX_VERSION onnxruntime==$ORT_VERSION onnxruntime-extensions if [[ $TF_VERSION == 1.* ]]; then - pip install numpy==1.19.0 + pip install numpy==1.19.0 tensorflow==$TF_VERSION else pip uninstall -y protobuf if [[ "$TF_VERSION" != "2.13.0" && "$TF_VERSION" != "2.9.0" ]]; then From 53771876fd810c60526faaf4f4264f2216795da4 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 18:00:13 +0100 Subject: [PATCH 24/26] fix issues Signed-off-by: xadupre --- .github/actions/keras_application_test/action.yml | 9 +++------ .github/actions/keras_unit_test/action.yml | 10 +++++----- tests/utils/setup_test_env.sh | 5 +++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index 3c2bf46e2..f19edf499 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -46,14 +46,11 @@ runs: pip install git+https://github.com/qubvel/efficientnet pip install keras-self-attention pip install pytest pytest-cov pytest-runner - pip uninstall -y protobuf + pip uninstall -y protobuf h5py if [[ ${{ inputs.tf_version }} == 1.* ]]; then - pip install keras==2.3.1 - pip install transformers==4.2.0 - pip uninstall -y h5py - pip install h5py==2.9.0 - pip install numpy==1.19.0 tensorflow==${{ inputs.tf_version }} + echo "-- install-1 TF1-KERAS ${{ inputs.tf_version }}" + pip install numpy==1.19.0 tensorflow==${{ inputs.tf_version }} protobuf h5py==2.9.0 transformers==4.2.0 keras h5py else pip install transformers if [[ "${{ inputs.tf_version }}" != "2.13.0" && "${{ inputs.tf_version }}" != "2.9.0" ]]; then diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index 5e2331641..66ce90f0a 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -24,22 +24,22 @@ runs: python -m pip install --upgrade pip pip install onnxconverter-common pip install onnx==${{ inputs.onnx_version }} - pip install h5py pip install parameterized pip install timeout-decorator pip install coloredlogs flatbuffers pip install pytest pytest-cov pytest-runner pip install onnxruntime==${{ inputs.ort_version }} - pip uninstall -y protobuf + pip uninstall -y protobuf h5py tensorflow if [[ ${{ inputs.tf_version }} == 1.* ]]; then - pip install numpy==1.19.0 tensorflow==${{ inputs.tf_version }} + echo "-- install-2 TF1-KERAS ${{ inputs.tf_version }}" + pip install numpy==1.19.0 tensorflow==${{ inputs.tf_version }} protobuf keras h5py else if [[ "${{ inputs.tf_version }}" != "2.13.0" && "${{ inputs.tf_version }}" != "2.9.0" ]]; then echo "-- install-2 TF-KERAS ${{ inputs.tf_version }}" - pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} + pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} h5py else echo "-- install-2 TF ${{ inputs.tf_version }}" - pip install protobuf tensorflow==${{ inputs.tf_version }} + pip install protobuf tensorflow==${{ inputs.tf_version }} h5py fi fi diff --git a/tests/utils/setup_test_env.sh b/tests/utils/setup_test_env.sh index 9a903dd29..0c643d854 100755 --- a/tests/utils/setup_test_env.sh +++ b/tests/utils/setup_test_env.sh @@ -16,11 +16,12 @@ echo "==== ONNXRuntime version: $ORT_VERSION" echo "==== ONNX version: $ONNX_VERSION" pip install pytest pytest-cov pytest-runner coverage graphviz requests pyyaml pillow pandas parameterized sympy coloredlogs flatbuffers timeout-decorator -pip uninstall -y tensorflow +pip uninstall -y tensorflow protobuf h5py pip install onnx==$ONNX_VERSION onnxruntime==$ORT_VERSION onnxruntime-extensions if [[ $TF_VERSION == 1.* ]]; then - pip install numpy==1.19.0 tensorflow==$TF_VERSION + echo "-- install-3 TF1-KERAS $TF_VERSION" + pip install numpy==1.19.0 tensorflow==$TF_VERSION protobug keras h5py else pip uninstall -y protobuf if [[ "$TF_VERSION" != "2.13.0" && "$TF_VERSION" != "2.9.0" ]]; then From 03c615f8c95391bfe0312a88b8e4de9a7bb9b877 Mon Sep 17 00:00:00 2001 From: xadupre Date: Tue, 4 Feb 2025 19:03:04 +0100 Subject: [PATCH 25/26] fix ci Signed-off-by: xadupre --- .github/actions/keras_application_test/action.yml | 2 +- .github/actions/keras_unit_test/action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/keras_application_test/action.yml b/.github/actions/keras_application_test/action.yml index f19edf499..f03745e6d 100644 --- a/.github/actions/keras_application_test/action.yml +++ b/.github/actions/keras_application_test/action.yml @@ -55,7 +55,7 @@ runs: pip install transformers if [[ "${{ inputs.tf_version }}" != "2.13.0" && "${{ inputs.tf_version }}" != "2.9.0" ]]; then echo "-- install-1 TF-KERAS ${{ inputs.tf_version }}" - pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} + pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} protobuf else echo "-- install-1 TF ${{ inputs.tf_version }}" pip install protobuf tensorflow==${{ inputs.tf_version }} diff --git a/.github/actions/keras_unit_test/action.yml b/.github/actions/keras_unit_test/action.yml index 66ce90f0a..d5d5171bd 100644 --- a/.github/actions/keras_unit_test/action.yml +++ b/.github/actions/keras_unit_test/action.yml @@ -36,7 +36,7 @@ runs: else if [[ "${{ inputs.tf_version }}" != "2.13.0" && "${{ inputs.tf_version }}" != "2.9.0" ]]; then echo "-- install-2 TF-KERAS ${{ inputs.tf_version }}" - pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} h5py + pip install tf_keras==${{ inputs.tf_version }} tensorflow==${{ inputs.tf_version }} h5py protobuf else echo "-- install-2 TF ${{ inputs.tf_version }}" pip install protobuf tensorflow==${{ inputs.tf_version }} h5py From a0e1d3be07e0c821cf5cc7cc0d7e3cc1a9f8738f Mon Sep 17 00:00:00 2001 From: xadupre Date: Wed, 26 Feb 2025 23:38:28 +0100 Subject: [PATCH 26/26] first try --- Troubleshooting.md | 4 ++ examples/end2end_tfkeras.py | 2 - .../double_and_add_one_custom_op.py | 1 - .../keras2onnx_unit_tests/test_subclassing.py | 45 ++++++++++++++++++- tf2onnx/convert.py | 2 +- 5 files changed, 49 insertions(+), 5 deletions(-) diff --git a/Troubleshooting.md b/Troubleshooting.md index fd9ef4a6a..5aff57cc5 100644 --- a/Troubleshooting.md +++ b/Troubleshooting.md @@ -36,3 +36,7 @@ An example of this is the [ONNX Slice operator before opset-10](https://github.c You can pass the options ```--fold_const```(removed after tf2onnx-1.9.3) in the tf2onnx command line that allows tf2onnx to apply more aggressive constant folding which will increase chances to find a constant. If this doesn't work the model is most likely not to be able to convert to ONNX. We used to see this a lot of issue with the ONNX Slice op and in opset-10 was updated for exactly this reason. + +## cudaSetDevice() on GPU:0 failed. Status: CUDA-capable device(s) is/are busy or unavailable + +See [Regression: TF 2.18 crashes with cudaSetDevice failing due to GPU being busy](https://github.com/tensorflow/tensorflow/issues/78784). diff --git a/examples/end2end_tfkeras.py b/examples/end2end_tfkeras.py index 21ffd2d76..24a95f5dc 100644 --- a/examples/end2end_tfkeras.py +++ b/examples/end2end_tfkeras.py @@ -8,11 +8,9 @@ *onnxruntime*, *tensorflow* and *tensorflow.lite*. """ from onnxruntime import InferenceSession -import os import subprocess import timeit import numpy as np -import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers, Input diff --git a/examples/tf_custom_op/double_and_add_one_custom_op.py b/examples/tf_custom_op/double_and_add_one_custom_op.py index 770324ceb..e8510c414 100644 --- a/examples/tf_custom_op/double_and_add_one_custom_op.py +++ b/examples/tf_custom_op/double_and_add_one_custom_op.py @@ -7,7 +7,6 @@ import os from tf2onnx import utils from tf2onnx.handler import tf_op -from tf2onnx.tf_loader import tf_placeholder DIR_PATH = os.path.realpath(os.path.dirname(__file__)) diff --git a/tests/keras2onnx_unit_tests/test_subclassing.py b/tests/keras2onnx_unit_tests/test_subclassing.py index f4b8ea9d0..cd7de66b6 100644 --- a/tests/keras2onnx_unit_tests/test_subclassing.py +++ b/tests/keras2onnx_unit_tests/test_subclassing.py @@ -49,6 +49,43 @@ def call(self, inputs, **kwargs): return output +def get_save_spec(model, dynamic_batch=False): + """Returns the save spec of the subclassing keras model.""" + from tensorflow.python.framework import tensor_spec + shapes_dict = getattr(model, '_build_shapes_dict', None) + # TODO: restore dynamic_batch + # assert not dynamic_batch, f"get_save_spec: dynamic_batch={dynamic_batch}, shapes_dict={shapes_dict}" + if not shapes_dict: + return None + + if 'input_shape' not in shapes_dict: + raise ValueError( + 'Model {} cannot be saved because the input shapes have not been set.' + ) + + input_shape = shapes_dict['input_shape'] + if isinstance(input_shape, tuple): + shape = input_shape + shape = (None,) + shape[1:] + return tensor_spec.TensorSpec( + shape=shape, dtype=model.input_dtype + ) + elif isinstance(input_shape, dict): + specs = {} + for key, shape in input_shape.items(): + shape = (None,) + shape[1:] + specs[key] = tensor_spec.TensorSpec( + shape=shape, dtype=model.input_dtype, name=key + ) + return specs + elif isinstance(input_shape, list): + specs = [] + for shape in input_shape: + shape = (None,) + shape[1:] + specs.append(tensor_spec.TensorSpec(shape=shape, dtype=model.input_dtype)) + return specs + + class SimpleWrapperModel(tf.keras.Model): def __init__(self, func): super(SimpleWrapperModel, self).__init__() @@ -57,6 +94,9 @@ def __init__(self, func): def call(self, inputs, **kwargs): return self.func(inputs) + def _get_save_spec(self, dynamic_batch=False): + return get_save_spec(self, dynamic_batch=dynamic_batch) + def test_lenet(runner): tf.keras.backend.clear_session() @@ -198,7 +238,10 @@ def _tf_where(input_0): swm = SimpleWrapperModel(_tf_where) const_in = [np.array([2, 4, 6, 8, 10]).astype(np.int32)] expected = swm(const_in) - swm._set_inputs(const_in) + if hasattr(swm, "_set_input"): + swm._set_inputs(const_in) + else: + swm.inputs_spec = const_in oxml = convert_keras(swm) assert runner('where_test', oxml, const_in, expected) diff --git a/tf2onnx/convert.py b/tf2onnx/convert.py index f7ec42add..3ee9d4640 100644 --- a/tf2onnx/convert.py +++ b/tf2onnx/convert.py @@ -447,7 +447,7 @@ def from_keras(model, input_signature=None, opset=None, custom_ops=None, custom_ function = _saving_utils.trace_model_call(model, input_signature) try: concrete_func = function.get_concrete_function() - except TypeError as e: + except (TypeError, AttributeError) as e: # Legacy keras models don't accept the training arg tf provides so we hack around it if "got an unexpected keyword argument 'training'" not in str(e): raise e