aboutsummaryrefslogtreecommitdiff
path: root/python/tosa
diff options
context:
space:
mode:
authorTai Ly <tai.ly@arm.com>2024-03-21 17:01:14 +0000
committerTai Ly <tai.ly@arm.com>2024-04-08 22:18:34 +0000
commitce911a2f1d9cd678fb9fe82a40c86ad0c6772f5a (patch)
tree68faf6d7b1c676705a022b32d8aa7950db03ab5e /python/tosa
parent8f9e2842ce7d25645233ad4f6fa406be982346ae (diff)
downloadserialization_lib-ce911a2f1d9cd678fb9fe82a40c86ad0c6772f5a.tar.gz
Add conversions of U8 to/from BF16 and FP8
Adds type to PadAttribute and ClampAttribute so their pad_const and max_val/min_val can be deserialized according to type Adds conversion functions of U8 arrays to/from BF16/FP8 values Also, refactor and expose TosaSerializer.convertDataToUint8Vec for converting dtype/data to uint8 list for serialization And modify convertDataToUint8Vec to serialize bf16 values into 2 bytes each, and serialize fp8 values into single bytes each. Signed-off-by: Tai Ly <tai.ly@arm.com> Change-Id: I05659e8187c76d359f1cc9f71c8c23cafd0e877f
Diffstat (limited to 'python/tosa')
-rw-r--r--python/tosa/ClampAttribute.py15
-rw-r--r--python/tosa/PadAttribute.py15
2 files changed, 28 insertions, 2 deletions
diff --git a/python/tosa/ClampAttribute.py b/python/tosa/ClampAttribute.py
index 6a41498..1189acb 100644
--- a/python/tosa/ClampAttribute.py
+++ b/python/tosa/ClampAttribute.py
@@ -82,8 +82,15 @@ class ClampAttribute(object):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
return o == 0
+ # ClampAttribute
+ def Type(self):
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
+ if o != 0:
+ return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos)
+ return 0
+
def ClampAttributeStart(builder):
- builder.StartObject(2)
+ builder.StartObject(3)
def Start(builder):
ClampAttributeStart(builder)
@@ -112,6 +119,12 @@ def ClampAttributeStartMaxValVector(builder, numElems):
def StartMaxValVector(builder, numElems: int) -> int:
return ClampAttributeStartMaxValVector(builder, numElems)
+def ClampAttributeAddType(builder, type):
+ builder.PrependUint32Slot(2, type, 0)
+
+def AddType(builder, type):
+ ClampAttributeAddType(builder, type)
+
def ClampAttributeEnd(builder):
return builder.EndObject()
diff --git a/python/tosa/PadAttribute.py b/python/tosa/PadAttribute.py
index 301bf17..c4084dc 100644
--- a/python/tosa/PadAttribute.py
+++ b/python/tosa/PadAttribute.py
@@ -55,8 +55,15 @@ class PadAttribute(object):
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
return o == 0
+ # PadAttribute
+ def Type(self):
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
+ if o != 0:
+ return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos)
+ return 0
+
def PadAttributeStart(builder):
- builder.StartObject(1)
+ builder.StartObject(2)
def Start(builder):
PadAttributeStart(builder)
@@ -73,6 +80,12 @@ def PadAttributeStartPadConstVector(builder, numElems):
def StartPadConstVector(builder, numElems: int) -> int:
return PadAttributeStartPadConstVector(builder, numElems)
+def PadAttributeAddType(builder, type):
+ builder.PrependUint32Slot(1, type, 0)
+
+def AddType(builder, type):
+ PadAttributeAddType(builder, type)
+
def PadAttributeEnd(builder):
return builder.EndObject()