Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Support onnx 1.7 and ort 1.3 in UT and nightly build. #496

Merged
merged 39 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4cfa05a
test
jiafatom May 13, 2020
983c18e
Merge branch 'master' into op17_test_1
jiafatom May 20, 2020
9a11209
Merge branch 'master' into op17_test_1
jiafatom May 20, 2020
2c036b3
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
317d558
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
3abf915
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
ea93c69
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
c966034
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
0aa192c
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
b76d85b
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
d10c61f
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
59e68ac
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
895ee27
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
6ff0b99
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
5c75701
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
6072490
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
7b8a7ac
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
2ebc429
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
fc1e754
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
4d8e3e6
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
c0fcc2d
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
17acefe
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
645be90
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
8eb2e20
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
cbf8a95
Merge branch 'master' into op17_test_1
jiafatom May 21, 2020
8b9e874
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 21, 2020
b220e93
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
c6b3774
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
2faeda6
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
c7586ff
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
9833722
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
a368857
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
c88fa54
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
e1da542
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
2c11347
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
c835579
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
4dd8d96
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
4ebb36a
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
d6276ab
Merge branch 'op17_test_1' of https://github.com/jiafatom/keras-onnx …
jiafatom May 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .azure-pipelines/linux-CI-keras-applications-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ jobs:
INSTALL_KERAS: pip install keras
UNINSTALL_KERAS:
INSTALL_TENSORFLOW: pip install tensorflow==1.15.0
INSTALL_ORT: pip install onnxruntime==1.1.1
INSTALL_ORT: pip install onnxruntime==1.3.0
INSTALL_KERAS_RESNET: pip install keras-resnet
INSTALL_TRANSFORMERS:
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py"

Python37-tf2:
python.version: '3.7.3'
jiafatom marked this conversation as resolved.
Show resolved Hide resolved
ONNX_PATH: onnx==1.6.0
python.version: '3.8'
ONNX_PATH: onnx==1.7.0
INSTALL_KERAS:
UNINSTALL_KERAS: pip uninstall keras -y
INSTALL_TENSORFLOW: pip install tensorflow==2.2.0
Expand Down
6 changes: 6 additions & 0 deletions .azure-pipelines/linux-conda-CI-tf-keras.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ jobs:
TENSORFLOW_PATH: tensorflow-cpu
INSTALL_ORT:

Python38:
python.version: '3.8'
ONNX_PATH: onnx==1.7.0
TENSORFLOW_PATH: tensorflow-cpu
INSTALL_ORT:

maxParallel: 3

steps:
Expand Down
10 changes: 9 additions & 1 deletion .azure-pipelines/linux-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ jobs:
TENSORFLOW_PATH: tensorflow==1.15.0
INSTALL_ORT: pip install onnxruntime==1.1.1

Python37-tf200:
jiafatom marked this conversation as resolved.
Show resolved Hide resolved
# UT for standalone keras need tensorflow <= 2.0.0
Python37-tf200-onnx160:
python.version: '3.7'
ONNX_PATH: onnx==1.6.0
KERAS: keras
TENSORFLOW_PATH: tensorflow==2.0.0
INSTALL_ORT:

Python37-tf200-onnx170:
python.version: '3.7'
ONNX_PATH: onnx==1.7.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.6?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

KERAS: keras
TENSORFLOW_PATH: tensorflow==2.0.0
INSTALL_ORT:

maxParallel: 3

steps:
Expand Down
8 changes: 4 additions & 4 deletions .azure-pipelines/win32-CI-keras-applications-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ jobs:
INSTALL_TRANSFORMERS:
NIGHTLY_BUILD_TEST: python run_all.py --exclude "test_keras_applications_v2.py test_mask_rcnn.py"

Python37-tf2:
python.version: '3.7'
ONNX_PATH: onnx==1.6.0
Python38-tf2:
python.version: '3.8'
ONNX_PATH: onnx==1.7.0
INSTALL_KERAS:
UNINSTALL_KERAS: pip uninstall keras -y
INSTALL_TENSORFLOW: pip install tensorflow==2.2.0
INSTALL_ORT: pip install onnxruntime==1.1.1
INSTALL_ORT: pip install onnxruntime==1.3.0
INSTALL_KERAS_RESNET: pip install keras-resnet
INSTALL_TRANSFORMERS: pip install transformers
NIGHTLY_BUILD_TEST: pytest test_keras_applications_v2.py test_transformers.py test_efn.py --doctest-modules --junitxml=junit/test-results-v2.xml
Expand Down
6 changes: 6 additions & 0 deletions .azure-pipelines/win32-conda-CI-tf-keras.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ jobs:
TENSORFLOW_PATH: tensorflow-cpu
INSTALL_ORT:

Python38:
python.version: '3.8'
ONNX_PATH: onnx==1.7.0
TENSORFLOW_PATH: tensorflow-cpu
INSTALL_ORT:

maxParallel: 3

steps:
Expand Down
10 changes: 9 additions & 1 deletion .azure-pipelines/win32-conda-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ jobs:
TENSORFLOW_PATH: tensorflow==1.15.0
INSTALL_ORT: pip install onnxruntime==1.1.1

Python37-tf200:
# UT for standalone keras need tensorflow <= 2.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Python37-tf200-onnx160:
python.version: '3.7'
ONNX_PATH: onnx==1.6.0
KERAS: keras
TENSORFLOW_PATH: tensorflow==2.0.0
INSTALL_ORT:

Python37-tf200-onnx170:
python.version: '3.7'
ONNX_PATH: onnx==1.7.0
KERAS: keras
TENSORFLOW_PATH: tensorflow==2.0.0
INSTALL_ORT:

maxParallel: 3

steps:
Expand Down
11 changes: 5 additions & 6 deletions applications/nightly_build/test_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,18 @@ def test_TFGPT2(self):
def test_TFXLNet(self):
if enable_full_transformer_test:
from transformers import XLNetConfig, TFXLNetModel, TFXLNetLMHeadModel, TFXLNetForSequenceClassification, \
TFXLNetForTokenClassification, TFXLNetForQuestionAnsweringSimple
TFXLNetForTokenClassification, TFXLNetForQuestionAnsweringSimple, XLNetTokenizer
model_list = [TFXLNetModel, TFXLNetLMHeadModel, TFXLNetForSequenceClassification, \
TFXLNetForTokenClassification, TFXLNetForQuestionAnsweringSimple]
else:
from transformers import XLNetConfig, TFXLNetModel
from transformers import XLNetConfig, TFXLNetModel, XLNetTokenizer
model_list = [TFXLNetModel]

# pretrained_weights = 'xlnet-large-cased'
tokenizer_file = 'xlnet_xlnet-large-cased.pickle'
tokenizer = self._get_tokenzier(tokenizer_file)
# XLNetTokenizer need SentencePiece, so the pickle file does not work here.
tokenizer = XLNetTokenizer.from_pretrained('xlnet-large-cased')
config = XLNetConfig(n_layer=2)
# The model with input mask has MatrixDiagV3 which is not a registered function/op
token = tokenizer.encode(self.text_str, add_special_tokens=True)
token = np.asarray(tokenizer.encode(self.text_str, add_special_tokens=True), dtype=np.int32)
inputs_onnx = {'input_1': np.expand_dims(token, axis=0)}
inputs = tf.constant(token)[None, :] # Batch size 1

Expand Down
22 changes: 20 additions & 2 deletions keras2onnx/_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,26 @@ def convert_tf_one_hot(scope, operator, container):
name=operator.full_name + '_one_hot', axis=axis)


@converter_func(TYPES.Pow)
def convert_tf_pow(scope, operator, container):
oopb = OnnxOperatorBuilder(container, scope)
node = operator.raw_operator
jiafatom marked this conversation as resolved.
Show resolved Hide resolved
if container.target_opset < 12:
supported_types = [oopb.float16, oopb.float, oopb.double]
for input_idx_ in range(2):
dtype = _to_onnx_type(node.inputs[input_idx_].dtype)
if dtype not in supported_types:
raise ValueError("The input type of Pow is not supported for opset < 12.")
dtype = _to_onnx_type(node.outputs[0].dtype)
if dtype not in supported_types:
raise ValueError("The output type of Pow is not supported for opset < 12.")

oopb.apply_op_with_output("apply_pow",
operator.input_full_names,
operator.output_full_names,
name=operator.full_name)


@converter_func(TYPES.ReadVariableOp)
def convert_tf_read_variable_op(scope, operator, container):
oopb = OnnxOperatorBuilder(container, scope)
Expand Down Expand Up @@ -1835,7 +1855,6 @@ def _prepare_StridedSlice(node, target_opset):
# onnx slice op can't remove a axis, track axis and add a squeeze op if needed
needs_squeeze = []
ellipsis_gap = 0
data_input = node.inputs[0]

new_axis_len = 0
cur_new_axis_mask = new_axis_mask
Expand Down Expand Up @@ -2121,7 +2140,6 @@ def convert_tf_zeros_like(scope, operator, container):
"Log": ("apply_log",),
"Mul": ("apply_mul",),
"Neg": ("apply_neg",),
"Pow": ("apply_pow",),
"RealDiv": ("apply_div",),
"Reciprocal": ("apply_reciprocal",),
"Relu": ("apply_relu",),
Expand Down
1 change: 1 addition & 0 deletions keras2onnx/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class TYPES:
Pack = 'Pack'
Pad = 'Pad'
PadV2 = 'PadV2'
Pow = 'Pow'
Prod = 'Prod'
Range = 'Range'
ReadVariableOp = 'ReadVariableOp'
Expand Down
21 changes: 21 additions & 0 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,27 @@ def test_tf_bias_add(runner):
assert runner('onnx_bias_add', onnx_model, data, expected)


def test_tf_clip(runner):
model = Sequential()
model.add(Lambda(lambda x: K.clip(x, 0, 10), input_shape=[5, 5]))
data = np.random.randint(-5, 15, size=(1, 5, 5)).astype(np.float32)
expected = model.predict(data)
onnx_model = keras2onnx.convert_keras(model, 'test_tf_clip')
assert runner('onnx_tf_clip', onnx_model, data, expected)


@pytest.mark.skipif(get_maximum_opset_supported() < 12,
reason="Result mismatch on ORT, skip conversion for unsupported types.")
def test_tf_pow(runner):
model = Sequential()
y = tf.constant([[2.0, 2.0], [2.0, 2.0]])
model.add(Lambda(lambda x: tf.math.pow(tf.cast(x, tf.int32), tf.cast(y, tf.int32)), input_shape=[2, 2]))
data = (100 * np.random.rand(3, 2, 2)).astype(np.float32)
expected = model.predict(data)
onnx_model = keras2onnx.convert_keras(model, 'test_tf_pow')
assert runner('onnx_tf_pow', onnx_model, data, expected)


def test_tf_concat(runner):
def my_func_1(x):
return tf.concat([x[0], x[1]], 1)
Expand Down