Skip to content

Commit

Permalink
Update to flatbuffers v2.0.0 (microsoft#10866)
Browse files Browse the repository at this point in the history
  • Loading branch information
chilo-ms authored and lavanyax committed Mar 29, 2022
1 parent 3e0e6ec commit fac3712
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion onnxruntime/python/tools/quantization/quant_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fac3712

Please sign in to comment.