Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Improve performance by adding forward indexes. #1035

Closed
wants to merge 51 commits into from

Conversation

xadupre
Copy link
Collaborator

@xadupre xadupre commented Aug 3, 2020

Add forward index to easily find nodes ingesting a node. Following profile measure the improvment for the conversion of model EfficientNetB2, with and without this PR.

Before:

61.469 profile  conversion_time.py:44
`- 61.469 convert  conversion_time.py:38
   |- 35.363 spy_convert  conversion_time.py:26
   |  |- 34.500 spy_convert_in  conversion_time.py:30
   |  |  `- 34.497 process_tf_graph  tf2onnx/tfonnx.py:334
   |  |     |- 16.260 tensorflow_onnx_mapping  tf2onnx/tfonnx.py:211
   |  |     |  |- 5.029 version_11  tf2onnx/onnx_opset/nn.py:360
   |  |     |  |  `- 5.029 version_1  tf2onnx/onnx_opset/nn.py:325
   |  |     |  |     `- 4.989 conv_convert_inputs  tf2onnx/onnx_opset/nn.py:64
   |  |     |  |        |- 2.890 insert_new_node_on_output  tf2onnx/graph.py:1252
   |  |     |  |        |  `- 2.773 replace_all_inputs  tf2onnx/graph.py:1291
   |  |     |  |        |     `- 1.462 replace_all_inputs  tf2onnx/graph.py:1291
   |  |     |  |        `- 1.747 find_output_consumers  tf2onnx/graph.py:1277
   |  |     |  |           `- 0.920 find_output_consumers  tf2onnx/graph.py:1277
   |  |     |  |              `- 0.634 get_body_graphs  tf2onnx/graph.py:332
   |  |     |  |- 4.203 version_1  tf2onnx/onnx_opset/tensor.py:129
   |  |     |  |  `- 4.193 replace_all_inputs  tf2onnx/graph.py:1291
   |  |     |  |     |- 2.185 replace_all_inputs  tf2onnx/graph.py:1291
   |  |     |  |     |  |- 0.897 [self]  
   |  |     |  |     |  `- 0.796 get_body_graphs  tf2onnx/graph.py:332
   |  |     |  |     |- 0.775 [self]  
   |  |     |  |     `- 0.675 get_body_graphs  tf2onnx/graph.py:332
   |  |     |  |- 2.079 version_1  tf2onnx/onnx_opset/tensor.py:110
   |  |     |  |  `- 2.065 replace_all_inputs  tf2onnx/graph.py:1291
   |  |     |  |     |- 0.792 [self]  
   |  |     |  |     `- 0.755 get_body_graphs  tf2onnx/graph.py:332
   |  |     |  |- 1.845 version_1  tf2onnx/onnx_opset/controlflow.py:420
   |  |     |  |  `- 1.788 wire_if_branch  tf2onnx/onnx_opset/controlflow.py:725
   |  |     |  |     `- 1.721 prefix_graph  tf2onnx/onnx_opset/controlflow.py:795
   |  |     |  |        `- 1.031 replace_all_inputs  tf2onnx/graph.py:1291
   |  |     |  |- 0.775 version_1  tf2onnx/onnx_opset/nn.py:443
   |  |     |  |  `- 0.768 conv_convert_inputs  tf2onnx/onnx_opset/nn.py:64
   |  |     |  |     `- 0.696 insert_new_node_on_output  tf2onnx/graph.py:1252
   |  |     |  |        `- 0.673 replace_all_inputs  tf2onnx/graph.py:1291
   |  |     |  |- 0.746 version_10  tf2onnx/onnx_opset/tensor.py:760
   |  |     |  |  `- 0.744 version_1  tf2onnx/onnx_opset/tensor.py:647
   |  |     |  |     `- 0.710 insert_new_node_on_output  tf2onnx/graph.py:1252
   |  |     |  |        `- 0.687 replace_all_inputs  tf2onnx/graph.py:1291
   |  |     |  |- 0.718 version_1  tf2onnx/onnx_opset/tensor.py:1030
   |  |     |  |  `- 0.680 replace_all_inputs  tf2onnx/graph.py:1291
   |  |     |  `- 0.713 version_1  tf2onnx/onnx_opset/tensor.py:1176
   |  |     |     `- 0.698 insert_new_node_on_output  tf2onnx/graph.py:1252
   |  |     |        `- 0.670 replace_all_inputs  tf2onnx/graph.py:1291
   |  |     |- 6.489 process_tf_graph  tf2onnx/tfonnx.py:334
   |  |     |  |- 3.558 run_rewriters  tf2onnx/tfonnx.py:302
   |  |     |  |  `- 0.979 reset_nodes  tf2onnx/graph.py:665
   |  |     |  |- 1.042 tensorflow_onnx_mapping  tf2onnx/tfonnx.py:211
   |  |     |  `- 0.899 tensorflow_to_onnx  tf2onnx/tf_utils.py:225
   |  |     |     `- 0.897 tflist_to_onnx  tf2onnx/tf_utils.py:132
   |  |     |- 6.242 resolve_functions  tf2onnx/tf_loader.py:417
   |  |     |  |- 3.780 tflist_to_onnx  tf2onnx/tf_utils.py:132
   |  |     |  |  `- 2.336 tf_to_onnx_tensor  tf2onnx/tf_utils.py:53
   |  |     |  |     `- 2.241 get_tf_tensor_data  tf2onnx/tf_utils.py:69
   |  |     |  |        `- 2.060 _array_str_implementation  numpy/core/arrayprint.py:1489
   |  |     |  |              [102 frames hidden]  numpy
   |  |     |  `- 2.188 function_def_to_graph  tensorflow/python/framework/function_def_to_graph.py:33
   |  |     |        [518 frames hidden]  tensorflow, contextlib, threading, fu...
   |  |     |- 3.083 tensorflow_to_onnx  tf2onnx/tf_utils.py:225
   |  |     |  `- 3.083 tflist_to_onnx  tf2onnx/tf_utils.py:132
   |  |     |     `- 2.201 tf_to_onnx_tensor  tf2onnx/tf_utils.py:53
   |  |     |        `- 2.127 get_tf_tensor_data  tf2onnx/tf_utils.py:69
   |  |     |           `- 2.005 _array_str_implementation  numpy/core/arrayprint.py:1489
   |  |     |                 [100 frames hidden]  numpy
   |  |     |- 1.100 run_rewriters  tf2onnx/tfonnx.py:302
   |  |     `- 0.871 update_proto  tf2onnx/graph.py:795
   |  |        `- 0.870 update_proto  tf2onnx/graph.py:344
   |  |           `- 0.703 make_graph  tf2onnx/graph.py:1027
   |  `- 0.863 new_func  tensorflow/python/util/deprecation.py:473
   |        [265 frames hidden]  tensorflow, contextlib, inspect
   `- 26.091 spy_model  conversion_time.py:9
      |- 23.741 EfficientNetB2  tensorflow/python/keras/applications/efficientnet.py:569
      |     [38166 frames hidden]  tensorflow, _collections_abc, six, th...
      `- 1.940 new_func  tensorflow/python/util/deprecation.py:311
            [363 frames hidden]  tensorflow, abc, contextlib, copy, lo...

After:

40.406 profile  conversion_time.py:45
`- 40.406 convert  conversion_time.py:39
   |- 24.676 spy_model  conversion_time.py:10
   |  |- 22.778 EfficientNetB2  tensorflow/python/keras/applications/efficientnet.py:569
   |  |     [35899 frames hidden]  tensorflow, _collections_abc, six, th...
   |  `- 1.508 new_func  tensorflow/python/util/deprecation.py:311
   |        [343 frames hidden]  tensorflow, abc, copy, logging, absl,...
   `- 15.715 spy_convert  conversion_time.py:27
      |- 14.877 spy_convert_in  conversion_time.py:31
      |  `- 14.874 process_tf_graph  tf2onnx/tfonnx.py:334
      |     |- 5.679 process_tf_graph  tf2onnx/tfonnx.py:334
      |     |  |- 3.258 run_rewriters  tf2onnx/tfonnx.py:302
      |     |  |  |- 0.850 reset_nodes  tf2onnx/graph.py:665
      |     |  |  |  `- 0.491 [self]  
      |     |  |  `- 0.424 rewrite_flatten  tf2onnx/rewriter/flatten_rewriter.py:17
      |     |  |     `- 0.409 match_ops  tf2onnx/graph_matcher.py:243
      |     |  |        `- 0.406 match_op  tf2onnx/graph_matcher.py:226
      |     |  |- 0.837 tensorflow_onnx_mapping  tf2onnx/tfonnx.py:211
      |     |  `- 0.743 tensorflow_to_onnx  tf2onnx/tf_utils.py:225
      |     |     `- 0.741 tflist_to_onnx  tf2onnx/tf_utils.py:132
      |     |- 3.993 resolve_functions  tf2onnx/tf_loader.py:417
      |     |  |- 1.949 function_def_to_graph  tensorflow/python/framework/function_def_to_graph.py:33
      |     |  |     [524 frames hidden]  tensorflow, contextlib, threading, fu...
      |     |  `- 1.775 tflist_to_onnx  tf2onnx/tf_utils.py:132
      |     |     `- 0.446 get_tf_node_attr  tf2onnx/tf_utils.py:120
      |     |        `- 0.433 get_attr  tensorflow/python/framework/ops.py:2497
      |     |              [18 frames hidden]  tensorflow, contextlib
      |     |- 2.178 tensorflow_onnx_mapping  tf2onnx/tfonnx.py:211
      |     |  `- 1.492 version_1  tf2onnx/onnx_opset/controlflow.py:420
      |     |     `- 1.440 wire_if_branch  tf2onnx/onnx_opset/controlflow.py:725
      |     |        `- 1.375 prefix_graph  tf2onnx/onnx_opset/controlflow.py:795
      |     |           |- 0.693 replace_all_inputs  tf2onnx/graph.py:1298
      |     |           `- 0.519 make_node  tf2onnx/graph.py:549
      |     |- 1.073 run_rewriters  tf2onnx/tfonnx.py:302
      |     |  `- 0.503 reset_nodes  tf2onnx/graph.py:665
      |     |- 0.806 tensorflow_to_onnx  tf2onnx/tf_utils.py:225
      |     |  `- 0.806 tflist_to_onnx  tf2onnx/tf_utils.py:132
      |     `- 0.754 update_proto  tf2onnx/graph.py:795
      |        `- 0.753 update_proto  tf2onnx/graph.py:344
      |           `- 0.596 make_graph  tf2onnx/graph.py:1027
      `- 0.838 new_func  tensorflow/python/util/deprecation.py:473
            [270 frames hidden]  tensorflow, contextlib, threading, in...

@lgtm-com
Copy link

lgtm-com bot commented Aug 3, 2020

This pull request introduces 1 alert when merging 1de2a95 into 36d7413 - view on LGTM.com

new alerts:

  • 1 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Aug 3, 2020

This pull request introduces 1 alert when merging 4167ad1 into 36d7413 - view on LGTM.com

new alerts:

  • 1 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Aug 3, 2020

This pull request introduces 1 alert when merging 6fc785d into 36d7413 - view on LGTM.com

new alerts:

  • 1 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Aug 3, 2020

This pull request introduces 2 alerts when merging 63d12a7 into 36d7413 - view on LGTM.com

new alerts:

  • 1 for Unused local variable
  • 1 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Aug 3, 2020

This pull request introduces 2 alerts when merging b612427 into b4126fb - view on LGTM.com

new alerts:

  • 1 for Unused local variable
  • 1 for Unused import

@xadupre xadupre changed the title Improve performance by adding forward indexes. [WIP] Improve performance by adding forward indexes. Aug 4, 2020
@lgtm-com
Copy link

lgtm-com bot commented Aug 4, 2020

This pull request introduces 2 alerts when merging 57a3d6c into b4126fb - view on LGTM.com

new alerts:

  • 1 for Unused local variable
  • 1 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Aug 4, 2020

This pull request introduces 1 alert when merging 922ce19 into b4126fb - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 4, 2020

This pull request introduces 1 alert when merging 00091ff into b4126fb - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 4, 2020

This pull request introduces 1 alert when merging 91fb1c1 into b4126fb - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 4, 2020

This pull request introduces 1 alert when merging 4949509 into b4126fb - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 4, 2020

This pull request introduces 1 alert when merging 7047b47 into b4126fb - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 4, 2020

This pull request introduces 1 alert when merging b81b2f8 into b4126fb - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 4, 2020

This pull request introduces 1 alert when merging 78a7ac3 into b4126fb - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 4, 2020

This pull request introduces 1 alert when merging 252fd21 into b4126fb - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 10, 2020

This pull request introduces 1 alert when merging 0f6a1cc into c867e52 - view on LGTM.com

new alerts:

  • 1 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Aug 10, 2020

This pull request introduces 1 alert when merging ebff87d into c867e52 - view on LGTM.com

new alerts:

  • 1 for Unused import

@lgtm-com
Copy link

lgtm-com bot commented Aug 11, 2020

This pull request introduces 2 alerts when merging 6570acd into 0110037 - view on LGTM.com

new alerts:

  • 2 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 11, 2020

This pull request introduces 2 alerts when merging 1b03b07 into 0110037 - view on LGTM.com

new alerts:

  • 2 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 12, 2020

This pull request introduces 2 alerts when merging 785e8aa into 0110037 - view on LGTM.com

new alerts:

  • 2 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 12, 2020

This pull request introduces 2 alerts when merging 16b5284 into 0110037 - view on LGTM.com

new alerts:

  • 2 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 12, 2020

This pull request introduces 2 alerts when merging 09119b9 into d3d301a - view on LGTM.com

new alerts:

  • 2 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Aug 12, 2020

This pull request introduces 2 alerts when merging ffac86a into d3d301a - view on LGTM.com

new alerts:

  • 2 for Unused local variable

@xadupre xadupre closed this Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants