diff --git a/src/finn/builder/build_dataflow.py b/src/finn/builder/build_dataflow.py index 68733e59ba49a5e0e1b553e8e40d3e18ac3fc645..c4664a5471984e1f88a70f1d9bb6ce674e38c782 100644 --- a/src/finn/builder/build_dataflow.py +++ b/src/finn/builder/build_dataflow.py @@ -34,7 +34,6 @@ import pdb # NOQA import sys import time import traceback -from copy import deepcopy from finn.builder.build_dataflow_config import ( DataflowBuildConfig, @@ -67,9 +66,6 @@ def resolve_build_steps(cfg: DataflowBuildConfig, partial: bool = True): steps = cfg.steps if steps is None: steps = default_build_dataflow_steps - if cfg.expect_QONNX_as_input: - steps = deepcopy(steps) - steps.insert(0, "step_qonnx_to_finn") steps_as_fxns = [] for transform_step in steps: if type(transform_step) is str: diff --git a/src/finn/builder/build_dataflow_config.py b/src/finn/builder/build_dataflow_config.py index ca1a108d2b74e66f380735c1ad7280046215709f..e48aa4043864124cb6949f713ec13c5e762eb4ef 100644 --- a/src/finn/builder/build_dataflow_config.py +++ b/src/finn/builder/build_dataflow_config.py @@ -89,6 +89,8 @@ class LargeFIFOMemStyle(str, Enum): class VerificationStepType(str, Enum): "Steps at which FINN ONNX execution can be launched for verification." + #: verify after step_qonnx_to_finn, using Python execution + FINN_ONNX_PYTHON = "finn_onnx_python" #: verify after step_tidy_up, using Python execution TIDY_UP_PYTHON = "initial_python" #: verify after step_streamline , using Python execution @@ -103,6 +105,7 @@ class VerificationStepType(str, Enum): #: specified order. Use the `steps` as part of build config to restrict which #: steps will be run. default_build_dataflow_steps = [ + "step_qonnx_to_finn", "step_tidy_up", "step_streamline", "step_convert_to_hls", @@ -123,6 +126,7 @@ default_build_dataflow_steps = [ #: List of steps to run for an estimate-only (no synthesis) dataflow build estimate_only_dataflow_steps = [ + "step_qonnx_to_finn", "step_tidy_up", "step_streamline", "step_convert_to_hls", @@ -291,11 +295,6 @@ class DataflowBuildConfig: #: If given, stop at this step. stop_step: Optional[str] = None - #: If set to True, the dataflow builder will assume that the input ONNX file is - #: in the QONNX dialect. FINN will then try to convert the input to the - #: FINN-ONNX dialect. - expect_QONNX_as_input: Optional[bool] = False - def _resolve_hls_clk_period(self): if self.hls_clk_period_ns is None: # use same clk for synth and hls if not explicitly specified diff --git a/src/finn/builder/build_dataflow_steps.py b/src/finn/builder/build_dataflow_steps.py index 9af273163d74dfe9a29008ee58e1ab5536791e9c..b3f80e1bb5ae6427d8de2c6ca6b54c8180c34fe5 100644 --- a/src/finn/builder/build_dataflow_steps.py +++ b/src/finn/builder/build_dataflow_steps.py @@ -191,15 +191,24 @@ def prepare_for_stitched_ip_rtlsim(verify_model, cfg): def step_qonnx_to_finn(model: ModelWrapper, cfg: DataflowBuildConfig): """ - This runs the tidy-up step from QONNX and then converts the QONNX model - to the FINN-ONNX dialect. + This step will only execute if QONNX nodes are found. + These include the following op_types: "Quant" , "Trunc" and "BinaryQuant". + If such nodes are found the step will run the tidy-up step from QONNX + and then convert the QONNX model to the FINN-ONNX dialect. """ + # Check if any QONNX nodes exist, i.e. BinaryQuant, Quant or Trunc + q_count = 0 + for op_type in ["BinaryQuant", "Quant", "Trunc"]: + q_count += len(model.get_nodes_by_op_type(op_type)) + if q_count == 0: + return model + # QONNX cleanup model = cleanup_model(model) # QONNX to FINN-ONNX model = model.transform(ConvertQONNXtoFINN()) - if VerificationStepType.TIDY_UP_PYTHON in cfg._resolve_verification_steps(): + if VerificationStepType.FINN_ONNX_PYTHON in cfg._resolve_verification_steps(): verify_step(model, cfg, "initial_python", need_parent=False) return model