finn-plus-tests 1.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. finn_plus_tests-1.3.0.dist-info/METADATA +25 -0
  2. finn_plus_tests-1.3.0.dist-info/RECORD +126 -0
  3. finn_plus_tests-1.3.0.dist-info/WHEEL +4 -0
  4. tests/__init__.py +0 -0
  5. tests/analysis/test_unsupported_layers.py +301 -0
  6. tests/brevitas/king_charles.jpg +0 -0
  7. tests/brevitas/test_brevitas_avg_pool_export.py +114 -0
  8. tests/brevitas/test_brevitas_cnv.py +82 -0
  9. tests/brevitas/test_brevitas_debug.py +98 -0
  10. tests/brevitas/test_brevitas_deconv.py +82 -0
  11. tests/brevitas/test_brevitas_fc.py +87 -0
  12. tests/brevitas/test_brevitas_mobilenet.py +130 -0
  13. tests/brevitas/test_brevitas_non_scaled_quanthardtanh_export.py +87 -0
  14. tests/brevitas/test_brevitas_qconv2d.py +108 -0
  15. tests/brevitas/test_brevitas_qlinear.py +83 -0
  16. tests/brevitas/test_brevitas_relu_act_export.py +105 -0
  17. tests/brevitas/test_brevitas_scaled_qhardtanh_export.py +123 -0
  18. tests/brevitas/test_brevitas_selu_act_export.py +73 -0
  19. tests/brevitas/test_brevitas_validate_mobilenet.py +214 -0
  20. tests/conftest.py +91 -0
  21. tests/end2end/test_end2end_bnn_pynq.py +834 -0
  22. tests/end2end/test_end2end_cybsec_mlp.py +193 -0
  23. tests/end2end/test_end2end_mobilenet_v1.py +523 -0
  24. tests/end2end/test_ext_weights.py +104 -0
  25. tests/example_data/build_dataflow/build.py +70 -0
  26. tests/example_data/build_dataflow/dataflow_build_config.json +28 -0
  27. tests/example_data/build_dataflow/expected_output.npy +0 -0
  28. tests/example_data/build_dataflow/folding_config.json +29 -0
  29. tests/example_data/build_dataflow/input.npy +0 -0
  30. tests/example_data/build_dataflow/model.onnx +0 -0
  31. tests/example_data/build_dataflow/specialize_layers_config.json +21 -0
  32. tests/example_data/cifar10/cifar10-test-data-class3.npz +0 -0
  33. tests/example_data/cybsec-mlp/state_dict.pth +0 -0
  34. tests/example_data/cybsec-mlp/validate-unsw-nb15.py +105 -0
  35. tests/example_data/test_ext_weights/specialize_layers_config.json +30 -0
  36. tests/example_data/test_ext_weights/tfc-w2a2-extw.json +38 -0
  37. tests/fpgadataflow/test_code_gen_trafo.py +98 -0
  38. tests/fpgadataflow/test_compilation_trafo.py +95 -0
  39. tests/fpgadataflow/test_convert_to_hw_1d_conv_layer.py +196 -0
  40. tests/fpgadataflow/test_convert_to_hw_channelwise_layer.py +143 -0
  41. tests/fpgadataflow/test_convert_to_hw_conv_fc_transition.py +226 -0
  42. tests/fpgadataflow/test_convert_to_hw_conv_layer.py +173 -0
  43. tests/fpgadataflow/test_convert_to_hw_layers_cnv.py +153 -0
  44. tests/fpgadataflow/test_convert_to_hw_layers_fc.py +208 -0
  45. tests/fpgadataflow/test_convert_to_hw_layers_synthetic.py +238 -0
  46. tests/fpgadataflow/test_convert_to_hw_pool_batch.py +244 -0
  47. tests/fpgadataflow/test_depthwise_convolution.py +242 -0
  48. tests/fpgadataflow/test_fifosizing.py +180 -0
  49. tests/fpgadataflow/test_fpgadataflow_addstreams.py +148 -0
  50. tests/fpgadataflow/test_fpgadataflow_attention.py +537 -0
  51. tests/fpgadataflow/test_fpgadataflow_attention_heads.py +411 -0
  52. tests/fpgadataflow/test_fpgadataflow_channelwise_ops.py +174 -0
  53. tests/fpgadataflow/test_fpgadataflow_checksum.py +230 -0
  54. tests/fpgadataflow/test_fpgadataflow_concat.py +176 -0
  55. tests/fpgadataflow/test_fpgadataflow_convinputgenerator.py +227 -0
  56. tests/fpgadataflow/test_fpgadataflow_convinputgenerator_rtl_dynamic.py +616 -0
  57. tests/fpgadataflow/test_fpgadataflow_deconv.py +206 -0
  58. tests/fpgadataflow/test_fpgadataflow_downsampler.py +162 -0
  59. tests/fpgadataflow/test_fpgadataflow_duplicatestreams.py +159 -0
  60. tests/fpgadataflow/test_fpgadataflow_dwc.py +174 -0
  61. tests/fpgadataflow/test_fpgadataflow_elementwise_binary.py +329 -0
  62. tests/fpgadataflow/test_fpgadataflow_eltwise.py +143 -0
  63. tests/fpgadataflow/test_fpgadataflow_fifo.py +111 -0
  64. tests/fpgadataflow/test_fpgadataflow_fmpadding.py +160 -0
  65. tests/fpgadataflow/test_fpgadataflow_globalaccpool.py +146 -0
  66. tests/fpgadataflow/test_fpgadataflow_ipstitch.py +329 -0
  67. tests/fpgadataflow/test_fpgadataflow_labelselect.py +138 -0
  68. tests/fpgadataflow/test_fpgadataflow_lookup.py +192 -0
  69. tests/fpgadataflow/test_fpgadataflow_mvau.py +961 -0
  70. tests/fpgadataflow/test_fpgadataflow_replicate_stream.py +222 -0
  71. tests/fpgadataflow/test_fpgadataflow_res_estimate.py +145 -0
  72. tests/fpgadataflow/test_fpgadataflow_split.py +154 -0
  73. tests/fpgadataflow/test_fpgadataflow_thresholding.py +387 -0
  74. tests/fpgadataflow/test_fpgadataflow_thresholding_runtime.py +356 -0
  75. tests/fpgadataflow/test_fpgadataflow_upsampler.py +217 -0
  76. tests/fpgadataflow/test_fpgadataflow_vvau.py +474 -0
  77. tests/fpgadataflow/test_minimize_bit_width.py +304 -0
  78. tests/fpgadataflow/test_runtime_weights.py +141 -0
  79. tests/fpgadataflow/test_set_folding.py +136 -0
  80. tests/fpgadataflow/test_split_large_fifos.py +123 -0
  81. tests/fpgadataflow/test_squeeze.py +392 -0
  82. tests/fpgadataflow/test_unsqueeze.py +397 -0
  83. tests/infrastructure/custom_steps.py +2 -0
  84. tests/infrastructure/test_custom_step_resolution.py +32 -0
  85. tests/notebooks/test_jupyter_notebooks.py +108 -0
  86. tests/pyproject.toml +47 -0
  87. tests/test_enforce_import_order.py +43 -0
  88. tests/testing_util/__init__.py +34 -0
  89. tests/testing_util/imagenet.py +1146 -0
  90. tests/testing_util/pytorch.py +65 -0
  91. tests/testing_util/test.py +172 -0
  92. tests/transformation/streamline/test_absorb_mul_into_topk.py +108 -0
  93. tests/transformation/streamline/test_absorb_opposite_transposes.py +81 -0
  94. tests/transformation/streamline/test_absorb_transp_into_flatten.py +100 -0
  95. tests/transformation/streamline/test_collapse_repeated_op.py +132 -0
  96. tests/transformation/streamline/test_factor_out_mul_sign_magnitude.py +61 -0
  97. tests/transformation/streamline/test_maxpool_nhwc.py +97 -0
  98. tests/transformation/streamline/test_move_add_past_mul.py +150 -0
  99. tests/transformation/streamline/test_move_chw_add_past_conv.py +107 -0
  100. tests/transformation/streamline/test_move_flatten_past_affine.py +108 -0
  101. tests/transformation/streamline/test_move_flatten_past_topk.py +94 -0
  102. tests/transformation/streamline/test_move_identical_op_past_join_add.py +151 -0
  103. tests/transformation/streamline/test_move_identical_op_past_join_add_broadcast.py +255 -0
  104. tests/transformation/streamline/test_move_identical_op_past_join_concat.py +184 -0
  105. tests/transformation/streamline/test_move_identical_op_past_split.py +140 -0
  106. tests/transformation/streamline/test_move_maxpool_past_multithreshold.py +125 -0
  107. tests/transformation/streamline/test_move_mul_past_dw_conv.py +118 -0
  108. tests/transformation/streamline/test_move_mul_past_maxpool.py +116 -0
  109. tests/transformation/streamline/test_move_past_fork.py +133 -0
  110. tests/transformation/streamline/test_move_scalar_past_conv.py +196 -0
  111. tests/transformation/streamline/test_move_scalar_past_convtranspose.py +106 -0
  112. tests/transformation/streamline/test_move_scalar_past_matmul.py +190 -0
  113. tests/transformation/streamline/test_move_transpose_past_scalar_mul.py +113 -0
  114. tests/transformation/streamline/test_round_thresholds.py +270 -0
  115. tests/transformation/streamline/test_scale_resize_nhwc.py +376 -0
  116. tests/transformation/streamline/test_sign_to_thres.py +66 -0
  117. tests/transformation/streamline/test_streamline_cnv.py +103 -0
  118. tests/transformation/streamline/test_streamline_fc.py +98 -0
  119. tests/transformation/test_batchnorm_to_affine_bnn_pynq.py +96 -0
  120. tests/transformation/test_infer_data_layouts_cnv.py +124 -0
  121. tests/transformation/test_infer_datatypes_lfc.py +68 -0
  122. tests/transformation/test_qonnx_to_finn.py +145 -0
  123. tests/util/test_build_dataflow.py +81 -0
  124. tests/util/test_create.py +67 -0
  125. tests/util/test_data_packing.py +182 -0
  126. tests/util/test_hls_vector.py +117 -0
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: finn-plus-tests
3
+ Version: 1.3.0
4
+ Summary: Test suite for finn-plus
5
+ Maintainer: Felix Jentzsch
6
+ Maintainer-email: felix.jentzsch@upb.de
7
+ Requires-Python: >=3.10,<3.12
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Requires-Dist: pytest (>=8.4.1,<8.5.0)
12
+ Requires-Dist: pytest-cov (>=6.2.1,<6.3.0)
13
+ Requires-Dist: pytest-dependency (>=0.6.0,<0.7.0)
14
+ Requires-Dist: pytest-forked (>=1.6.0,<1.7.0)
15
+ Requires-Dist: pytest-html (>=4.1.1,<4.2.0)
16
+ Requires-Dist: pytest-html-merger (>=0.1.0,<0.2.0)
17
+ Requires-Dist: pytest-metadata (>=3.1.1,<3.2.0)
18
+ Requires-Dist: pytest-parallel (>=0.1.1,<0.2.0)
19
+ Requires-Dist: pytest-rerunfailures (>=15.1,<15.2)
20
+ Requires-Dist: pytest-xdist[setproctitle] (>=3.6.1,<3.7.0)
21
+ Requires-Dist: torch (>=2.7.1,<2.8.0)
22
+ Requires-Dist: torchvision (>=0.22.1,<0.23.0)
23
+ Requires-Dist: wget (>=3.2,<3.3)
24
+ Project-URL: EKI Project, https://www.eki-project.tech/
25
+ Project-URL: GitHub, https://github.com/eki-project/finn-plus
@@ -0,0 +1,126 @@
1
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ tests/analysis/test_unsupported_layers.py,sha256=zmKLDG7eZLz8l4r-rt5bKYJz8Ty2ZGycOjdua8Nm4C4,7595
3
+ tests/brevitas/king_charles.jpg,sha256=Pgq5wUKohq5lt4pNWIhe1uHnDFOyM7E4c-Dp1hWDolE,44529
4
+ tests/brevitas/test_brevitas_avg_pool_export.py,sha256=E4BvTyFUWwlOHXmishRQDGr4m7dMDvS9ESz1be5seMs,4374
5
+ tests/brevitas/test_brevitas_cnv.py,sha256=9bOSkFpX5lImccaUsqInqWyvfhYwqPayc-nYVJs3ay0,3864
6
+ tests/brevitas/test_brevitas_debug.py,sha256=-xTRT9WThlLoieWNiSepFU9pbf19oOFDWWBkVF__6Hw,4525
7
+ tests/brevitas/test_brevitas_deconv.py,sha256=sVjuQXTz-qeSteTR3KbftboDTIFU1YejL04ysXosdTY,3691
8
+ tests/brevitas/test_brevitas_fc.py,sha256=A6j8CjZBml240Baaz0WCA-kJJffStzcXi4YQGgjAJ_A,4013
9
+ tests/brevitas/test_brevitas_mobilenet.py,sha256=7shY03rlfzLZMo08s3NYj-tPZnD134V0EeG_2ZUwD7A,6205
10
+ tests/brevitas/test_brevitas_non_scaled_quanthardtanh_export.py,sha256=9NBAqarbb03oszI6jiyWLiNFKfcD0xyeI6RxlbcL3m4,3814
11
+ tests/brevitas/test_brevitas_qconv2d.py,sha256=hcBFZtbsg4ojLNPtktLv6-lR8izqSyoTs7lNpvWMuOk,4371
12
+ tests/brevitas/test_brevitas_qlinear.py,sha256=NwDlA-aI_t4EvCB9Bj8wAdQCQoA-hpnOHNuhkyKVCWU,3712
13
+ tests/brevitas/test_brevitas_relu_act_export.py,sha256=qHmWdVtKVHDlFQKD2aO9gMDG6oXhEY1E44S3g9GVHxo,4347
14
+ tests/brevitas/test_brevitas_scaled_qhardtanh_export.py,sha256=zOt0hWbX4Lz9WLT33OpqxDpjkoH9jieGQjA-bkGbc4k,5158
15
+ tests/brevitas/test_brevitas_selu_act_export.py,sha256=lDAu1xZo4_QWXXzxA9vrhk-nrLDi2ktj074__RqBDac,3238
16
+ tests/brevitas/test_brevitas_validate_mobilenet.py,sha256=0wn4X-LLzPmcXGR7e9qG6PibUcsvwM07MD8Bg9qCUMc,9452
17
+ tests/conftest.py,sha256=lh9DAuYg7MAkMzY14nQlFwyxhTjkffYd744_8Xid5Rc,3653
18
+ tests/end2end/test_end2end_bnn_pynq.py,sha256=NSLQ9ZXCqY-09J4D5E1hexAcGMY6lyTDrdmMcEppGos,37787
19
+ tests/end2end/test_end2end_cybsec_mlp.py,sha256=Fp9R4R_btTHJbDCTT6FrfbTnV7KHJuJezcRgrDzlyts,8923
20
+ tests/end2end/test_end2end_mobilenet_v1.py,sha256=bZzsbdZUIdz_N5-afYfu5_TqYmtQ-Pk7pClmheeKTsY,25767
21
+ tests/end2end/test_ext_weights.py,sha256=JPu7BLW75QMDKGIa48POnzhriulUw0S72a_AYHHzZH4,4913
22
+ tests/example_data/build_dataflow/build.py,sha256=GMa8sDNkC3tlS4XxuZEQ1x-5FkTU_6Hn4egNNzwWjAU,3171
23
+ tests/example_data/build_dataflow/dataflow_build_config.json,sha256=f2H2q9hrI3iUO7NsGWkvCs1IeV3Fm5W0ngB_l8lvPb4,677
24
+ tests/example_data/build_dataflow/expected_output.npy,sha256=EFNP3uhvMQNgBI-D2fn1NUDcLvez-kRw3QTR1GOGvis,160
25
+ tests/example_data/build_dataflow/folding_config.json,sha256=CKOotaIavfwA5Ekn-7Wb9PaIhKP8e1I2ONKKEJYJtng,417
26
+ tests/example_data/build_dataflow/input.npy,sha256=W0FgPlFQVhCP7t8yyHwPlUeGMtdov7IonMFKGDExsuU,12672
27
+ tests/example_data/build_dataflow/model.onnx,sha256=Fwa1kJIN8qc9xfJWclKSuahkD5BODgNFVHcitgfepqA,248104
28
+ tests/example_data/build_dataflow/specialize_layers_config.json,sha256=iPNCXq8r6_Yv2s6yIPxVFzP12-ulp_MBaZe1PYAh69o,345
29
+ tests/example_data/cifar10/cifar10-test-data-class3.npz,sha256=7Dg0aDkzoIVgWLYWoTlJJlSjwpwQED1I5chjdEVtbHo,3316
30
+ tests/example_data/cybsec-mlp/state_dict.pth,sha256=W4tZxXh02zwGAPtRBZTpl8zr7v53wkqBiXek7q_VPw4,599154
31
+ tests/example_data/cybsec-mlp/validate-unsw-nb15.py,sha256=S_3Kgzs4RBY0ssp3OZ0P59OWjW3Mgf5oSg_ZOoApIZY,4118
32
+ tests/example_data/test_ext_weights/specialize_layers_config.json,sha256=GRlS1qZwlNSiVxvUtb5iYKmCBTHquDjSUrgcq6IKTKk,537
33
+ tests/example_data/test_ext_weights/tfc-w2a2-extw.json,sha256=8I9DkeJA5dTczaH9JqCnJqcG2oRq4dPybK2yGnftlH4,628
34
+ tests/fpgadataflow/test_code_gen_trafo.py,sha256=rzBwcbMfFk5BTCJFnMuMd4btApbHWUvESicuK7VWX7Q,3697
35
+ tests/fpgadataflow/test_compilation_trafo.py,sha256=GgqCOg6jtBvehXACNAWlNauUAQjyTNKKSNdSTZ2vqhs,3648
36
+ tests/fpgadataflow/test_convert_to_hw_1d_conv_layer.py,sha256=tsNkH89xmHDx58rneaJ1yzaziWeY-ili-fpPgAP21pc,8568
37
+ tests/fpgadataflow/test_convert_to_hw_channelwise_layer.py,sha256=dYEQM3KfJvmjlyDudYIfynxcS5ElWuyVpUkxvZmDenA,6105
38
+ tests/fpgadataflow/test_convert_to_hw_conv_fc_transition.py,sha256=dyw2HOgSRdzFN83g-wMWD97Js9Nj5Bg71ugT60zM0fI,10157
39
+ tests/fpgadataflow/test_convert_to_hw_conv_layer.py,sha256=rOtQIJI2eYB5e3H9pqtCCQRm9wEQlEDscqCj2ImLKHU,7718
40
+ tests/fpgadataflow/test_convert_to_hw_layers_cnv.py,sha256=w6n2gxjiIlxtGvngVZ9A-X2opj_9U051bOo0PGt8baE,7161
41
+ tests/fpgadataflow/test_convert_to_hw_layers_fc.py,sha256=WGAoFzXb8nnyF_lKVJYm617qCcXr1vyIRMlcY6qh4-Q,9352
42
+ tests/fpgadataflow/test_convert_to_hw_layers_synthetic.py,sha256=WFz8_HPXz9gfiHRzOeW-k6z8fvLUV0FHlCFQ8MstC0U,10614
43
+ tests/fpgadataflow/test_convert_to_hw_pool_batch.py,sha256=2A5dyJZQR0hOLH-OXurR-Uftu60Y0Yotj9-LuHlUgfY,10062
44
+ tests/fpgadataflow/test_depthwise_convolution.py,sha256=Y9h7Xdwdlbf3oMElO_xFvOdN2rNnAx1SLJWB70_Wqfk,9413
45
+ tests/fpgadataflow/test_fifosizing.py,sha256=4F7i9LauOaF2OX9d60GZk8x6jZmWYihf7qBYHVNB6Ww,7339
46
+ tests/fpgadataflow/test_fpgadataflow_addstreams.py,sha256=c9ox46zyNmemvvkzw4dpb4Q_fM_0ME1uQNfTegpqswk,5851
47
+ tests/fpgadataflow/test_fpgadataflow_attention.py,sha256=vqndbWDs0m0nlG0lOk6EOKOBIgyECT1qhr6rfSjF9Ys,21863
48
+ tests/fpgadataflow/test_fpgadataflow_attention_heads.py,sha256=c1PD05ghQHpa2YPJKoQVf0HhJ6xc4CbhG58lYlCxDOk,17197
49
+ tests/fpgadataflow/test_fpgadataflow_channelwise_ops.py,sha256=L6fU2ZIYsdeggpp1bg-Fui9Xz8tDESsd16xFYq7h2nc,6584
50
+ tests/fpgadataflow/test_fpgadataflow_checksum.py,sha256=wI4Vi01wKbjDRX60hmGOUhhhOWFNmYTdlXK2zSQQSvU,8347
51
+ tests/fpgadataflow/test_fpgadataflow_concat.py,sha256=xgLJYOHw-q9oSEZstpEP-XOPAC1dNx3IKhxx6pRg2DI,7842
52
+ tests/fpgadataflow/test_fpgadataflow_convinputgenerator.py,sha256=lRDqfhO3agsOFrPQeqHBu50-jmYNpqkOzGrLIpSvfko,9119
53
+ tests/fpgadataflow/test_fpgadataflow_convinputgenerator_rtl_dynamic.py,sha256=xXwpkSNhiyjSNpGbMJfzxnc2R_cIEcAL7jYJj2jMFMI,24767
54
+ tests/fpgadataflow/test_fpgadataflow_deconv.py,sha256=wQnev2UUY2_seWirb3ojgWmXwziB-tb9WoigWwtP8aI,7841
55
+ tests/fpgadataflow/test_fpgadataflow_downsampler.py,sha256=0XkRIKN4bY13SRTW5MDhskRURMTG_87KeNIW1Qf_NE0,6875
56
+ tests/fpgadataflow/test_fpgadataflow_duplicatestreams.py,sha256=_hb_fsEQtWbrcicnfJBoWt5VYrnZ-9-h0kYkMB4aRgk,6218
57
+ tests/fpgadataflow/test_fpgadataflow_dwc.py,sha256=bp6e00supVxsLpWQGaiybiw8dj9W_sDf524wKmW4hcU,6929
58
+ tests/fpgadataflow/test_fpgadataflow_elementwise_binary.py,sha256=UoXr0tPUxJnQ7KuVJ7Jc7za1Pd4f4dUI-rCtVRubKqo,13432
59
+ tests/fpgadataflow/test_fpgadataflow_eltwise.py,sha256=ZmwLzSId-jLl_vdhRz92V5wauldDGQ4QtzE6k5dzYd8,5830
60
+ tests/fpgadataflow/test_fpgadataflow_fifo.py,sha256=CeUv4Q8wVcy-MXaYIl9TjWGr3Ky-AFe9n9MmxEHFNsk,4424
61
+ tests/fpgadataflow/test_fpgadataflow_fmpadding.py,sha256=H90uQ-9IvKy8Q_bMiQZpm7Z4lBA4fTjtzbZ1zc0ujTg,6357
62
+ tests/fpgadataflow/test_fpgadataflow_globalaccpool.py,sha256=morpDJOSp23VWTxnEbewlTMZyTuG5XxAengkpf0CI4U,5847
63
+ tests/fpgadataflow/test_fpgadataflow_ipstitch.py,sha256=i0SiQ_uHwUQ0F9oBQV-hBH3nIkws6RUpEuURoJbna54,13264
64
+ tests/fpgadataflow/test_fpgadataflow_labelselect.py,sha256=lr4u98Ac3TAv4KvvjriRA_nGU7iIOiD2S0s-R9XQFus,5190
65
+ tests/fpgadataflow/test_fpgadataflow_lookup.py,sha256=YIWwCVbTMPcIMISjddIw-bkpbXlBEMlGgQcJRAq6WYg,8962
66
+ tests/fpgadataflow/test_fpgadataflow_mvau.py,sha256=UqO2qUzA8tJCIEawc0fxNri55UMkrSWFACr4QCjNhEg,37880
67
+ tests/fpgadataflow/test_fpgadataflow_replicate_stream.py,sha256=HP4d9_f4eK0W_iMYycU2JnC3qNyHpUerrNPw9ijkBvo,9452
68
+ tests/fpgadataflow/test_fpgadataflow_res_estimate.py,sha256=rtN_IqwoBjyHtKlVzokHpx4qA2rtZ3sPkJy_qu98P2w,5006
69
+ tests/fpgadataflow/test_fpgadataflow_split.py,sha256=ak5stfHVUaoe1BBy9tuFt2nUrcgZ6ivyXChPokfn6BE,6960
70
+ tests/fpgadataflow/test_fpgadataflow_thresholding.py,sha256=rcFBLGeW4GIQZ-ZAOaphJJqynHTCPICRFzNK_M161ac,14736
71
+ tests/fpgadataflow/test_fpgadataflow_thresholding_runtime.py,sha256=zzNsxEdcYPG83IW8PFJnI44-BMve8CAnfxZlOhDP4qA,13291
72
+ tests/fpgadataflow/test_fpgadataflow_upsampler.py,sha256=6m-Y0n_ojSEaDsCXEYrunJ9O8hpmGvHyMV4RTZvsygo,8943
73
+ tests/fpgadataflow/test_fpgadataflow_vvau.py,sha256=TdIApgL_sDQWAz8YRTVPyRGPU1pvlQ-pq2p4gKv-XhI,18721
74
+ tests/fpgadataflow/test_minimize_bit_width.py,sha256=PBxh3HzEG1iAmqfHVDu9c8IWlFu2lZkefAfmmN5v1_E,13041
75
+ tests/fpgadataflow/test_runtime_weights.py,sha256=hB0LM8cI8ifucTHZT2-WZl_R1Ft2bUOApLpvJtk4fXo,5924
76
+ tests/fpgadataflow/test_set_folding.py,sha256=74Uc82ReXDvcwO7BuW-hCInwSB8pJ7Yuv_TGtwvC9-g,5470
77
+ tests/fpgadataflow/test_split_large_fifos.py,sha256=ySJB2hbL5nM1_wRoqHsI1V_w0iX1d8g3OAuQgh-x9wo,5015
78
+ tests/fpgadataflow/test_squeeze.py,sha256=i-Mw5Au7i3mRYdH8GDSzn_WZ9t_n5NQO9Sy3sXi_x7Y,16076
79
+ tests/fpgadataflow/test_unsqueeze.py,sha256=O2kgVgkMtjfHV14rBlsYp96wIXYb71usquTgchSMuTY,16437
80
+ tests/infrastructure/custom_steps.py,sha256=HLC6WxtvIUrWCD4obbOr7iI-B1gvW3g-1vdp5RkGLZ4,53
81
+ tests/infrastructure/test_custom_step_resolution.py,sha256=WobI509D5cfVfgq_Gq21el-FWxO2TQCDoowW4QNTO60,1186
82
+ tests/notebooks/test_jupyter_notebooks.py,sha256=or4hjb7LUlQdNOwDRjc92EI7-tojdrLu54j7AVeiH4k,3775
83
+ tests/pyproject.toml,sha256=DdSsR_PpAi3FGzKWkfs-GE0xprN-nnbu0ka3oPs7olg,1405
84
+ tests/test_enforce_import_order.py,sha256=NgafZaVaDhkmUY6e7YJcXh7q0J5nXZYug6XkQ7UBc_g,1935
85
+ tests/testing_util/__init__.py,sha256=3ZbU4fsQYoB2HHnZt9gDxdgix4yrUdm0TO0QGnJaIs8,1661
86
+ tests/testing_util/imagenet.py,sha256=h-YPkNyx7VKsTjuJF9TIxgTKM5y_zVL2gJaZ2ZdNqN0,39359
87
+ tests/testing_util/pytorch.py,sha256=0el1PA3WFQ6ZFZljk6TDVfpp0FbOaQq1zfsz9UP1OqQ,2493
88
+ tests/testing_util/test.py,sha256=evno7cYsIykLIsN6RWnQ9Fe8GoDg4U-NUr5rIJFmTDA,6493
89
+ tests/transformation/streamline/test_absorb_mul_into_topk.py,sha256=UdNhrKULO9wo5tSS_EEuQNnlG2q-MEsUT5vbLXse_mE,4934
90
+ tests/transformation/streamline/test_absorb_opposite_transposes.py,sha256=6RLfVpoZCMkSVeF23g5Cbv8HxefDs02EZTDdrdmJTUI,3310
91
+ tests/transformation/streamline/test_absorb_transp_into_flatten.py,sha256=YJPxT---2-_aViu1zQCM2TDo84JeLOyzKvFxK9fi_DA,4409
92
+ tests/transformation/streamline/test_collapse_repeated_op.py,sha256=ir6bhld53_iYwoIsAZYyNVNDeOPYmAE1956CaEyvU2o,5973
93
+ tests/transformation/streamline/test_factor_out_mul_sign_magnitude.py,sha256=TXuQJRDQGBztAzlHuHLkTTzHKRHpo5flUcwu3Bvsb2k,2792
94
+ tests/transformation/streamline/test_maxpool_nhwc.py,sha256=BHrtlPZ4qmHMpoPUw-JR38SMOKkRYJfLKIdSIzGHcxI,3266
95
+ tests/transformation/streamline/test_move_add_past_mul.py,sha256=TRGU_xwtdTWSFTaKuggCXf5VHNl8pmu8wQwp2wpZaZc,7238
96
+ tests/transformation/streamline/test_move_chw_add_past_conv.py,sha256=PInRQOjG_hXEKzQh5rtoP40pfpRDKI4Y_mG8xY-IJlI,4304
97
+ tests/transformation/streamline/test_move_flatten_past_affine.py,sha256=JKN0i6mn5PVwxrlCKJwhnBNk3vWgE1x2f7Bp5BGyk0U,4997
98
+ tests/transformation/streamline/test_move_flatten_past_topk.py,sha256=UJrPpaiC362sdJclqH-zryoSmD2FlVoHfwhgc_gPOgU,4164
99
+ tests/transformation/streamline/test_move_identical_op_past_join_add.py,sha256=mPJrk1dxePhMLoYfsUnbR5sQmR-znSECTc6SV5B5yCY,6282
100
+ tests/transformation/streamline/test_move_identical_op_past_join_add_broadcast.py,sha256=cCJokhTLZtgUZ1TIrL_odAnptNbKsXvcZ7APCtr8Waw,9701
101
+ tests/transformation/streamline/test_move_identical_op_past_join_concat.py,sha256=M0qdHo5HDYpAYatXz5cpU9Um-7Of5ZhD-p4Ulp__p8U,7276
102
+ tests/transformation/streamline/test_move_identical_op_past_split.py,sha256=lCKasZIr_u3WXV9yKBxGuGMUZ5G2z9KJUAQnH7eoJC0,5669
103
+ tests/transformation/streamline/test_move_maxpool_past_multithreshold.py,sha256=mW-H05YdLwpts0JuSmCWWXXEPR5Ky5JIneQWxiF2aDs,4796
104
+ tests/transformation/streamline/test_move_mul_past_dw_conv.py,sha256=TwqhbZfi4dDO3T7pXeoCgpnuP9Zpdlx8KYQ2I-mivT8,4846
105
+ tests/transformation/streamline/test_move_mul_past_maxpool.py,sha256=srvQtHKJZiwPfCNXpJ2MuAt5fAhSV5NSVnh-ZUZmE7g,4660
106
+ tests/transformation/streamline/test_move_past_fork.py,sha256=VNDoxJspe1SUDkfZS3Yd061mZ6ZWshGpuGmtbw1qpq0,5220
107
+ tests/transformation/streamline/test_move_scalar_past_conv.py,sha256=6h-1zTZs4lBDb7z_Sg8qPVOFU4JZX3bP7iOrsJF7o3Y,8051
108
+ tests/transformation/streamline/test_move_scalar_past_convtranspose.py,sha256=CPuGXoTtbIfXExutBFggyYv471Oj2R4sCktyxAnOO7I,4321
109
+ tests/transformation/streamline/test_move_scalar_past_matmul.py,sha256=H18AmtQABQjk3NXM1TEEul61sPTBDacca_wcOrYMNXA,8740
110
+ tests/transformation/streamline/test_move_transpose_past_scalar_mul.py,sha256=f97F93euuiBi27WVweA6T9YZB3R7ht0op6Gf_OWO8kM,5392
111
+ tests/transformation/streamline/test_round_thresholds.py,sha256=Db25ZDLPFJ6Z3OcOpkT9Pjo3c0Vk47-Qgp8XaBBk6YA,11940
112
+ tests/transformation/streamline/test_scale_resize_nhwc.py,sha256=SiqWvuEFQYgpoKVr2Y_X-JKGdgZvZ8fNIgPvjrNTAOQ,12687
113
+ tests/transformation/streamline/test_sign_to_thres.py,sha256=4pAotMfofxv3Sba-a-5IPwMFonExWaK__xgn7KuNlSI,3019
114
+ tests/transformation/streamline/test_streamline_cnv.py,sha256=WCPEJAT50QiCTUfGE6pq52EqWf1vG1o2BF9lbjBV0tk,4487
115
+ tests/transformation/streamline/test_streamline_fc.py,sha256=BO3SNHNKi4Hrk3U6vJgWPyTr_A8bUwET1-GV_NT82PE,4519
116
+ tests/transformation/test_batchnorm_to_affine_bnn_pynq.py,sha256=gY1aab1hx92Hd6Tv2bSN42Kkw8ouMfv_AWKI9hU385Q,4321
117
+ tests/transformation/test_infer_data_layouts_cnv.py,sha256=BRoFKJKNJuBwpsioJqrKO8loJj-nFQQhb8-0wACwkmw,6367
118
+ tests/transformation/test_infer_datatypes_lfc.py,sha256=MuWd8U0asiqqBVvncZ-lr6iptXMoHi40kpZiyz8aXb8,3438
119
+ tests/transformation/test_qonnx_to_finn.py,sha256=pJPdD3qQndQIOuJgkNonBzCZP-8eVT2AqsjOa81MQ6M,6228
120
+ tests/util/test_build_dataflow.py,sha256=O7bFZ06s5OEHONtFuR1TvXbFrptxEaOSxC0gN72VS60,4455
121
+ tests/util/test_create.py,sha256=Rx2t0u-l7EAbE92tGL6HNF8JKhQ9cpPaBBoMRgvRQiM,2617
122
+ tests/util/test_data_packing.py,sha256=21DA79zy5c32ZCDPbwkdQw5tbBVKc3gXHdgQCgRckAk,7324
123
+ tests/util/test_hls_vector.py,sha256=ghUtBEUYuiJcg57VKIKskUSWQ_n7o_ZVhy5MiSt1lcI,4819
124
+ finn_plus_tests-1.3.0.dist-info/METADATA,sha256=qOuB6B6TVo2hVB-HvCl2T3dicFpP69Vhzo4CwN3qTHM,1054
125
+ finn_plus_tests-1.3.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
126
+ finn_plus_tests-1.3.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.2.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
tests/__init__.py ADDED
File without changes
@@ -0,0 +1,301 @@
1
+ import pytest
2
+
3
+ import random
4
+ import string
5
+ from onnx import TensorProto, helper
6
+ from qonnx.core.modelwrapper import ModelWrapper
7
+ from qonnx.util.basic import qonnx_make_model
8
+
9
+ from finn.analysis.fpgadataflow.unsupported_layers import unsupported_layers
10
+ from finn.builder.build_dataflow_steps import step_create_dataflow_partition
11
+ from finn.util.exception import FINNUserError
12
+
13
+
14
+ def get_random_name():
15
+ return "".join(random.choices(string.ascii_lowercase, k=10))
16
+
17
+
18
+ def create_tensor():
19
+ return helper.make_tensor_value_info(get_random_name(), TensorProto.FLOAT, None)
20
+
21
+
22
+ def create_node(inputs, outputs, fpga=False, name=None):
23
+ if fpga:
24
+ domain = "finn.custom_op.fpgadataflow"
25
+ else:
26
+ domain = "somethingelse"
27
+
28
+ return helper.make_node(
29
+ "CustomOp", [i.name for i in inputs], [o.name for o in outputs], domain=domain, name=name
30
+ )
31
+
32
+
33
+ @pytest.mark.analysis
34
+ def test_unsupported_layers_expected_fail():
35
+ inp1 = create_tensor()
36
+ inp2 = create_tensor()
37
+
38
+ n1n3 = create_tensor()
39
+ n2n3 = create_tensor()
40
+
41
+ n1 = create_node([inp1], [n1n3], fpga=False)
42
+ n2 = create_node([inp2], [n2n3], fpga=False)
43
+
44
+ n3n5 = create_tensor()
45
+ n3n4 = create_tensor()
46
+
47
+ n3 = create_node([n1n3, n2n3], [n3n4, n3n5], fpga=True)
48
+
49
+ n5n6 = create_tensor()
50
+ n4n6 = create_tensor()
51
+
52
+ n5 = create_node([n3n5], [n5n6], fpga=False)
53
+ n4 = create_node([n3n4], [n4n6], fpga=True)
54
+
55
+ n6n7 = create_tensor()
56
+
57
+ n6 = create_node([n5n6, n4n6], [n6n7], fpga=True)
58
+
59
+ out = create_tensor()
60
+
61
+ n7 = create_node([n6n7], [out], fpga=True)
62
+
63
+ mul_graph = helper.make_graph(
64
+ nodes=[n1, n2, n3, n4, n5, n6, n7],
65
+ name="g1",
66
+ inputs=[inp1, inp2],
67
+ outputs=[out],
68
+ value_info=[n1n3, n2n3, n3n4, n3n5, n5n6, n4n6, n6n7],
69
+ )
70
+
71
+ model = qonnx_make_model(mul_graph)
72
+ model = ModelWrapper(model)
73
+
74
+ ret = unsupported_layers(model)
75
+ assert ret[0] is False, "Model should not be supported, but was not detected as such"
76
+
77
+
78
+ @pytest.mark.analysis
79
+ def test_unsupported_layers():
80
+ inp1 = create_tensor()
81
+ inp2 = create_tensor()
82
+
83
+ n1n3 = create_tensor()
84
+ n2n3 = create_tensor()
85
+
86
+ n1 = create_node([inp1], [n1n3], fpga=False)
87
+ n2 = create_node([inp2], [n2n3], fpga=False)
88
+
89
+ n3n5 = create_tensor()
90
+ n3n4 = create_tensor()
91
+
92
+ n3 = create_node([n1n3, n2n3], [n3n4, n3n5], fpga=True)
93
+
94
+ n5n6 = create_tensor()
95
+ n4n6 = create_tensor()
96
+
97
+ n5 = create_node([n3n5], [n5n6], fpga=True)
98
+ n4 = create_node([n3n4], [n4n6], fpga=True)
99
+
100
+ n6n7 = create_tensor()
101
+
102
+ n6 = create_node([n5n6, n4n6], [n6n7], fpga=True)
103
+
104
+ out = create_tensor()
105
+
106
+ n7 = create_node([n6n7], [out], fpga=True)
107
+
108
+ mul_graph = helper.make_graph(
109
+ nodes=[n1, n2, n3, n4, n5, n6, n7],
110
+ name="g1",
111
+ inputs=[inp1, inp2],
112
+ outputs=[out],
113
+ value_info=[n1n3, n2n3, n3n4, n3n5, n5n6, n4n6, n6n7],
114
+ )
115
+
116
+ model = qonnx_make_model(mul_graph)
117
+ model = ModelWrapper(model)
118
+
119
+ ret = unsupported_layers(model)
120
+ assert ret[0] is True, "Model should be supported, but was not detected as such"
121
+
122
+
123
+ @pytest.mark.analysis
124
+ def test_unsupported_layers_loop():
125
+ inp1 = create_tensor()
126
+ inp2 = create_tensor()
127
+
128
+ n1n3 = create_tensor()
129
+ n2n3 = create_tensor()
130
+
131
+ n1 = create_node([inp1], [n1n3], fpga=False)
132
+ n2 = create_node([inp2], [n2n3], fpga=False)
133
+
134
+ n3n5 = create_tensor()
135
+ n3n4 = create_tensor()
136
+
137
+ n3 = create_node([n1n3, n2n3], [n3n4, n3n5], fpga=True)
138
+
139
+ n5n6 = create_tensor()
140
+ n4n6 = create_tensor()
141
+
142
+ n6n5 = create_tensor()
143
+
144
+ n5 = create_node([n3n5, n6n5], [n5n6], fpga=True)
145
+ n4 = create_node([n3n4], [n4n6], fpga=True)
146
+
147
+ n6n7 = create_tensor()
148
+
149
+ n6 = create_node([n5n6, n4n6], [n6n7, n6n5], fpga=True)
150
+
151
+ out = create_tensor()
152
+
153
+ n7 = create_node([n6n7], [out], fpga=True)
154
+
155
+ mul_graph = helper.make_graph(
156
+ nodes=[n1, n2, n3, n4, n5, n6, n7],
157
+ name="g1",
158
+ inputs=[inp1, inp2],
159
+ outputs=[out],
160
+ value_info=[n1n3, n2n3, n3n4, n3n5, n5n6, n4n6, n6n7],
161
+ )
162
+
163
+ model = qonnx_make_model(mul_graph)
164
+ model = ModelWrapper(model)
165
+
166
+ ret = unsupported_layers(model)
167
+ assert ret[0] is True, "Model should be supported, but was not detected as such"
168
+
169
+
170
+ @pytest.mark.analysis
171
+ def test_large_model():
172
+ inp1 = create_tensor()
173
+ inp2 = create_tensor()
174
+
175
+ n1n3 = create_tensor()
176
+ n2n4 = create_tensor()
177
+
178
+ n1 = create_node([inp1], [n1n3], fpga=False)
179
+ n2 = create_node([inp2], [n2n4], fpga=False)
180
+
181
+ n3n5 = create_tensor()
182
+ n4n5 = create_tensor()
183
+ n4n6 = create_tensor()
184
+
185
+ n3 = create_node([n1n3], [n3n5], fpga=True)
186
+ n4 = create_node([n2n4], [n4n5, n4n6], fpga=False)
187
+
188
+ out1 = create_tensor()
189
+
190
+ n6 = create_node([n4n6], [out1], fpga=False)
191
+
192
+ n5n7 = create_tensor()
193
+ n5n8 = create_tensor()
194
+
195
+ n5 = create_node([n3n5, n4n5], [n5n7, n5n8], fpga=True)
196
+
197
+ out2 = create_tensor()
198
+
199
+ n7 = create_node([n5n7], [out2], fpga=True)
200
+
201
+ n8n9 = create_tensor()
202
+
203
+ n8 = create_node([n5n8], [n8n9], fpga=True)
204
+
205
+ n9n10 = create_tensor()
206
+
207
+ n9 = create_node([n8n9], [n9n10], fpga=True, name="n9")
208
+
209
+ n10n11 = create_tensor()
210
+ n10n12 = create_tensor()
211
+
212
+ n10 = create_node([n9n10], [n10n11, n10n12], fpga=False, name="n10")
213
+
214
+ out3 = create_tensor()
215
+
216
+ n11 = create_node([n10n11], [out3], fpga=False, name="n11")
217
+
218
+ out4 = create_tensor()
219
+
220
+ n12 = create_node([n10n12], [out4], fpga=True, name="n12")
221
+
222
+ mul_graph = helper.make_graph(
223
+ nodes=[n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12],
224
+ name="g2",
225
+ inputs=[inp1, inp2],
226
+ outputs=[out1, out2, out3, out4],
227
+ value_info=[n1n3, n2n4, n3n5, n4n5, n4n6, n5n7, n5n8, n8n9, n9n10, n10n11, n10n12],
228
+ )
229
+
230
+ model = qonnx_make_model(mul_graph)
231
+ model = ModelWrapper(model)
232
+
233
+ ret = unsupported_layers(model)
234
+ assert ret[0] is False, "Model should not be supported, but was not detected as such"
235
+
236
+
237
+ @pytest.mark.analysis
238
+ def test_large_model_step():
239
+ inp1 = create_tensor()
240
+ inp2 = create_tensor()
241
+
242
+ n1n3 = create_tensor()
243
+ n2n4 = create_tensor()
244
+
245
+ n1 = create_node([inp1], [n1n3], fpga=False)
246
+ n2 = create_node([inp2], [n2n4], fpga=False)
247
+
248
+ n3n5 = create_tensor()
249
+ n4n5 = create_tensor()
250
+ n4n6 = create_tensor()
251
+
252
+ n3 = create_node([n1n3], [n3n5], fpga=True)
253
+ n4 = create_node([n2n4], [n4n5, n4n6], fpga=False)
254
+
255
+ out1 = create_tensor()
256
+
257
+ n6 = create_node([n4n6], [out1], fpga=False)
258
+
259
+ n5n7 = create_tensor()
260
+ n5n8 = create_tensor()
261
+
262
+ n5 = create_node([n3n5, n4n5], [n5n7, n5n8], fpga=True)
263
+
264
+ out2 = create_tensor()
265
+
266
+ n7 = create_node([n5n7], [out2], fpga=True)
267
+
268
+ n8n9 = create_tensor()
269
+
270
+ n8 = create_node([n5n8], [n8n9], fpga=True)
271
+
272
+ n9n10 = create_tensor()
273
+
274
+ n9 = create_node([n8n9], [n9n10], fpga=True, name="n9")
275
+
276
+ n10n11 = create_tensor()
277
+ n10n12 = create_tensor()
278
+
279
+ n10 = create_node([n9n10], [n10n11, n10n12], fpga=False, name="n10")
280
+
281
+ out3 = create_tensor()
282
+
283
+ n11 = create_node([n10n11], [out3], fpga=False, name="n11")
284
+
285
+ out4 = create_tensor()
286
+
287
+ n12 = create_node([n10n12], [out4], fpga=True, name="n12")
288
+
289
+ mul_graph = helper.make_graph(
290
+ nodes=[n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12],
291
+ name="g2",
292
+ inputs=[inp1, inp2],
293
+ outputs=[out1, out2, out3, out4],
294
+ value_info=[n1n3, n2n4, n3n5, n4n5, n4n6, n5n7, n5n8, n8n9, n9n10, n10n11, n10n12],
295
+ )
296
+
297
+ model = qonnx_make_model(mul_graph)
298
+ model = ModelWrapper(model)
299
+
300
+ with pytest.raises(FINNUserError):
301
+ step_create_dataflow_partition(model, None)
Binary file
@@ -0,0 +1,114 @@
1
+ # Copyright (c) 2020, Xilinx
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice, this
8
+ # list of conditions and the following disclaimer.
9
+ #
10
+ # * Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # * Neither the name of FINN nor the names of its
15
+ # contributors may be used to endorse or promote products derived from
16
+ # this software without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ import pytest
29
+
30
+ import numpy as np
31
+ import os
32
+ import torch
33
+ from brevitas.export import export_qonnx
34
+ from brevitas.nn import QuantIdentity, QuantReLU, TruncAvgPool2d
35
+ from qonnx.core.datatype import DataType
36
+ from qonnx.core.modelwrapper import ModelWrapper
37
+ from qonnx.transformation.infer_datatypes import InferDataTypes
38
+ from qonnx.transformation.infer_shapes import InferShapes
39
+ from qonnx.util.basic import gen_finn_dt_tensor
40
+ from qonnx.util.cleanup import cleanup as qonnx_cleanup
41
+
42
+ import finn.core.onnx_exec as oxe
43
+ from finn.transformation.qonnx.convert_qonnx_to_finn import ConvertQONNXtoFINN
44
+ from finn.util.basic import make_build_dir
45
+
46
+
47
+ @pytest.mark.brevitas_export
48
+ @pytest.mark.parametrize("kernel_size", [2, 3])
49
+ @pytest.mark.parametrize("stride", [1, 2])
50
+ @pytest.mark.parametrize("signed", [True]) # TODO: Add unsigned test case
51
+ @pytest.mark.parametrize("bit_width", [2, 4])
52
+ @pytest.mark.parametrize("input_bit_width", [4, 8, 16])
53
+ @pytest.mark.parametrize("channels", [2, 4])
54
+ @pytest.mark.parametrize("idim", [7, 8])
55
+ def test_brevitas_avg_pool_export(
56
+ kernel_size,
57
+ stride,
58
+ signed,
59
+ bit_width,
60
+ input_bit_width,
61
+ channels,
62
+ idim,
63
+ ):
64
+ build_dir = make_build_dir(prefix="test_brevitas_avg_pool_export")
65
+ export_onnx_path = os.path.join(build_dir, "test.onnx")
66
+ if signed:
67
+ quant_node = QuantIdentity(
68
+ bit_width=input_bit_width,
69
+ return_quant_tensor=True,
70
+ )
71
+ else:
72
+ quant_node = QuantReLU(
73
+ bit_width=input_bit_width,
74
+ return_quant_tensor=True,
75
+ )
76
+ quant_avgpool = TruncAvgPool2d(
77
+ kernel_size=kernel_size,
78
+ stride=stride,
79
+ bit_width=bit_width,
80
+ return_quant_tensor=False,
81
+ float_to_int_impl_type="FLOOR",
82
+ )
83
+ model_brevitas = torch.nn.Sequential(quant_node, quant_avgpool)
84
+ model_brevitas.eval()
85
+
86
+ # determine input
87
+ input_shape = (1, channels, idim, idim)
88
+ input_array = gen_finn_dt_tensor(DataType["FLOAT32"], input_shape)
89
+
90
+ input_tensor = torch.from_numpy(input_array).float()
91
+
92
+ # export
93
+ export_qonnx(
94
+ model_brevitas,
95
+ export_path=export_onnx_path,
96
+ input_t=input_tensor,
97
+ )
98
+ model = ModelWrapper(export_onnx_path)
99
+ model.save(export_onnx_path)
100
+
101
+ qonnx_cleanup(export_onnx_path, out_file=export_onnx_path)
102
+ model = ModelWrapper(export_onnx_path)
103
+ model = model.transform(ConvertQONNXtoFINN())
104
+ model = model.transform(InferShapes())
105
+ model = model.transform(InferDataTypes())
106
+
107
+ # reference brevitas output
108
+ ref_output_array = model_brevitas(input_tensor).detach().numpy()
109
+ # finn output
110
+ idict = {model.graph.input[0].name: input_array}
111
+ odict = oxe.execute_onnx(model, idict, True)
112
+ finn_output = odict[model.graph.output[0].name]
113
+ # compare outputs
114
+ assert np.isclose(ref_output_array, finn_output).all()
@@ -0,0 +1,82 @@
1
+ # Copyright (c) 2020, Xilinx
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice, this
8
+ # list of conditions and the following disclaimer.
9
+ #
10
+ # * Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # * Neither the name of FINN nor the names of its
15
+ # contributors may be used to endorse or promote products derived from
16
+ # this software without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+
29
+ import pytest
30
+
31
+ import numpy as np
32
+ import os
33
+ import torch
34
+ from brevitas.export import export_qonnx
35
+ from pathlib import Path
36
+ from qonnx.core.modelwrapper import ModelWrapper
37
+ from qonnx.transformation.fold_constants import FoldConstants
38
+ from qonnx.transformation.general import GiveUniqueNodeNames, RemoveStaticGraphInputs
39
+ from qonnx.transformation.infer_shapes import InferShapes
40
+ from qonnx.util.cleanup import cleanup as qonnx_cleanup
41
+
42
+ import finn.core.onnx_exec as oxe
43
+ from finn.transformation.qonnx.convert_qonnx_to_finn import ConvertQONNXtoFINN
44
+ from finn.util.basic import make_build_dir
45
+ from tests.testing_util.test import get_test_model_trained
46
+
47
+
48
+ @pytest.mark.brevitas_export
49
+ @pytest.mark.parametrize("abits", [1, 2])
50
+ @pytest.mark.parametrize("wbits", [1, 2])
51
+ def test_brevitas_cnv_export_exec(wbits, abits):
52
+ if wbits > abits:
53
+ pytest.skip("No wbits > abits cases at the moment")
54
+ build_dir = make_build_dir("test_brevitas_cnv_export_exec")
55
+ export_onnx_path = os.path.join(build_dir, "test_brevitas_cnv.onnx")
56
+ cnv = get_test_model_trained("CNV", wbits, abits)
57
+ ishape = (1, 3, 32, 32)
58
+ export_qonnx(cnv, torch.randn(ishape), export_onnx_path)
59
+ qonnx_cleanup(export_onnx_path, out_file=export_onnx_path)
60
+ model = ModelWrapper(export_onnx_path)
61
+ model = model.transform(ConvertQONNXtoFINN())
62
+ model = model.transform(GiveUniqueNodeNames())
63
+ model = model.transform(InferShapes())
64
+ model = model.transform(FoldConstants())
65
+ model = model.transform(RemoveStaticGraphInputs())
66
+ assert len(model.graph.input) == 1
67
+ assert len(model.graph.output) == 1
68
+ cifar_path = (
69
+ Path(__file__).parent.parent / "example_data" / "cifar10" / "cifar10-test-data-class3.npz"
70
+ )
71
+ input_tensor = np.load(cifar_path)["arr_0"].astype(np.float32)
72
+ input_tensor = input_tensor / 255
73
+ assert input_tensor.shape == (1, 3, 32, 32)
74
+ # run using FINN-based execution
75
+ input_dict = {model.graph.input[0].name: input_tensor}
76
+ output_dict = oxe.execute_onnx(model, input_dict, True)
77
+ produced = output_dict[model.graph.output[0].name]
78
+ # do forward pass in PyTorch/Brevitas
79
+ input_tensor = torch.from_numpy(input_tensor).float()
80
+ expected = cnv.forward(input_tensor).detach().numpy()
81
+ assert np.isclose(produced, expected, atol=1e-3).all()
82
+ assert np.argmax(produced) == 3