From 255dec0b82bfc5d69ad897d769aa295a03d36aa2 Mon Sep 17 00:00:00 2001 From: Hendrik Borras <hendrikborras@web.de> Date: Fri, 15 Oct 2021 14:27:54 +0100 Subject: [PATCH] Added QONNX_export test to test_brevitas_act_export_relu test. --- tests/brevitas/test_brevitas_relu_act_export.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/brevitas/test_brevitas_relu_act_export.py b/tests/brevitas/test_brevitas_relu_act_export.py index bb59a8414..305382bbc 100644 --- a/tests/brevitas/test_brevitas_relu_act_export.py +++ b/tests/brevitas/test_brevitas_relu_act_export.py @@ -36,11 +36,14 @@ import torch from brevitas.core.quant import QuantType from brevitas.core.restrict_val import RestrictValueType from brevitas.core.scaling import ScalingImplType +from brevitas.export.onnx.generic.manager import BrevitasONNXManager from brevitas.nn import QuantReLU +from qonnx.util.cleanup import cleanup as qonnx_cleanup import finn.core.onnx_exec as oxe from finn.core.modelwrapper import ModelWrapper from finn.transformation.infer_shapes import InferShapes +from finn.transformation.qonnx.convert_qonnx_to_finn import ConvertQONNXtoFINN export_onnx_path = "test_brevitas_relu_act_export.onnx" @@ -50,7 +53,8 @@ export_onnx_path = "test_brevitas_relu_act_export.onnx" @pytest.mark.parametrize( "scaling_impl_type", [ScalingImplType.CONST, ScalingImplType.PARAMETER] ) -def test_brevitas_act_export_relu(abits, max_val, scaling_impl_type): +@pytest.mark.parametrize("QONNX_export", [False, True]) +def test_brevitas_act_export_relu(abits, max_val, scaling_impl_type, QONNX_export): min_val = -1.0 ishape = (1, 15) @@ -71,8 +75,15 @@ scaling_impl.learned_value": torch.tensor( ) } b_act.load_state_dict(checkpoint) - - bo.export_finn_onnx(b_act, ishape, export_onnx_path) + if QONNX_export: + m_path = export_onnx_path + BrevitasONNXManager.export(b_act, ishape, m_path) + qonnx_cleanup(m_path, out_file=m_path) + model = ModelWrapper(m_path) + model = model.transform(ConvertQONNXtoFINN()) + model.save(m_path) + else: + bo.export_finn_onnx(b_act, ishape, export_onnx_path) model = ModelWrapper(export_onnx_path) model = model.transform(InferShapes()) inp_tensor = np.random.uniform(low=min_val, high=max_val, size=ishape).astype( -- GitLab