Skip to content

Conversation

@iksnagreb
Copy link

@iksnagreb iksnagreb commented Oct 4, 2025

This PR explores integration of a new ONNX IR and ONNX Script based front end mostly covering streamlining and graph-level optimization transformations. Most of the added steps comprises glue to apply passes from the pass library developed at ONNX Passes and for converting back to the FINN-supported format afterwards. Most of these could eventually be reduced to a bare minimum once transitioning more infrastructure to ONNX IR and ONNX Script, making the formats directly compatible.

Contributions in Detail

  • Adds ONNX Passes dependency providing new infrastructure for ONNX graph transformation and verification
  • Adds a wrapper step using ONNX Passes as a front end for streamlining and threshold conversion by applying a reasonable selection of default passes from the pass library
  • Bridges between QONNX format and the new ONNX IR representation used by the ONNX Passes and ONNX Script
  • Transformation bridging the new convolution lowering implemented as part of ONNX Passes to the QONNX/FINN format: This should mostly be a matter of translating some attributes and transplanting from one custom domain into another...
  • Recreate more/missing streamlining transformations as part of ONNX Passes: Big ones missing are Split/Concat, Im2Col, and everything related to pooling (probably could/should be handled in terms of Reduce* operators?)
    TODO: There might be even more? Split/Concat, Im2Col, Pooling is mostly done, needs testing though...
  • Simple test cases using the new front end for importing and streamlining models: Should eventually cover a single quantizer, a layer tail, a quantized linear layer and a quantized convolution layer example
  • End to end test cases using the new front end on some of the real models from our pool: Probably ResNets and Transformers are the most interesting candidates here
  • ...

Where to go from here?

Seems like step_qonnx_to_finn and (with some extra effort) step_tidy_up could be immediately deprecated as everything done by those is covered by the new transformations or could at least be recreated without too much effort. Due to the mismatch between QONNX and ONNX IR representation, we probably still want to maintain a step_tidy_up using QONNX transformations with a ModelWrapper to be able to apply this at any point within a step sequence, at least for some transitional period.

With more and more transformations being recreated as ONNX Passes, or even as part of the ONNX Script rewriter, we can probably gradually phase out the step_streamline, eventually moving any remaining FINN specifics into the hardware conversion step or creating new, more explicitly named steps.

The new infrastructure could be used to overhaul almost all of the transformations and steps, but I am not sure this is actually worth the effort, as beyond step_convert_to_hw most transformations merely set/update annotations and node attributes or call into simulation or synthesis tools. I don't see any problems here which could be solved by new infrastructure or model representation.

TODO: Propose and discuss a strategy for when/how to use the new infrastructure vs. the old QONNX Transformation base when creating new or reworking existing transformations... probably best to discuss this offline for the start?

TODO: Discuss how to extend the tight verification and ONNX Runtime execution (for verification) to the rest of the flow - probably this is infeasible due to complexity and runtime of C++ and RTL simulation, but some aspects, such as metric-based verification, could be incorporated?

Layout Annotation and Conversion

Now also contributes a new experimental approach to the ongoing data layout issues (see #53, #84, #86, #87, #91, #101, fastmachinelearning/qonnx/issues/173). For details refer to the convolution demo at ONNX Passes.

This aims at replicating the core idea of the "data layout" concept of FINN and QONNX without the baggage of layout propagation: Layouts are annotated as (for now unenforced) assumptions and matching transposes are inserted which try to propagate the information via simple (compared to layout propagation) streamlining.

This might require further extension of streamlining transpose operators and modifications to the MultiThreshold operator in QONNX and the conversion of these to FINN's Thresholding operator.

  • Extend ONNX Passes by streamlining rules relating padding, Im2Col and transposes to not block the flow of layout information in front of padded convolution.
  • Collect all existing usage of the layout annotation (tensors and node attributes) in FINN and QONNX to decide if these could be removed, based upon this new mechanism or need to be kept as parallel infrastructure.

Other Contributions

Includes PRs #127 and #128 for implementing Reshape operations remaining in the graph after streamlining as some of the architectures to be enabled by this new front end have "real" reshape operations as part of the graph.

@iksnagreb iksnagreb self-assigned this Oct 4, 2025
@github-actions

This comment was marked as resolved.

@iksnagreb iksnagreb added the enhancement New feature or request label Oct 5, 2025
@fpjentzsch fpjentzsch moved this to In Progress in FINN+ Feature Tracker Oct 6, 2025
@iksnagreb iksnagreb linked an issue Oct 8, 2025 that may be closed by this pull request
@iksnagreb iksnagreb linked an issue Oct 8, 2025 that may be closed by this pull request
@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

📋 Docstring Check Report

Checked files:

  • src/finn/builder/build_dataflow_config.py
  • src/finn/builder/build_dataflow_steps.py
  • src/finn/builder/passes.py
  • src/finn/custom_op/fpgadataflow/hls/pool_hls.py
  • src/finn/custom_op/fpgadataflow/pool.py
  • src/finn/transformation/fpgadataflow/convert_to_hw_layers.py
  • src/finn/transformation/streamline/__init__.py

Docstring check failed!

Missing Docstrings Details:

📄 src/finn/custom_op/fpgadataflow/hls/pool_hls.py:

    • Line 1: module 'pool_hls.py'
    • Line 54: function 'Pool_hls.get_nodeattr_types'
    • Line 60: function 'Pool_hls.global_includes'
    • Line 63: function 'Pool_hls.defines'
    • Line 72: function 'Pool_hls.docompute'
    • Line 117: function 'Pool_hls.pragmas'
    • Line 123: function 'Pool_hls.blackboxfunction'
    • Line 135: function 'Pool_hls.execute_node'

📄 src/finn/custom_op/fpgadataflow/pool.py:

    • Line 1: module 'pool.py'
    • Line 54: function 'Pool.get_nodeattr_types'
    • Line 103: function 'Pool.get_normal_input_shape'
    • Line 112: function 'Pool.get_folded_input_shape'
    • Line 121: function 'Pool.get_normal_output_shape'
    • Line 128: function 'Pool.get_folded_output_shape'
    • Line 137: function 'Pool.get_exp_cycles'
    • Line 148: function 'Pool.get_instream_width'
    • Line 154: function 'Pool.get_outstream_width'
    • Line 160: function 'Pool.infer_node_datatype'
    • Line 166: function 'Pool.verify_node'
    • Line 189: function 'Pool.execute_node'

Total missing docstrings: 20

How to Fix:

Please add docstrings to the missing functions, classes, and modules listed above.

Docstring Guidelines:

  • All modules should have a module-level docstring
  • All public functions and methods should have docstrings
  • All private functions should have docstrings
  • All classes should have docstrings
  • Use triple quotes (""") for docstrings
  • Follow PEP 257 conventions
Raw output from docstring checker
Checking 7 changed Python file(s):
❌ Missing docstrings found:

📄 src/finn/custom_op/fpgadataflow/hls/pool_hls.py:
  - Line 1: module 'pool_hls.py'
  - Line 54: function 'Pool_hls.get_nodeattr_types'
  - Line 60: function 'Pool_hls.global_includes'
  - Line 63: function 'Pool_hls.defines'
  - Line 72: function 'Pool_hls.docompute'
  - Line 117: function 'Pool_hls.pragmas'
  - Line 123: function 'Pool_hls.blackboxfunction'
  - Line 135: function 'Pool_hls.execute_node'

📄 src/finn/custom_op/fpgadataflow/pool.py:
  - Line 1: module 'pool.py'
  - Line 54: function 'Pool.get_nodeattr_types'
  - Line 103: function 'Pool.get_normal_input_shape'
  - Line 112: function 'Pool.get_folded_input_shape'
  - Line 121: function 'Pool.get_normal_output_shape'
  - Line 128: function 'Pool.get_folded_output_shape'
  - Line 137: function 'Pool.get_exp_cycles'
  - Line 148: function 'Pool.get_instream_width'
  - Line 154: function 'Pool.get_outstream_width'
  - Line 160: function 'Pool.infer_node_datatype'
  - Line 166: function 'Pool.verify_node'
  - Line 189: function 'Pool.execute_node'

Total missing docstrings: 20

Note: This is mostly a workaround for missing datatype inference for
Reduce operators in QONNX. Inferring these as pooling enables type
inference via the FINN custom-op. Eventually QONNX should handle this.
Note: Inferring Reshape is included as a default hardware conversion
transformation, meaning any Reshape remaining to the end of hardware
conversion will be turned into the Reshape pass-through operator.
Note: Previously this assumed identical input and output shape for
PE-ops, which might not always be the case, e.g., Reshape.

As PE refers to the output parallelism, the fallback should be derived
from the output shape to get valid folding.
@github-actions
Copy link

github-actions bot commented Nov 7, 2025

📋 Docstring Check Report

Checked files:

  • src/finn/builder/build_dataflow_config.py
  • src/finn/builder/build_dataflow_steps.py
  • src/finn/builder/passes.py
  • src/finn/custom_op/fpgadataflow/hls/pool_hls.py
  • src/finn/custom_op/fpgadataflow/pool.py
  • src/finn/custom_op/fpgadataflow/reshape.py
  • src/finn/custom_op/fpgadataflow/rtl/__init__.py
  • src/finn/custom_op/fpgadataflow/rtl/reshape_rtl.py
  • src/finn/transformation/fpgadataflow/convert_to_hw_layers.py
  • src/finn/transformation/fpgadataflow/set_folding.py
  • src/finn/transformation/streamline/__init__.py

Docstring check failed!

Missing Docstrings Details:

📄 src/finn/transformation/fpgadataflow/set_folding.py:

    • Line 1: module 'set_folding.py'
    • Line 48: function 'divisors'
    • Line 54: function 'common_divisors'
    • Line 109: function 'SetFolding.init'
    • Line 115: function 'SetFolding.optimize_attribute_val'
    • Line 124: function 'SetFolding.apply'

Total missing docstrings: 6

How to Fix:

Please add docstrings to the missing functions, classes, and modules listed above.

Docstring Guidelines:

  • All modules should have a module-level docstring
  • All public functions and methods should have docstrings
  • All private functions should have docstrings
  • All classes should have docstrings
  • Use triple quotes (""") for docstrings
  • Follow PEP 257 conventions
Raw output from docstring checker
Checking 11 changed Python file(s):
❌ Missing docstrings found:

📄 src/finn/transformation/fpgadataflow/set_folding.py:
  - Line 1: module 'set_folding.py'
  - Line 48: function 'divisors'
  - Line 54: function 'common_divisors'
  - Line 109: function 'SetFolding.__init__'
  - Line 115: function 'SetFolding.optimize_attribute_val'
  - Line 124: function 'SetFolding.apply'

Total missing docstrings: 6

@github-actions
Copy link

github-actions bot commented Nov 8, 2025

📋 Docstring Check Report

Checked files:

  • src/finn/builder/build_dataflow_config.py
  • src/finn/builder/build_dataflow_steps.py
  • src/finn/builder/passes.py
  • src/finn/custom_op/fpgadataflow/hls/pool_hls.py
  • src/finn/custom_op/fpgadataflow/pool.py
  • src/finn/custom_op/fpgadataflow/reshape.py
  • src/finn/custom_op/fpgadataflow/rtl/__init__.py
  • src/finn/custom_op/fpgadataflow/rtl/reshape_rtl.py
  • src/finn/transformation/fpgadataflow/convert_to_hw_layers.py
  • src/finn/transformation/fpgadataflow/set_folding.py
  • src/finn/transformation/streamline/__init__.py
  • src/finn/transformation/streamline/round_thresholds.py

Docstring check failed!

Missing Docstrings Details:

📄 src/finn/transformation/streamline/round_thresholds.py:

    • Line 1: module 'round_thresholds.py'
    • Line 46: function 'RoundAndClipThresholds.apply'

Total missing docstrings: 2

How to Fix:

Please add docstrings to the missing functions, classes, and modules listed above.

Docstring Guidelines:

  • All modules should have a module-level docstring
  • All public functions and methods should have docstrings
  • All private functions should have docstrings
  • All classes should have docstrings
  • Use triple quotes (""") for docstrings
  • Follow PEP 257 conventions
Raw output from docstring checker
Checking 12 changed Python file(s):
❌ Missing docstrings found:

📄 src/finn/transformation/streamline/round_thresholds.py:
  - Line 1: module 'round_thresholds.py'
  - Line 46: function 'RoundAndClipThresholds.apply'

Total missing docstrings: 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Adding graph utility functions

2 participants