Skip to content
Snippets Groups Projects
Commit 222e7889 authored by Hendrik Borras's avatar Hendrik Borras
Browse files

Made QONNX to FINN a default build step, changed verification step name and...

Made QONNX to FINN a default build step, changed verification step name and made running of conversion conditional on the existence of quant nodes.
parent 07e4dfa9
No related branches found
No related tags found
No related merge requests found
...@@ -34,7 +34,6 @@ import pdb # NOQA ...@@ -34,7 +34,6 @@ import pdb # NOQA
import sys import sys
import time import time
import traceback import traceback
from copy import deepcopy
from finn.builder.build_dataflow_config import ( from finn.builder.build_dataflow_config import (
DataflowBuildConfig, DataflowBuildConfig,
...@@ -67,9 +66,6 @@ def resolve_build_steps(cfg: DataflowBuildConfig, partial: bool = True): ...@@ -67,9 +66,6 @@ def resolve_build_steps(cfg: DataflowBuildConfig, partial: bool = True):
steps = cfg.steps steps = cfg.steps
if steps is None: if steps is None:
steps = default_build_dataflow_steps steps = default_build_dataflow_steps
if cfg.expect_QONNX_as_input:
steps = deepcopy(steps)
steps.insert(0, "step_qonnx_to_finn")
steps_as_fxns = [] steps_as_fxns = []
for transform_step in steps: for transform_step in steps:
if type(transform_step) is str: if type(transform_step) is str:
......
...@@ -89,6 +89,8 @@ class LargeFIFOMemStyle(str, Enum): ...@@ -89,6 +89,8 @@ class LargeFIFOMemStyle(str, Enum):
class VerificationStepType(str, Enum): class VerificationStepType(str, Enum):
"Steps at which FINN ONNX execution can be launched for verification." "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 #: verify after step_tidy_up, using Python execution
TIDY_UP_PYTHON = "initial_python" TIDY_UP_PYTHON = "initial_python"
#: verify after step_streamline , using Python execution #: verify after step_streamline , using Python execution
...@@ -103,6 +105,7 @@ class VerificationStepType(str, Enum): ...@@ -103,6 +105,7 @@ class VerificationStepType(str, Enum):
#: specified order. Use the `steps` as part of build config to restrict which #: specified order. Use the `steps` as part of build config to restrict which
#: steps will be run. #: steps will be run.
default_build_dataflow_steps = [ default_build_dataflow_steps = [
"step_qonnx_to_finn",
"step_tidy_up", "step_tidy_up",
"step_streamline", "step_streamline",
"step_convert_to_hls", "step_convert_to_hls",
...@@ -123,6 +126,7 @@ default_build_dataflow_steps = [ ...@@ -123,6 +126,7 @@ default_build_dataflow_steps = [
#: List of steps to run for an estimate-only (no synthesis) dataflow build #: List of steps to run for an estimate-only (no synthesis) dataflow build
estimate_only_dataflow_steps = [ estimate_only_dataflow_steps = [
"step_qonnx_to_finn",
"step_tidy_up", "step_tidy_up",
"step_streamline", "step_streamline",
"step_convert_to_hls", "step_convert_to_hls",
...@@ -291,11 +295,6 @@ class DataflowBuildConfig: ...@@ -291,11 +295,6 @@ class DataflowBuildConfig:
#: If given, stop at this step. #: If given, stop at this step.
stop_step: Optional[str] = None 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): def _resolve_hls_clk_period(self):
if self.hls_clk_period_ns is None: if self.hls_clk_period_ns is None:
# use same clk for synth and hls if not explicitly specified # use same clk for synth and hls if not explicitly specified
......
...@@ -191,15 +191,24 @@ def prepare_for_stitched_ip_rtlsim(verify_model, cfg): ...@@ -191,15 +191,24 @@ def prepare_for_stitched_ip_rtlsim(verify_model, cfg):
def step_qonnx_to_finn(model: ModelWrapper, cfg: DataflowBuildConfig): def step_qonnx_to_finn(model: ModelWrapper, cfg: DataflowBuildConfig):
""" """
This runs the tidy-up step from QONNX and then converts the QONNX model This step will only execute if QONNX nodes are found.
to the FINN-ONNX dialect. 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 # QONNX cleanup
model = cleanup_model(model) model = cleanup_model(model)
# QONNX to FINN-ONNX # QONNX to FINN-ONNX
model = model.transform(ConvertQONNXtoFINN()) 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) verify_step(model, cfg, "initial_python", need_parent=False)
return model return model
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment