Skip to content

Commit 59e09b1

Browse files
authored
Merge branch 'main' into main
2 parents 8f9756c + 14f04ff commit 59e09b1

File tree

8 files changed

+91
-22
lines changed

8 files changed

+91
-22
lines changed

.github/workflows/keras_application_test_ci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
- name: Upload Test Results
3636
if: always()
37-
uses: actions/upload-artifact@v3
37+
uses: actions/upload-artifact@v4
3838
with:
3939
name: Test Results (Py38-TF2.9-ubuntu)
4040
path: ./**/test-results-*.xml
@@ -58,7 +58,7 @@ jobs:
5858

5959
- name: Upload Test Results
6060
if: always()
61-
uses: actions/upload-artifact@v3
61+
uses: actions/upload-artifact@v4
6262
with:
6363
name: Test Results (Py310-TF2.15-ubuntu)
6464
path: ./**/test-results-*.xml
@@ -82,7 +82,7 @@ jobs:
8282

8383
- name: Upload Test Results
8484
if: always()
85-
uses: actions/upload-artifact@v3
85+
uses: actions/upload-artifact@v4
8686
with:
8787
name: Test Results (Py37-TF1.15-ubuntu)
8888
path: ./**/test-results-*.xml
@@ -119,7 +119,7 @@ jobs:
119119
onnx_version: ${{ matrix.onnx_version }}
120120
- name: Upload Test Results
121121
if: always()
122-
uses: actions/upload-artifact@v3
122+
uses: actions/upload-artifact@v4
123123
with:
124124
name: Test Results (${{ matrix.python_version }}-${{ matrix.tf_version }}-${{ matrix.os }})
125125
path: ./**/test-results*.xml
@@ -134,7 +134,7 @@ jobs:
134134
if: always()
135135
steps:
136136
- name: Download Artifacts
137-
uses: actions/download-artifact@v3
137+
uses: actions/download-artifact@v4
138138
with:
139139
path: artifacts
140140

.github/workflows/keras_unit_test_ci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
- name: Upload Test Results
3535
if: always()
36-
uses: actions/upload-artifact@v3
36+
uses: actions/upload-artifact@v4
3737
with:
3838
name: Test Results (Py38-TF2.9-ubuntu)
3939
path: ./**/test-results-*.xml
@@ -57,7 +57,7 @@ jobs:
5757

5858
- name: Upload Test Results
5959
if: always()
60-
uses: actions/upload-artifact@v3
60+
uses: actions/upload-artifact@v4
6161
with:
6262
name: Test Results (Py310-TF2.15-ubuntu)
6363
path: ./**/test-results-*.xml
@@ -81,7 +81,7 @@ jobs:
8181

8282
- name: Upload Test Results
8383
if: always()
84-
uses: actions/upload-artifact@v3
84+
uses: actions/upload-artifact@v4
8585
with:
8686
name: Test Results (Py37-TF1.15-ubuntu)
8787
path: ./**/test-results-*.xml
@@ -118,7 +118,7 @@ jobs:
118118
onnx_version: ${{ matrix.onnx_version }}
119119
- name: Upload Test Results
120120
if: always()
121-
uses: actions/upload-artifact@v3
121+
uses: actions/upload-artifact@v4
122122
with:
123123
name: Test Results (${{ matrix.python_version }}-${{ matrix.tf_version }}-${{ matrix.os }})
124124
path: ./**/test-results*.xml
@@ -133,7 +133,7 @@ jobs:
133133
if: always()
134134
steps:
135135
- name: Download Artifacts
136-
uses: actions/download-artifact@v3
136+
uses: actions/download-artifact@v4
137137
with:
138138
path: artifacts
139139

.github/workflows/pretrained_model_test_ci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737

3838
- name: Upload Test Results
3939
if: always()
40-
uses: actions/upload-artifact@v3
40+
uses: actions/upload-artifact@v4
4141
with:
4242
name: Test Results (Py38-TF2.9-18-ubuntu)
4343
path: ./**/test-results-*.xml
@@ -64,7 +64,7 @@ jobs:
6464

6565
- name: Upload Test Results
6666
if: always()
67-
uses: actions/upload-artifact@v3
67+
uses: actions/upload-artifact@v4
6868
with:
6969
name: Test Results (Py310-TF2.15-18-ubuntu)
7070
path: ./**/test-results-*.xml
@@ -90,7 +90,7 @@ jobs:
9090

9191
- name: Upload Test Results
9292
if: always()
93-
uses: actions/upload-artifact@v3
93+
uses: actions/upload-artifact@v4
9494
with:
9595
name: Test Results (Py37-TF1.15-15-ubuntu)
9696
path: ./**/test-results-*.xml
@@ -132,7 +132,7 @@ jobs:
132132

133133
- name: Upload Test Results
134134
if: always()
135-
uses: actions/upload-artifact@v3
135+
uses: actions/upload-artifact@v4
136136
with:
137137
name: Test Results (Py${{ matrix.python_version }}_TF${{ matrix.tf_version }}_${{ matrix.os }}_${{ matrix.opset_version }}_${{ matrix.ort_version }}_${{ matrix.skip_tflite }})
138138
path: ./**/test-results-*.xml
@@ -147,7 +147,7 @@ jobs:
147147
if: always()
148148
steps:
149149
- name: Download Artifacts
150-
uses: actions/download-artifact@v3
150+
uses: actions/download-artifact@v4
151151
with:
152152
path: artifacts
153153

.github/workflows/unit_test_ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737

3838
- name: Upload Test Results
3939
if: always()
40-
uses: actions/upload-artifact@v3
40+
uses: actions/upload-artifact@v4
4141
with:
4242
name: Test Results (Py38-TF2.9-18-ubuntu)
4343
path: ./**/test-results-*.xml
@@ -64,7 +64,7 @@ jobs:
6464

6565
- name: Upload Test Results
6666
if: always()
67-
uses: actions/upload-artifact@v3
67+
uses: actions/upload-artifact@v4
6868
with:
6969
name: Test Results (Py310-TF2.15-18-ubuntu)
7070
path: ./**/test-results-*.xml
@@ -115,7 +115,7 @@ jobs:
115115

116116
- name: Upload Test Results
117117
if: always()
118-
uses: actions/upload-artifact@v3
118+
uses: actions/upload-artifact@v4
119119
with:
120120
name: Test Results (Py${{ matrix.python_version }}_TF${{ matrix.tf_version }}_${{ matrix.os }}_${{ matrix.opset_version }}_${{ matrix.ort_version }}_${{ matrix.skip_tflite }})
121121
path: ./**/test-results-*.xml
@@ -130,7 +130,7 @@ jobs:
130130
if: always()
131131
steps:
132132
- name: Download Artifacts
133-
uses: actions/download-artifact@v3
133+
uses: actions/download-artifact@v4
134134
with:
135135
path: artifacts
136136

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ __pycache__
1111
.cache
1212
.eggs
1313
*.egg-info
14+
*.onnx
1415
run.sh
1516
node_modules/*
1617
tests/tfhub/*/*.onnx

tests/keras2onnx_unit_tests/conftest.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def runner_func(*args, **kwargs):
2626
return run_onnx_runtime(*args, model_files, **kwargs)
2727

2828
# Ensure Keras layer naming is reset for each function
29-
K.reset_uids()
29+
if hasattr(K, "reset_uids"):
30+
# see https://github.com/onnx/tensorflow-onnx/issues/2370
31+
K.reset_uids()
3032
# Reset the TensorFlow session to avoid resource leaking between tests
3133
K.clear_session()
3234

tests/keras2onnx_unit_tests/test_utils.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
# Mapping opset to ONNXRuntime version.
1919
ORT_OPSET_VERSION = {
2020
"1.6.0": 13, "1.7.0": 13, "1.8.0": 14, "1.9.0": 15, "1.10.0": 15, "1.11.0": 16,
21-
"1.12.0": 17, "1.13.0": 17, "1.14.0": 18, "1.15.0": 18, "1.16.0": 18
21+
"1.12.0": 17, "1.13.0": 17, "1.14.0": 18, "1.15.0": 18, "1.16.0": 18, "1.17.0": 18,
22+
"1.18.0": 18, "1.19.0": 18, "1.20.0": 18,
2223
}
2324

2425
working_path = os.path.abspath(os.path.dirname(__file__))
@@ -319,13 +320,14 @@ def get_max_opset_supported_by_ort():
319320
if ort_ver in ORT_OPSET_VERSION.keys():
320321
return ORT_OPSET_VERSION[ort_ver]
321322
else:
322-
print("Given onnxruntime version doesn't exist in ORT_OPSET_VERSION: {}".format(ort_ver))
323323
return None
324324
except ImportError:
325325
return None
326326

327327

328328
def get_max_opset_supported_for_test():
329+
if get_max_opset_supported_by_ort() is None:
330+
return get_maximum_opset_supported()
329331
return min(get_max_opset_supported_by_ort(), get_maximum_opset_supported())
330332

331333

tests/test_issue_2025.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# pylint: disable=missing-docstring,unused-import,import-outside-toplevel,unused-variable
3+
import unittest
4+
from backend_test_base import Tf2OnnxBackendTestBase
5+
6+
7+
class TestIssue2025(Tf2OnnxBackendTestBase):
8+
def test_tanhgrad(self):
9+
10+
import tensorflow as tf
11+
import tf2onnx
12+
from tf2onnx.handler import tf_op
13+
import numpy as np
14+
15+
@tf_op("TanhGrad")
16+
class TanhGrad:
17+
@classmethod
18+
def version_1(cls, ctx, node, **_kwargs):
19+
tanh_output = node.input[0]
20+
grad = node.input[1]
21+
square = ctx.make_node("Mul", [tanh_output, tanh_output])
22+
one = ctx.make_const(
23+
name=node.name + "_one", np_val=np.array(1, dtype=np.float32)
24+
)
25+
derivative = ctx.make_node("Sub", [one.output[0], square.output[0]])
26+
result = ctx.make_node("Mul", [derivative.output[0], grad])
27+
ctx.replace_all_inputs(node.output[0], result.output[0])
28+
return result.output
29+
30+
class QFGrad(tf.keras.Model):
31+
def __init__(self):
32+
super().__init__()
33+
self.output_names = ["grad"]
34+
35+
def calc_q_grad(self, x):
36+
with tf.GradientTape() as tape:
37+
tape.watch(x)
38+
y = tf.keras.activations.tanh(tf.abs(x))
39+
# tf.raw_ops.TanhGrad
40+
x_grad = tape.gradient(y, x)
41+
return x_grad
42+
43+
def call(self, x):
44+
q_grad = self.calc_q_grad(x)
45+
return q_grad
46+
47+
model = QFGrad()
48+
x = tf.random.uniform((1, 1, 6))
49+
model(x)
50+
51+
save_path = "test_tanhgrad.onnx"
52+
model_proto, _ = tf2onnx.convert.from_keras(
53+
model=model,
54+
input_signature=(tf.TensorSpec((1, 1, 6), dtype=tf.float32, name="x"),),
55+
opset=13,
56+
output_path=save_path,
57+
)
58+
node_types = [n.op_type for n in model_proto.graph.node]
59+
self.assertNotIn("TanhGrad", node_types)
60+
61+
62+
63+
if __name__ == "__main__":
64+
unittest.main()

0 commit comments

Comments
 (0)