Skip to content

[MO] Fix fp16 in shapeof subgraphs#4524

Merged
lazarevevgeny merged 25 commits intoopenvinotoolkit:masterfrom
pavel-esir:fix_fp16_in_shapeof_subgraph
Mar 30, 2021
Merged

[MO] Fix fp16 in shapeof subgraphs#4524
lazarevevgeny merged 25 commits intoopenvinotoolkit:masterfrom
pavel-esir:fix_fp16_in_shapeof_subgraph

Conversation

@pavel-esir
Copy link
Copy Markdown
Contributor

@pavel-esir pavel-esir commented Feb 26, 2021

Description: For some models float16 precision in shape subgraphs is not sufficient for correct shape calculation - either shape value exceeds max(float16) or we get inaccurate scales values for operations like Interpolate.

In order to unblock such models decided to keep shape calculation in FP32 even if such models are being converted with command --data_type=FP16. To keep shapes in FP32 the following changes have been made:

  1. added transformation MarkNodesWithShapeValues that goes up from ports of operations that accept shape values (Interpolate:1, Interpolate:2, Reshape:1, etc.) and marks such nodes with 'returns_shape_value' attribute
  2. also the transformation below marks Const nodes carrying shape values with the attribute 'correct_data_type' to prevent converting them to FP16 in convert_data_type.py
  3. moved ChangeCastOutputType to the end of the back phase in order to cover all ShapeOf nodes that could've been inserted during common pipeline transformations
  4. in ChangeCastOutputType if Cast has attr returns_shape_value==True then keep return type float32 even if ['cmd_params'].data_type == 'FP16'

Tickets: 42771, 44587

Code:

  • Transformation tests
  • Comments
  • Code style (PEP8)
  • Transformation generates reshape-able IR
  • Transformation preserves original framework node names

Validation:

  • Unit tests
  • Framework operation tests, no new operations were added
  • Model Optimizer IR Reader check: done

Documentation:

  • Supported frameworks operations list: N/A
  • Guide on how to convert the public model: N/A
  • User guide update: N/A

…BFS search staring point to avoid nodeless shapeof subgraphs
…h in MarkAndChangeDataTypeInShapeOfSubgraphs.py, revised Const values in transformations that affect ShapeOf subgraph nodes
@pavel-esir pavel-esir changed the title Fix fp16 in shapeof subgraph [MO] Fix fp16 in shapeof subgraphs Mar 1, 2021
@pavel-esir pavel-esir requested review from a team, e-nugmanova, evolosen, iimironov and mvafin and removed request for a team and evolosen March 1, 2021 10:01
@pavel-esir pavel-esir added the category: MO Model Optimizer label Mar 1, 2021
@pavel-esir pavel-esir added this to the 2021.3 milestone Mar 1, 2021
@pavel-esir pavel-esir marked this pull request as ready for review March 1, 2021 10:02
@pavel-esir pavel-esir requested a review from a team March 1, 2021 10:02
@pavel-esir
Copy link
Copy Markdown
Contributor Author

Updated list of operations with shape inputs. Added new operations: VariadicSplit:2 with split_lengths, OneHot:1 with depth input and many others.

@lazarevevgeny
Copy link
Copy Markdown
Contributor

@pavel-esir , please, resolve merge conflicts.

# Conflicts:
#	model-optimizer/extensions/front/ChangeCastOutputType.py
#	model-optimizer/extensions/middle/MarkSubgraphsWithCorrectLayout.py
#	model-optimizer/extensions/ops/Cast.py
@pavel-esir
Copy link
Copy Markdown
Contributor Author

resolved all conflicts. @lazarevevgeny @jane-intel please review

@lazarevevgeny lazarevevgeny merged commit 6477e8e into openvinotoolkit:master Mar 30, 2021
luo-cheng2021 pushed a commit to luo-cheng2021/openvino that referenced this pull request Apr 7, 2021
* Initial working solution

* moved bfs_search_apply_on_shapeof_subgraph_nodes from utils/graph.py to MarkShapeOfSubgraphDataType.py

* Reused bfs from MarkSubgraphsWithCorrectLayout.py

* fixed e2e precomit issues: specified correct const data_types, fixed BFS search staring point to avoid nodeless shapeof subgraphs

* fixed mxnet_rnnt: added converting all Const nodes in ShapeOf subgraph in MarkAndChangeDataTypeInShapeOfSubgraphs.py, revised Const values in transformations that affect ShapeOf subgraph nodes

* reverter ReverseV2ToReverseSequence.py and DecomposeBidirectionalRNNSequence.py

* in MarkSubgraphsWithCorrectLayout BFS search beauty applied

* apply review comments, returned back 'in_shape_subgraph' attribute

* graph condition added

* MO IR reader fix for mixed FP16 models, added replacer order placement comment

* moved to back phase

* new solution with marking nodes from bottom to top (WIP)

* successfully tested on back phase

* corrected unittest

* removed check for start nodes size in bfs

* fix transformations that insert f64 to f32 in shape subgraph

* corrected log.warning -> log.debug

* revised list if shape input operations added unittest for Const shape inputs

* applied @lazarevevgeny's comments

* licence head corrections
mryzhov pushed a commit to mryzhov/openvino that referenced this pull request Apr 23, 2021
* Initial working solution

* moved bfs_search_apply_on_shapeof_subgraph_nodes from utils/graph.py to MarkShapeOfSubgraphDataType.py

* Reused bfs from MarkSubgraphsWithCorrectLayout.py

* fixed e2e precomit issues: specified correct const data_types, fixed BFS search staring point to avoid nodeless shapeof subgraphs

* fixed mxnet_rnnt: added converting all Const nodes in ShapeOf subgraph in MarkAndChangeDataTypeInShapeOfSubgraphs.py, revised Const values in transformations that affect ShapeOf subgraph nodes

* reverter ReverseV2ToReverseSequence.py and DecomposeBidirectionalRNNSequence.py

* in MarkSubgraphsWithCorrectLayout BFS search beauty applied

* apply review comments, returned back 'in_shape_subgraph' attribute

* graph condition added

* MO IR reader fix for mixed FP16 models, added replacer order placement comment

* moved to back phase

* new solution with marking nodes from bottom to top (WIP)

* successfully tested on back phase

* corrected unittest

* removed check for start nodes size in bfs

* fix transformations that insert f64 to f32 in shape subgraph

* corrected log.warning -> log.debug

* revised list if shape input operations added unittest for Const shape inputs

* applied @lazarevevgeny's comments

* licence head corrections
@pavel-esir pavel-esir deleted the fix_fp16_in_shapeof_subgraph branch May 12, 2021 09:49
@pavel-esir pavel-esir mentioned this pull request May 25, 2021
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: MO Model Optimizer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants