diff options
author | Eric Kunze <eric.kunze@arm.com> | 2022-06-07 05:17:37 +0000 |
---|---|---|
committer | Eric Kunze <eric.kunze@arm.com> | 2022-06-15 08:30:47 -0700 |
commit | bdcc3fee1b8bf55aac50e060115b92a1ccf9741c (patch) | |
tree | 05951f3fd1b9e42f859e999976715e6e673acb15 /python/tosa | |
parent | a336d54aca08b06953a8b6c49d7e5f6c4899952e (diff) | |
download | serialization_lib-bdcc3fee1b8bf55aac50e060115b92a1ccf9741c.tar.gz |
Remove quantinfo types
Any needed information has been moved into the attributes for each operator.
This aligns with the structure of the attributes in the TOSA
specification, and generally simplifies the code.
Change-Id: I8243e91b09de1a9115f8af09c5e7def7e8f2866b
Signed-off-by: Eric Kunze <eric.kunze@arm.com>
Diffstat (limited to 'python/tosa')
-rw-r--r-- | python/tosa/Attribute.py | 3 | ||||
-rw-r--r-- | python/tosa/ConvAttribute.py | 18 | ||||
-rw-r--r-- | python/tosa/FullyConnectedAttribute.py (renamed from python/tosa/ConvQuantInfo.py) | 22 | ||||
-rw-r--r-- | python/tosa/MatMulAttribute.py (renamed from python/tosa/MatMulQuantInfo.py) | 22 | ||||
-rw-r--r-- | python/tosa/NegateAttribute.py (renamed from python/tosa/UnaryQuantInfo.py) | 24 | ||||
-rw-r--r-- | python/tosa/PadQuantInfo.py | 36 | ||||
-rw-r--r-- | python/tosa/PoolAttribute.py | 18 | ||||
-rw-r--r-- | python/tosa/QuantInfo.py | 11 | ||||
-rw-r--r-- | python/tosa/TosaOperator.py | 21 | ||||
-rw-r--r-- | python/tosa/TransposeConvAttribute.py | 18 | ||||
-rw-r--r-- | python/tosa/Version.py | 4 |
11 files changed, 91 insertions, 106 deletions
diff --git a/python/tosa/Attribute.py b/python/tosa/Attribute.py index f0307af..166de8e 100644 --- a/python/tosa/Attribute.py +++ b/python/tosa/Attribute.py @@ -21,4 +21,7 @@ class Attribute(object): WhileLoopAttribute = 15 TransposeAttribute = 16 TableAttribute = 17 + MatMulAttribute = 18 + FullyConnectedAttribute = 19 + NegateAttribute = 20 diff --git a/python/tosa/ConvAttribute.py b/python/tosa/ConvAttribute.py index 72a24ce..8244ea5 100644 --- a/python/tosa/ConvAttribute.py +++ b/python/tosa/ConvAttribute.py @@ -105,11 +105,27 @@ class ConvAttribute(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) return o == 0 -def ConvAttributeStart(builder): builder.StartObject(3) + # ConvAttribute + def InputZp(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # ConvAttribute + def WeightZp(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + +def ConvAttributeStart(builder): builder.StartObject(5) def ConvAttributeAddPad(builder, pad): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(pad), 0) def ConvAttributeStartPadVector(builder, numElems): return builder.StartVector(4, numElems, 4) def ConvAttributeAddStride(builder, stride): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(stride), 0) def ConvAttributeStartStrideVector(builder, numElems): return builder.StartVector(4, numElems, 4) def ConvAttributeAddDilation(builder, dilation): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(dilation), 0) def ConvAttributeStartDilationVector(builder, numElems): return builder.StartVector(4, numElems, 4) +def ConvAttributeAddInputZp(builder, inputZp): builder.PrependInt32Slot(3, inputZp, 0) +def ConvAttributeAddWeightZp(builder, weightZp): builder.PrependInt32Slot(4, weightZp, 0) def ConvAttributeEnd(builder): return builder.EndObject() diff --git a/python/tosa/ConvQuantInfo.py b/python/tosa/FullyConnectedAttribute.py index 7902c67..62b480d 100644 --- a/python/tosa/ConvQuantInfo.py +++ b/python/tosa/FullyConnectedAttribute.py @@ -6,39 +6,39 @@ import flatbuffers from flatbuffers.compat import import_numpy np = import_numpy() -class ConvQuantInfo(object): +class FullyConnectedAttribute(object): __slots__ = ['_tab'] @classmethod - def GetRootAsConvQuantInfo(cls, buf, offset): + def GetRootAsFullyConnectedAttribute(cls, buf, offset): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) - x = ConvQuantInfo() + x = FullyConnectedAttribute() x.Init(buf, n + offset) return x @classmethod - def ConvQuantInfoBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + def FullyConnectedAttributeBufferHasIdentifier(cls, buf, offset, size_prefixed=False): return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x54\x4F\x53\x41", size_prefixed=size_prefixed) - # ConvQuantInfo + # FullyConnectedAttribute def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) - # ConvQuantInfo + # FullyConnectedAttribute def InputZp(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) if o != 0: return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) return 0 - # ConvQuantInfo + # FullyConnectedAttribute def WeightZp(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) if o != 0: return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) return 0 -def ConvQuantInfoStart(builder): builder.StartObject(2) -def ConvQuantInfoAddInputZp(builder, inputZp): builder.PrependInt32Slot(0, inputZp, 0) -def ConvQuantInfoAddWeightZp(builder, weightZp): builder.PrependInt32Slot(1, weightZp, 0) -def ConvQuantInfoEnd(builder): return builder.EndObject() +def FullyConnectedAttributeStart(builder): builder.StartObject(2) +def FullyConnectedAttributeAddInputZp(builder, inputZp): builder.PrependInt32Slot(0, inputZp, 0) +def FullyConnectedAttributeAddWeightZp(builder, weightZp): builder.PrependInt32Slot(1, weightZp, 0) +def FullyConnectedAttributeEnd(builder): return builder.EndObject() diff --git a/python/tosa/MatMulQuantInfo.py b/python/tosa/MatMulAttribute.py index 457da66..601f13f 100644 --- a/python/tosa/MatMulQuantInfo.py +++ b/python/tosa/MatMulAttribute.py @@ -6,39 +6,39 @@ import flatbuffers from flatbuffers.compat import import_numpy np = import_numpy() -class MatMulQuantInfo(object): +class MatMulAttribute(object): __slots__ = ['_tab'] @classmethod - def GetRootAsMatMulQuantInfo(cls, buf, offset): + def GetRootAsMatMulAttribute(cls, buf, offset): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) - x = MatMulQuantInfo() + x = MatMulAttribute() x.Init(buf, n + offset) return x @classmethod - def MatMulQuantInfoBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + def MatMulAttributeBufferHasIdentifier(cls, buf, offset, size_prefixed=False): return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x54\x4F\x53\x41", size_prefixed=size_prefixed) - # MatMulQuantInfo + # MatMulAttribute def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) - # MatMulQuantInfo + # MatMulAttribute def AZp(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) if o != 0: return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) return 0 - # MatMulQuantInfo + # MatMulAttribute def BZp(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) if o != 0: return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) return 0 -def MatMulQuantInfoStart(builder): builder.StartObject(2) -def MatMulQuantInfoAddAZp(builder, aZp): builder.PrependInt32Slot(0, aZp, 0) -def MatMulQuantInfoAddBZp(builder, bZp): builder.PrependInt32Slot(1, bZp, 0) -def MatMulQuantInfoEnd(builder): return builder.EndObject() +def MatMulAttributeStart(builder): builder.StartObject(2) +def MatMulAttributeAddAZp(builder, aZp): builder.PrependInt32Slot(0, aZp, 0) +def MatMulAttributeAddBZp(builder, bZp): builder.PrependInt32Slot(1, bZp, 0) +def MatMulAttributeEnd(builder): return builder.EndObject() diff --git a/python/tosa/UnaryQuantInfo.py b/python/tosa/NegateAttribute.py index 648fc34..24a57dc 100644 --- a/python/tosa/UnaryQuantInfo.py +++ b/python/tosa/NegateAttribute.py @@ -6,39 +6,39 @@ import flatbuffers from flatbuffers.compat import import_numpy np = import_numpy() -class UnaryQuantInfo(object): +class NegateAttribute(object): __slots__ = ['_tab'] @classmethod - def GetRootAsUnaryQuantInfo(cls, buf, offset): + def GetRootAsNegateAttribute(cls, buf, offset): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) - x = UnaryQuantInfo() + x = NegateAttribute() x.Init(buf, n + offset) return x @classmethod - def UnaryQuantInfoBufferHasIdentifier(cls, buf, offset, size_prefixed=False): + def NegateAttributeBufferHasIdentifier(cls, buf, offset, size_prefixed=False): return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x54\x4F\x53\x41", size_prefixed=size_prefixed) - # UnaryQuantInfo + # NegateAttribute def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) - # UnaryQuantInfo - def InputZp(self): + # NegateAttribute + def Input1Zp(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) if o != 0: return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) return 0 - # UnaryQuantInfo + # NegateAttribute def OutputZp(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) if o != 0: return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) return 0 -def UnaryQuantInfoStart(builder): builder.StartObject(2) -def UnaryQuantInfoAddInputZp(builder, inputZp): builder.PrependInt32Slot(0, inputZp, 0) -def UnaryQuantInfoAddOutputZp(builder, outputZp): builder.PrependInt32Slot(1, outputZp, 0) -def UnaryQuantInfoEnd(builder): return builder.EndObject() +def NegateAttributeStart(builder): builder.StartObject(2) +def NegateAttributeAddInput1Zp(builder, input1Zp): builder.PrependInt32Slot(0, input1Zp, 0) +def NegateAttributeAddOutputZp(builder, outputZp): builder.PrependInt32Slot(1, outputZp, 0) +def NegateAttributeEnd(builder): return builder.EndObject() diff --git a/python/tosa/PadQuantInfo.py b/python/tosa/PadQuantInfo.py deleted file mode 100644 index c07db07..0000000 --- a/python/tosa/PadQuantInfo.py +++ /dev/null @@ -1,36 +0,0 @@ -# automatically generated by the FlatBuffers compiler, do not modify - -# namespace: tosa - -import flatbuffers -from flatbuffers.compat import import_numpy -np = import_numpy() - -class PadQuantInfo(object): - __slots__ = ['_tab'] - - @classmethod - def GetRootAsPadQuantInfo(cls, buf, offset): - n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) - x = PadQuantInfo() - x.Init(buf, n + offset) - return x - - @classmethod - def PadQuantInfoBufferHasIdentifier(cls, buf, offset, size_prefixed=False): - return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x54\x4F\x53\x41", size_prefixed=size_prefixed) - - # PadQuantInfo - def Init(self, buf, pos): - self._tab = flatbuffers.table.Table(buf, pos) - - # PadQuantInfo - def InputZp(self): - o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) - if o != 0: - return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) - return 0 - -def PadQuantInfoStart(builder): builder.StartObject(1) -def PadQuantInfoAddInputZp(builder, inputZp): builder.PrependInt32Slot(0, inputZp, 0) -def PadQuantInfoEnd(builder): return builder.EndObject() diff --git a/python/tosa/PoolAttribute.py b/python/tosa/PoolAttribute.py index f2c12cf..8b6903e 100644 --- a/python/tosa/PoolAttribute.py +++ b/python/tosa/PoolAttribute.py @@ -105,11 +105,27 @@ class PoolAttribute(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) return o == 0 -def PoolAttributeStart(builder): builder.StartObject(3) + # PoolAttribute + def InputZp(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # PoolAttribute + def OutputZp(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + +def PoolAttributeStart(builder): builder.StartObject(5) def PoolAttributeAddPad(builder, pad): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(pad), 0) def PoolAttributeStartPadVector(builder, numElems): return builder.StartVector(4, numElems, 4) def PoolAttributeAddKernel(builder, kernel): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(kernel), 0) def PoolAttributeStartKernelVector(builder, numElems): return builder.StartVector(4, numElems, 4) def PoolAttributeAddStride(builder, stride): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(stride), 0) def PoolAttributeStartStrideVector(builder, numElems): return builder.StartVector(4, numElems, 4) +def PoolAttributeAddInputZp(builder, inputZp): builder.PrependInt32Slot(3, inputZp, 0) +def PoolAttributeAddOutputZp(builder, outputZp): builder.PrependInt32Slot(4, outputZp, 0) def PoolAttributeEnd(builder): return builder.EndObject() diff --git a/python/tosa/QuantInfo.py b/python/tosa/QuantInfo.py deleted file mode 100644 index ffdfd32..0000000 --- a/python/tosa/QuantInfo.py +++ /dev/null @@ -1,11 +0,0 @@ -# automatically generated by the FlatBuffers compiler, do not modify - -# namespace: tosa - -class QuantInfo(object): - NONE = 0 - UnaryQuantInfo = 1 - ConvQuantInfo = 2 - MatMulQuantInfo = 3 - PadQuantInfo = 4 - diff --git a/python/tosa/TosaOperator.py b/python/tosa/TosaOperator.py index 040c2dc..fd11f76 100644 --- a/python/tosa/TosaOperator.py +++ b/python/tosa/TosaOperator.py @@ -88,24 +88,7 @@ class TosaOperator(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) return o == 0 - # TosaOperator - def QuantInfoType(self): - o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) - if o != 0: - return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos) - return 0 - - # TosaOperator - def QuantInfo(self): - o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16)) - if o != 0: - from flatbuffers.table import Table - obj = Table(bytearray(), 0) - self._tab.Union(obj, o) - return obj - return None - -def TosaOperatorStart(builder): builder.StartObject(7) +def TosaOperatorStart(builder): builder.StartObject(5) def TosaOperatorAddOp(builder, op): builder.PrependUint32Slot(0, op, 0) def TosaOperatorAddAttributeType(builder, attributeType): builder.PrependUint8Slot(1, attributeType, 0) def TosaOperatorAddAttribute(builder, attribute): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(attribute), 0) @@ -113,6 +96,4 @@ def TosaOperatorAddInputs(builder, inputs): builder.PrependUOffsetTRelativeSlot( def TosaOperatorStartInputsVector(builder, numElems): return builder.StartVector(4, numElems, 4) def TosaOperatorAddOutputs(builder, outputs): builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(outputs), 0) def TosaOperatorStartOutputsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def TosaOperatorAddQuantInfoType(builder, quantInfoType): builder.PrependUint8Slot(5, quantInfoType, 0) -def TosaOperatorAddQuantInfo(builder, quantInfo): builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(quantInfo), 0) def TosaOperatorEnd(builder): return builder.EndObject() diff --git a/python/tosa/TransposeConvAttribute.py b/python/tosa/TransposeConvAttribute.py index 2a675a0..8ca5ba7 100644 --- a/python/tosa/TransposeConvAttribute.py +++ b/python/tosa/TransposeConvAttribute.py @@ -105,11 +105,27 @@ class TransposeConvAttribute(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) return o == 0 -def TransposeConvAttributeStart(builder): builder.StartObject(3) + # TransposeConvAttribute + def InputZp(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # TransposeConvAttribute + def WeightZp(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + +def TransposeConvAttributeStart(builder): builder.StartObject(5) def TransposeConvAttributeAddOutPad(builder, outPad): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(outPad), 0) def TransposeConvAttributeStartOutPadVector(builder, numElems): return builder.StartVector(4, numElems, 4) def TransposeConvAttributeAddStride(builder, stride): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(stride), 0) def TransposeConvAttributeStartStrideVector(builder, numElems): return builder.StartVector(4, numElems, 4) def TransposeConvAttributeAddOutputShape(builder, outputShape): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(outputShape), 0) def TransposeConvAttributeStartOutputShapeVector(builder, numElems): return builder.StartVector(4, numElems, 4) +def TransposeConvAttributeAddInputZp(builder, inputZp): builder.PrependInt32Slot(3, inputZp, 0) +def TransposeConvAttributeAddWeightZp(builder, weightZp): builder.PrependInt32Slot(4, weightZp, 0) def TransposeConvAttributeEnd(builder): return builder.EndObject() diff --git a/python/tosa/Version.py b/python/tosa/Version.py index 27dea53..bdac948 100644 --- a/python/tosa/Version.py +++ b/python/tosa/Version.py @@ -36,7 +36,7 @@ class Version(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) if o != 0: return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) - return 25 + return 30 # Version def _patch(self): @@ -54,7 +54,7 @@ class Version(object): def VersionStart(builder): builder.StartObject(4) def VersionAdd_major(builder, Major): builder.PrependInt32Slot(0, Major, 0) -def VersionAdd_minor(builder, Minor): builder.PrependInt32Slot(1, Minor, 25) +def VersionAdd_minor(builder, Minor): builder.PrependInt32Slot(1, Minor, 30) def VersionAdd_patch(builder, Patch): builder.PrependInt32Slot(2, Patch, 0) def VersionAdd_draft(builder, Draft): builder.PrependBoolSlot(3, Draft, 1) def VersionEnd(builder): return builder.EndObject() |