diff --git a/ci_build/azure_pipelines/onnxruntime_nightly_test.yml b/ci_build/azure_pipelines/onnxruntime_nightly_test.yml index b14066f49..632d563b7 100644 --- a/ci_build/azure_pipelines/onnxruntime_nightly_test.yml +++ b/ci_build/azure_pipelines/onnxruntime_nightly_test.yml @@ -68,7 +68,7 @@ stages: parameters: platforms: ['linux'] python_versions: ['3.9'] - tf_versions: ['2.5.0'] + tf_versions: ['2.8.0'] onnx_opsets: [''] onnx_backends: {onnxruntime: ['nightly']} job: diff --git a/ci_build/azure_pipelines/pretrained_model_test-matrix.yml b/ci_build/azure_pipelines/pretrained_model_test-matrix.yml index a2cd1ee38..d14fcdcda 100755 --- a/ci_build/azure_pipelines/pretrained_model_test-matrix.yml +++ b/ci_build/azure_pipelines/pretrained_model_test-matrix.yml @@ -28,11 +28,20 @@ jobs: steps: - template: 'pretrained_model_test.yml' +- template: 'templates/job_generator.yml' + parameters: + platforms: ['linux', 'windows'] + python_versions: ['3.9'] + tf_versions: ['2.6.2'] + job: + steps: + - template: 'pretrained_model_test.yml' + - template: 'templates/job_generator.yml' parameters: platforms: ['linux', 'windows'] python_versions: ['3.8'] - tf_versions: ['2.5.0'] + tf_versions: ['2.7.0'] job: steps: - template: 'pretrained_model_test.yml' @@ -40,8 +49,8 @@ jobs: - template: 'templates/job_generator.yml' parameters: platforms: ['linux', 'windows'] - python_versions: ['3.9'] - tf_versions: ['2.6.2'] + python_versions: ['3.8'] + tf_versions: ['2.8.0'] job: steps: - template: 'pretrained_model_test.yml' diff --git a/ci_build/azure_pipelines/pretrained_model_test.yml b/ci_build/azure_pipelines/pretrained_model_test.yml index 08b19589d..0fe9900f5 100644 --- a/ci_build/azure_pipelines/pretrained_model_test.yml +++ b/ci_build/azure_pipelines/pretrained_model_test.yml @@ -15,18 +15,18 @@ jobs: - template: 'templates/job_generator.yml' parameters: - # 2.6, tf + # 2.7, tf python_versions: ['3.7'] - tf_versions: ['1.15.5','2.6.2'] + tf_versions: ['1.15.5','2.7.0'] job: steps: - template: 'pretrained_model_test.yml' - template: 'templates/job_generator.yml' parameters: - # 2.7, tf + # 2.8, tf python_versions: ['3.9'] - tf_versions: ['2.7.0'] + tf_versions: ['2.8.0'] job: steps: - template: 'pretrained_model_test.yml' diff --git a/ci_build/azure_pipelines/templates/keras2onnx_application_tests.yml b/ci_build/azure_pipelines/templates/keras2onnx_application_tests.yml index 10b0bc08f..232bd3a90 100644 --- a/ci_build/azure_pipelines/templates/keras2onnx_application_tests.yml +++ b/ci_build/azure_pipelines/templates/keras2onnx_application_tests.yml @@ -20,7 +20,6 @@ steps: conda config --set always_yes yes --set changeps1 no pip install $(ONNX_PATH) pip install h5py==2.9.0 - pip install numpy==1.19 pip install parameterized $(INSTALL_TENSORFLOW) $(INSTALL_KERAS) @@ -82,7 +81,6 @@ steps: pip uninstall -y protobuf pip install protobuf pip install h5py==2.9.0 - pip install numpy==1.19 pip install parameterized %INSTALL_TENSORFLOW% %INSTALL_KERAS% diff --git a/ci_build/azure_pipelines/templates/keras2onnx_unit_test.yml b/ci_build/azure_pipelines/templates/keras2onnx_unit_test.yml index babcede4d..202189755 100644 --- a/ci_build/azure_pipelines/templates/keras2onnx_unit_test.yml +++ b/ci_build/azure_pipelines/templates/keras2onnx_unit_test.yml @@ -20,7 +20,6 @@ steps: conda config --set always_yes yes --set changeps1 no pip install $(ONNX_PATH) pip install h5py==2.9.0 - pip install numpy==1.19 pip install parameterized pip install $(TENSORFLOW_PATH) if [[ ! -z $KERAS ]]; diff --git a/ci_build/azure_pipelines/templates/setup.yml b/ci_build/azure_pipelines/templates/setup.yml index 2a8363dec..0f9e277ec 100644 --- a/ci_build/azure_pipelines/templates/setup.yml +++ b/ci_build/azure_pipelines/templates/setup.yml @@ -49,6 +49,10 @@ steps: then pip install "tensorflow-text>=2.7,<2.8" fi + if [[ $CI_TF_VERSION == 2.8* ]] ; + then + pip install "tensorflow-text>=2.8,<2.9" + fi fi python setup.py install diff --git a/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml b/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml index 7bce1c7a6..c833e1bb2 100644 --- a/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml +++ b/ci_build/azure_pipelines/trimmed_keras2onnx_unit_test.yml @@ -54,7 +54,7 @@ jobs: TENSORFLOW_PATH: tensorflow==1.15.0 INSTALL_ORT: pip install onnxruntime==1.9.0 - Python37-tf2.3: + Python37-tf2.8: python.version: '3.7' ONNX_PATH: onnx==1.10.2 TENSORFLOW_PATH: tensorflow-cpu==2.3.0 diff --git a/ci_build/azure_pipelines/unit_test-matrix.yml b/ci_build/azure_pipelines/unit_test-matrix.yml index 904e7ae5b..19f5c29c3 100644 --- a/ci_build/azure_pipelines/unit_test-matrix.yml +++ b/ci_build/azure_pipelines/unit_test-matrix.yml @@ -58,4 +58,15 @@ stages: - template: 'unit_test.yml' report_coverage: 'True' + - template: 'templates/job_generator.yml' + parameters: + platforms: ['linux', 'windows'] + python_versions: ['3.8'] + tf_versions: ['2.8.0'] + onnx_opsets: [''] + job: + steps: + - template: 'unit_test.yml' + report_coverage: 'True' + - template: 'templates/combine_test_coverage.yml' diff --git a/ci_build/azure_pipelines/unit_test.yml b/ci_build/azure_pipelines/unit_test.yml index 9fec89b84..0cc9d8a0a 100644 --- a/ci_build/azure_pipelines/unit_test.yml +++ b/ci_build/azure_pipelines/unit_test.yml @@ -3,6 +3,43 @@ stages: - stage: jobs: + - template: 'templates/job_generator.yml' + parameters: + # TFJS tf 2.8 + python_versions: ['3.9'] + tf_versions: ['2.8.0'] + onnx_opsets: [''] + skip_tfjs_tests: 'False' + skip_tf_tests: 'True' + job: + steps: + - template: 'unit_test.yml' + report_coverage: 'True' + + - template: 'templates/job_generator.yml' + parameters: + # TFLite tf 2.8 + python_versions: ['3.8'] + tf_versions: ['2.8.0'] + onnx_opsets: [''] + skip_tflite_tests: 'False' + skip_tf_tests: 'True' + job: + steps: + - template: 'unit_test.yml' + report_coverage: 'True' + + - template: 'templates/job_generator.yml' + parameters: + # tf 2.8 + python_versions: ['3.8'] + tf_versions: ['2.8.0'] + onnx_opsets: [''] + job: + steps: + - template: 'unit_test.yml' + report_coverage: 'True' + - template: 'templates/job_generator.yml' parameters: # TFJS tf 2.7 diff --git a/tests/test_backend.py b/tests/test_backend.py index fe25043d9..2205d0fa8 100755 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -305,7 +305,7 @@ def func(x): def test_multinomial(self): x_val = np.array([[10., 10.]], dtype=np.float32) def func(x): - op = multinomial(tf.math.log(x), 5, output_dtype=tf.int64) + op = multinomial(tf.math.log(x), 5, output_dtype=tf.int32) return tf.identity(op, name=_TFOUTPUT) # since returned indexes are random we can only check type and shape @@ -318,7 +318,7 @@ def test_multinomial1(self): shape = [2, 10] x_val = np.ones(np.prod(shape)).astype("float32").reshape(shape) def func(x): - op = multinomial(x, 2, output_dtype=tf.int64) + op = multinomial(x, 2, output_dtype=tf.int32) return tf.identity(op, name=_TFOUTPUT) # since returned indexes are random we can only check type and shape self._run_test_case(func, [_OUTPUT], {_INPUT: x_val}, check_value=False, diff --git a/tf2onnx/tflite/BucketizeOptions.py b/tf2onnx/tflite/BucketizeOptions.py new file mode 100644 index 000000000..84ca89eee --- /dev/null +++ b/tf2onnx/tflite/BucketizeOptions.py @@ -0,0 +1,75 @@ +# SPDX-License-Identifier: Apache-2.0 + +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class BucketizeOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = BucketizeOptions() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsBucketizeOptions(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def BucketizeOptionsBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x54\x46\x4C\x33", size_prefixed=size_prefixed) + + # BucketizeOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # BucketizeOptions + def Boundaries(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + a = self._tab.Vector(o) + return self._tab.Get(flatbuffers.number_types.Float32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return 0 + + # BucketizeOptions + def BoundariesAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Float32Flags, o) + return 0 + + # BucketizeOptions + def BoundariesLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # BucketizeOptions + def BoundariesIsNone(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + return o == 0 + +def Start(builder): builder.StartObject(1) +def BucketizeOptionsStart(builder): + """This method is deprecated. Please switch to Start.""" + return Start(builder) +def AddBoundaries(builder, boundaries): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(boundaries), 0) +def BucketizeOptionsAddBoundaries(builder, boundaries): + """This method is deprecated. Please switch to AddBoundaries.""" + return AddBoundaries(builder, boundaries) +def StartBoundariesVector(builder, numElems): return builder.StartVector(4, numElems, 4) +def BucketizeOptionsStartBoundariesVector(builder, numElems): + """This method is deprecated. Please switch to Start.""" + return StartBoundariesVector(builder, numElems) +def End(builder): return builder.EndObject() +def BucketizeOptionsEnd(builder): + """This method is deprecated. Please switch to End.""" + return End(builder) \ No newline at end of file diff --git a/tf2onnx/tflite/BuiltinOperator.py b/tf2onnx/tflite/BuiltinOperator.py index 6ee01c707..56eca2ef4 100644 --- a/tf2onnx/tflite/BuiltinOperator.py +++ b/tf2onnx/tflite/BuiltinOperator.py @@ -151,4 +151,10 @@ class BuiltinOperator(object): READ_VARIABLE = 143 ASSIGN_VARIABLE = 144 BROADCAST_ARGS = 145 + RANDOM_STANDARD_NORMAL = 146 + BUCKETIZE = 147 + RANDOM_UNIFORM = 148 + MULTINOMIAL = 149 + GELU = 150 + DYNAMIC_UPDATE_SLICE = 151 diff --git a/tf2onnx/tflite/BuiltinOptions.py b/tf2onnx/tflite/BuiltinOptions.py index f0e0c910e..114e7e81f 100644 --- a/tf2onnx/tflite/BuiltinOptions.py +++ b/tf2onnx/tflite/BuiltinOptions.py @@ -119,4 +119,8 @@ class BuiltinOptions(object): VarHandleOptions = 111 ReadVariableOptions = 112 AssignVariableOptions = 113 + RandomOptions = 114 + BucketizeOptions = 115 + GeluOptions = 116 + DynamicUpdateSliceOptions = 117 diff --git a/tf2onnx/tflite/DynamicUpdateSliceOptions.py b/tf2onnx/tflite/DynamicUpdateSliceOptions.py new file mode 100644 index 000000000..aa620697a --- /dev/null +++ b/tf2onnx/tflite/DynamicUpdateSliceOptions.py @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: Apache-2.0 + +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class DynamicUpdateSliceOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = DynamicUpdateSliceOptions() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsDynamicUpdateSliceOptions(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def DynamicUpdateSliceOptionsBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x54\x46\x4C\x33", size_prefixed=size_prefixed) + + # DynamicUpdateSliceOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + +def Start(builder): builder.StartObject(0) +def DynamicUpdateSliceOptionsStart(builder): + """This method is deprecated. Please switch to Start.""" + return Start(builder) +def End(builder): return builder.EndObject() +def DynamicUpdateSliceOptionsEnd(builder): + """This method is deprecated. Please switch to End.""" + return End(builder) \ No newline at end of file diff --git a/tf2onnx/tflite/GeluOptions.py b/tf2onnx/tflite/GeluOptions.py new file mode 100644 index 000000000..41ee0ed68 --- /dev/null +++ b/tf2onnx/tflite/GeluOptions.py @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: Apache-2.0 + +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class GeluOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = GeluOptions() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsGeluOptions(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def GeluOptionsBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x54\x46\x4C\x33", size_prefixed=size_prefixed) + + # GeluOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # GeluOptions + def Approximate(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return bool(self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos)) + return False + +def Start(builder): builder.StartObject(1) +def GeluOptionsStart(builder): + """This method is deprecated. Please switch to Start.""" + return Start(builder) +def AddApproximate(builder, approximate): builder.PrependBoolSlot(0, approximate, 0) +def GeluOptionsAddApproximate(builder, approximate): + """This method is deprecated. Please switch to AddApproximate.""" + return AddApproximate(builder, approximate) +def End(builder): return builder.EndObject() +def GeluOptionsEnd(builder): + """This method is deprecated. Please switch to End.""" + return End(builder) \ No newline at end of file diff --git a/tf2onnx/tflite/RandomOptions.py b/tf2onnx/tflite/RandomOptions.py new file mode 100644 index 000000000..b03e009b8 --- /dev/null +++ b/tf2onnx/tflite/RandomOptions.py @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: Apache-2.0 + +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers +from flatbuffers.compat import import_numpy +np = import_numpy() + +class RandomOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAs(cls, buf, offset=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = RandomOptions() + x.Init(buf, n + offset) + return x + + @classmethod + def GetRootAsRandomOptions(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) + @classmethod + def RandomOptionsBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x54\x46\x4C\x33", size_prefixed=size_prefixed) + + # RandomOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # RandomOptions + def Seed(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int64Flags, o + self._tab.Pos) + return 0 + + # RandomOptions + def Seed2(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int64Flags, o + self._tab.Pos) + return 0 + +def Start(builder): builder.StartObject(2) +def RandomOptionsStart(builder): + """This method is deprecated. Please switch to Start.""" + return Start(builder) +def AddSeed(builder, seed): builder.PrependInt64Slot(0, seed, 0) +def RandomOptionsAddSeed(builder, seed): + """This method is deprecated. Please switch to AddSeed.""" + return AddSeed(builder, seed) +def AddSeed2(builder, seed2): builder.PrependInt64Slot(1, seed2, 0) +def RandomOptionsAddSeed2(builder, seed2): + """This method is deprecated. Please switch to AddSeed2.""" + return AddSeed2(builder, seed2) +def End(builder): return builder.EndObject() +def RandomOptionsEnd(builder): + """This method is deprecated. Please switch to End.""" + return End(builder) \ No newline at end of file diff --git a/tf2onnx/tflite/TensorType.py b/tf2onnx/tflite/TensorType.py index 9948f2152..88345a09f 100644 --- a/tf2onnx/tflite/TensorType.py +++ b/tf2onnx/tflite/TensorType.py @@ -21,4 +21,5 @@ class TensorType(object): RESOURCE = 13 VARIANT = 14 UINT32 = 15 + UINT16 = 16 diff --git a/tf2onnx/tflite_handlers/tfl_direct.py b/tf2onnx/tflite_handlers/tfl_direct.py index c39397174..d38aa8227 100644 --- a/tf2onnx/tflite_handlers/tfl_direct.py +++ b/tf2onnx/tflite_handlers/tfl_direct.py @@ -34,9 +34,12 @@ @tfl_op("TFL_MATRIX_SET_DIAG", tf_op="MatrixSetDiag") @tfl_op("TFL_MAXIMUM", tf_op="Maximum") @tfl_op("TFL_MINIMUM", tf_op="Minimum") +@tfl_op("TFL_MULTINOMIAL", tf_op="Multinomial") @tfl_op("TFL_NEG", tf_op="Neg") @tfl_op("TFL_NOT_EQUAL", tf_op="NotEqual") @tfl_op("TFL_POW", tf_op="Pow") +@tfl_op("TFL_RANDOM_STANDARD_NORMAL", tf_op="RandomNormal") +@tfl_op("TFL_RANDOM_UNIFORM", tf_op="RandomUniform") @tfl_op("TFL_RANK", tf_op="Rank") @tfl_op("TFL_RELU", tf_op="Relu") @tfl_op("TFL_RELU6", tf_op="Relu6") diff --git a/tf2onnx/tflite_utils.py b/tf2onnx/tflite_utils.py index e1a12fa08..b5974c850 100644 --- a/tf2onnx/tflite_utils.py +++ b/tf2onnx/tflite_utils.py @@ -39,6 +39,7 @@ TFLiteTensorType.COMPLEX128: onnx_pb.TensorProto.COMPLEX128, TFLiteTensorType.UINT64: onnx_pb.TensorProto.UINT64, TFLiteTensorType.UINT32: onnx_pb.TensorProto.UINT32, + TFLiteTensorType.UINT16: onnx_pb.TensorProto.UINT16, TFLiteTensorType.RESOURCE: onnx_pb.TensorProto.UNDEFINED, TFLiteTensorType.VARIANT: onnx_pb.TensorProto.UNDEFINED, } @@ -59,6 +60,7 @@ TFLiteTensorType.COMPLEX128: types_pb2.DT_COMPLEX128, TFLiteTensorType.UINT64: types_pb2.DT_UINT64, TFLiteTensorType.UINT32: types_pb2.DT_UINT32, + TFLiteTensorType.UINT16: types_pb2.DT_UINT16, TFLiteTensorType.RESOURCE: types_pb2.DT_RESOURCE, TFLiteTensorType.VARIANT: types_pb2.DT_VARIANT, }