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

Added a helper script for extracting an IR subgraph #2168

Merged
merged 10 commits into from
Oct 9, 2023

Conversation

nikita-savelyevv
Copy link
Collaborator

@nikita-savelyevv nikita-savelyevv commented Oct 2, 2023

Changes

There recently have been cases of very large model IRs, for example for LLMs which can't be opened by Netron. This makes it difficult to examine model graph in general and Fake Quantize node placement in particular.

The added helper script allows to select a node from a graph and extract some subgraph around it. To control how many surrounding nodes to include, distance parameter is used.

Usage examples

python ir_subgraph.py openvino.xml "Constant_1116858"

The result will be saved at ./openvino_Constant_1116858_10.xml. An additional symbolic link will be created at ./openvino_Constant_1116858_10.bin leading to original .bin file so that weights for the subgraph IR are visible through Netron.

  • Parameter --distance can be used to control the subgraph size (10 by default)
python ir_subgraph.py openvino.xml "Constant_1116858" --distance 5

The result will be saved at ./openvino_Constant_1116858_5.xml.

  • Parameter --output-path can be used to control where to save the result. It can either be a file path or a directory path.
python ir_subgraph.py openvino.xml "Constant_1116858" --output-path ./subgraphs

The result will be saved at ./subgraphs/openvino_Constant_1116858_10.xml.

python ir_subgraph.py openvino.xml "Constant_1116858" --output-path ./subgraphs/Constant_1116858.xml

The result will be saved at ./subgraphs/Constant_1116858.xml.

Simplifying usage

A file can be run like below

 ir_subgraph.py openvino.xml "Constant_1116858"

after performing the following steps

  1. Add the directory with the ir_subgraph.py file to PATH variable PATH=$PATH:/path/to/dir
  2. Make it executable chmod +x /path/to/ir_subgraph.py
  3. Add #!/path/to/python as the first line of ir_subgraph.py

Reason for changes

Making it easier to analyze large graphs.

@nikita-savelyevv nikita-savelyevv requested a review from a team as a code owner October 2, 2023 08:28
@codecov
Copy link

codecov bot commented Oct 2, 2023

Codecov Report

Merging #2168 (f822bbe) into develop (1920398) will increase coverage by 0.01%.
Report is 4 commits behind head on develop.
The diff coverage is n/a.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2168      +/-   ##
===========================================
+ Coverage    36.13%   36.14%   +0.01%     
===========================================
  Files          478      480       +2     
  Lines        42723    43005     +282     
===========================================
+ Hits         15436    15546     +110     
- Misses       27287    27459     +172     

see 29 files with indirect coverage changes

Copy link
Contributor

@vshampor vshampor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type hints would be appreciated.

tools/ir_subgraph.py Outdated Show resolved Hide resolved
tools/ir_subgraph.py Outdated Show resolved Hide resolved
tools/ir_subgraph.py Outdated Show resolved Hide resolved
@l-bat
Copy link
Collaborator

l-bat commented Oct 3, 2023

@nikita-savelyevv thanks for the very clear description in PR! Could you please add more details to the script? It would be nice to have a Usage example.

@alexsu52 alexsu52 merged commit 881cca6 into openvinotoolkit:develop Oct 9, 2023
6 checks passed
@nikita-savelyevv nikita-savelyevv deleted the ir-subgraph branch October 9, 2023 16:00
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.

4 participants