From ce204d07443951f986ce8695790da2418ac25c34 Mon Sep 17 00:00:00 2001 From: Chi Lo <54722500+chilo-ms@users.noreply.github.com> Date: Wed, 16 Mar 2022 09:18:49 -0700 Subject: [PATCH] Update to flatbuffers v2.0.0 (#10866) --- .../CalTableFlatBuffers/KeyValue.py | 30 +++++++++++-------- .../CalTableFlatBuffers/TrtTable.py | 30 +++++++++++-------- .../python/tools/quantization/quant_utils.py | 2 +- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/onnxruntime/python/tools/quantization/CalTableFlatBuffers/KeyValue.py b/onnxruntime/python/tools/quantization/CalTableFlatBuffers/KeyValue.py index 3d82f2b599dcc..fc5d725db0fdd 100644 --- a/onnxruntime/python/tools/quantization/CalTableFlatBuffers/KeyValue.py +++ b/onnxruntime/python/tools/quantization/CalTableFlatBuffers/KeyValue.py @@ -6,17 +6,20 @@ from flatbuffers.compat import import_numpy np = import_numpy() - class KeyValue(object): __slots__ = ['_tab'] @classmethod - def GetRootAsKeyValue(cls, buf, offset): + def GetRootAs(cls, buf, offset=0): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) x = KeyValue() x.Init(buf, n + offset) return x + @classmethod + def GetRootAsKeyValue(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) # KeyValue def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) @@ -35,18 +38,19 @@ def Value(self): return self._tab.String(o + self._tab.Pos) return None - +def Start(builder): builder.StartObject(2) def KeyValueStart(builder): - builder.StartObject(2) - - + """This method is deprecated. Please switch to Start.""" + return Start(builder) +def AddKey(builder, key): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(key), 0) def KeyValueAddKey(builder, key): - builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(key), 0) - - + """This method is deprecated. Please switch to AddKey.""" + return AddKey(builder, key) +def AddValue(builder, value): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(value), 0) def KeyValueAddValue(builder, value): - builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(value), 0) - - + """This method is deprecated. Please switch to AddValue.""" + return AddValue(builder, value) +def End(builder): return builder.EndObject() def KeyValueEnd(builder): - return builder.EndObject() + """This method is deprecated. Please switch to End.""" + return End(builder) \ No newline at end of file diff --git a/onnxruntime/python/tools/quantization/CalTableFlatBuffers/TrtTable.py b/onnxruntime/python/tools/quantization/CalTableFlatBuffers/TrtTable.py index dcb837256964a..b31f4cac1d4c4 100644 --- a/onnxruntime/python/tools/quantization/CalTableFlatBuffers/TrtTable.py +++ b/onnxruntime/python/tools/quantization/CalTableFlatBuffers/TrtTable.py @@ -6,17 +6,20 @@ from flatbuffers.compat import import_numpy np = import_numpy() - class TrtTable(object): __slots__ = ['_tab'] @classmethod - def GetRootAsTrtTable(cls, buf, offset): + def GetRootAs(cls, buf, offset=0): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) x = TrtTable() x.Init(buf, n + offset) return x + @classmethod + def GetRootAsTrtTable(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) # TrtTable def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) @@ -46,18 +49,19 @@ def DictIsNone(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) return o == 0 - +def Start(builder): builder.StartObject(1) def TrtTableStart(builder): - builder.StartObject(1) - - + """This method is deprecated. Please switch to Start.""" + return Start(builder) +def AddDict(builder, dict): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(dict), 0) def TrtTableAddDict(builder, dict): - builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(dict), 0) - - + """This method is deprecated. Please switch to AddDict.""" + return AddDict(builder, dict) +def StartDictVector(builder, numElems): return builder.StartVector(4, numElems, 4) def TrtTableStartDictVector(builder, numElems): - return builder.StartVector(4, numElems, 4) - - + """This method is deprecated. Please switch to Start.""" + return StartDictVector(builder, numElems) +def End(builder): return builder.EndObject() def TrtTableEnd(builder): - return builder.EndObject() + """This method is deprecated. Please switch to End.""" + return End(builder) \ No newline at end of file diff --git a/onnxruntime/python/tools/quantization/quant_utils.py b/onnxruntime/python/tools/quantization/quant_utils.py index bb9ec646a7cf1..8cd0814dd3f9c 100644 --- a/onnxruntime/python/tools/quantization/quant_utils.py +++ b/onnxruntime/python/tools/quantization/quant_utils.py @@ -393,7 +393,7 @@ def write_calibration_table(calibration_cache): TrtTable.TrtTableStartDictVector(builder, len(key_value_list)) for key_value in key_value_list: builder.PrependUOffsetTRelative(key_value) - main_dict = builder.EndVector(len(key_value_list)) + main_dict = builder.EndVector() TrtTable.TrtTableStart(builder) TrtTable.TrtTableAddDict(builder, main_dict)