@@ -32,13 +32,16 @@ class TensorType(object):
32
32
class QuantizationDetails(object):
33
33
NONE = 0
34
34
CustomQuantization = 1
35
+ BlockwiseQuantization = 2
35
36
36
37
def QuantizationDetailsCreator(unionType, table):
37
38
from flatbuffers.table import Table
38
39
if not isinstance(table, Table):
39
40
return None
40
41
if unionType == QuantizationDetails().CustomQuantization:
41
42
return CustomQuantizationT.InitFromBuf(table.Bytes, table.Pos)
43
+ if unionType == QuantizationDetails().BlockwiseQuantization:
44
+ return BlockwiseQuantizationT.InitFromBuf(table.Bytes, table.Pos)
42
45
return None
43
46
44
47
@@ -949,6 +952,109 @@ def Pack(self, builder):
949
952
return customQuantization
950
953
951
954
955
+ class BlockwiseQuantization(object):
956
+ __slots__ = ['_tab']
957
+
958
+ @classmethod
959
+ def GetRootAs(cls, buf, offset=0):
960
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
961
+ x = BlockwiseQuantization()
962
+ x.Init(buf, n + offset)
963
+ return x
964
+
965
+ @classmethod
966
+ def GetRootAsBlockwiseQuantization(cls, buf, offset=0):
967
+ """This method is deprecated. Please switch to GetRootAs."""
968
+ return cls.GetRootAs(buf, offset)
969
+ @classmethod
970
+ def BlockwiseQuantizationBufferHasIdentifier(cls, buf, offset, size_prefixed=False):
971
+ return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x54\x46\x4C\x33", size_prefixed=size_prefixed)
972
+
973
+ # BlockwiseQuantization
974
+ def Init(self, buf, pos):
975
+ self._tab = flatbuffers.table.Table(buf, pos)
976
+
977
+ # BlockwiseQuantization
978
+ def Scales(self):
979
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
980
+ if o != 0:
981
+ return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos)
982
+ return 0
983
+
984
+ # BlockwiseQuantization
985
+ def ZeroPoints(self):
986
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
987
+ if o != 0:
988
+ return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos)
989
+ return 0
990
+
991
+ # BlockwiseQuantization
992
+ def BlockSize(self):
993
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
994
+ if o != 0:
995
+ return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos)
996
+ return 0
997
+
998
+ def BlockwiseQuantizationStart(builder):
999
+ builder.StartObject(3)
1000
+
1001
+ def BlockwiseQuantizationAddScales(builder, scales):
1002
+ builder.PrependInt32Slot(0, scales, 0)
1003
+
1004
+ def BlockwiseQuantizationAddZeroPoints(builder, zeroPoints):
1005
+ builder.PrependInt32Slot(1, zeroPoints, 0)
1006
+
1007
+ def BlockwiseQuantizationAddBlockSize(builder, blockSize):
1008
+ builder.PrependInt32Slot(2, blockSize, 0)
1009
+
1010
+ def BlockwiseQuantizationEnd(builder):
1011
+ return builder.EndObject()
1012
+
1013
+
1014
+
1015
+ class BlockwiseQuantizationT(object):
1016
+
1017
+ # BlockwiseQuantizationT
1018
+ def __init__(self):
1019
+ self.scales = 0 # type: int
1020
+ self.zeroPoints = 0 # type: int
1021
+ self.blockSize = 0 # type: int
1022
+
1023
+ @classmethod
1024
+ def InitFromBuf(cls, buf, pos):
1025
+ blockwiseQuantization = BlockwiseQuantization()
1026
+ blockwiseQuantization.Init(buf, pos)
1027
+ return cls.InitFromObj(blockwiseQuantization)
1028
+
1029
+ @classmethod
1030
+ def InitFromPackedBuf(cls, buf, pos=0):
1031
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
1032
+ return cls.InitFromBuf(buf, pos+n)
1033
+
1034
+ @classmethod
1035
+ def InitFromObj(cls, blockwiseQuantization):
1036
+ x = BlockwiseQuantizationT()
1037
+ x._UnPack(blockwiseQuantization)
1038
+ return x
1039
+
1040
+ # BlockwiseQuantizationT
1041
+ def _UnPack(self, blockwiseQuantization):
1042
+ if blockwiseQuantization is None:
1043
+ return
1044
+ self.scales = blockwiseQuantization.Scales()
1045
+ self.zeroPoints = blockwiseQuantization.ZeroPoints()
1046
+ self.blockSize = blockwiseQuantization.BlockSize()
1047
+
1048
+ # BlockwiseQuantizationT
1049
+ def Pack(self, builder):
1050
+ BlockwiseQuantizationStart(builder)
1051
+ BlockwiseQuantizationAddScales(builder, self.scales)
1052
+ BlockwiseQuantizationAddZeroPoints(builder, self.zeroPoints)
1053
+ BlockwiseQuantizationAddBlockSize(builder, self.blockSize)
1054
+ blockwiseQuantization = BlockwiseQuantizationEnd(builder)
1055
+ return blockwiseQuantization
1056
+
1057
+
952
1058
class QuantizationParameters(object):
953
1059
__slots__ = ['_tab']
954
1060
@@ -1157,7 +1263,7 @@ def __init__(self):
1157
1263
self.scale = None # type: List[float]
1158
1264
self.zeroPoint = None # type: List[int]
1159
1265
self.detailsType = 0 # type: int
1160
- self.details = None # type: Union[None, CustomQuantizationT]
1266
+ self.details = None # type: Union[None, CustomQuantizationT, BlockwiseQuantizationT ]
1161
1267
self.quantizedDimension = 0 # type: int
1162
1268
1163
1269
@classmethod
0 commit comments