From 323cd9f1d0808d0ee80b49dba2f12bbb51d89376 Mon Sep 17 00:00:00 2001 From: Christoph Berganski Date: Wed, 28 Aug 2024 14:53:52 +0200 Subject: [PATCH] [Streamline] Allow AbsorbSignBiasIntoMultiThreshold to absorb any bias Note: Keep the name indicating only handling signed-bias but adjust the datatype inference after absorbing the bias to handle signed bias as well as outputs. --- src/finn/transformation/streamline/absorb.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/finn/transformation/streamline/absorb.py b/src/finn/transformation/streamline/absorb.py index e3e2468bba..98c38964e5 100644 --- a/src/finn/transformation/streamline/absorb.py +++ b/src/finn/transformation/streamline/absorb.py @@ -80,7 +80,14 @@ def apply(self, model): steps = T.shape[-1] new_min = bias new_max = steps + bias - odt = DataType.get_smallest_possible(steps).name.replace("UINT", "INT") + + # Allows the signedness to change depending on the new + # output range [new_min,new_max] + if abs(new_min) > abs(new_max): + odt = DataType.get_smallest_possible(new_min).name + else: + odt = DataType.get_smallest_possible(new_max).name + odt = DataType[odt] assert odt.allowed(new_max) and odt.allowed( new_min