From ce911a2f1d9cd678fb9fe82a40c86ad0c6772f5a Mon Sep 17 00:00:00 2001 From: Tai Ly Date: Thu, 21 Mar 2024 17:01:14 +0000 Subject: 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 Change-Id: I05659e8187c76d359f1cc9f71c8c23cafd0e877f --- python/tosa/ClampAttribute.py | 15 ++++++++++++++- python/tosa/PadAttribute.py | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'python/tosa') 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() -- cgit v1.2.1