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

Preserve the constant subgraph #2902

Merged
merged 5 commits into from
Aug 29, 2024

Conversation

andrey-churkin
Copy link
Contributor

@andrey-churkin andrey-churkin commented Aug 22, 2024

Reason for changes

Removing the ShapeOf subgraph may lead to the removal of some input edges of operations, and QPS doesn't place FQ on these edges. In this case, the operations are quantized incorrectly because not all required inputs are quantized. These operations don't change their runtime precision in the execution graph, which means we do not have a fully quantized model.

Changes

To resolve the described problem, this PR introduces the following algorithm:

  • Step 1: Find all nodes belonging to the ShapeOf subgraphs in the graph. Let's denote the found nodes as $S$. At this step, we don't remove the found subgraphs; we only store the nodes they consist of. See find_shapeof_subgraphs() method.

  • Step 2: Check the producers for the specified nodes (currently, we are considering only nodes of the LSTMSequence and Convolution types). If any of these producers are in set $S$, it means that we will lose this input edge when the ShapeOf subgraph is removed. Therefore, we try to exclude float subgraphs from this ShapeOf subgraph. Let's denote the nodes that are part of such float subgraphs as $P$. We can see that $P \subset S$. See find_preserved_nodes() method.

  • Step 3: Find all nodes belonging to the Constant subgraphs in the graph. Let's denote the found nodes as $C$. At this step, we don't remove the found subgraphs; we only store the nodes they consist of. See find_constant_subgraphs() method.

  • Step 4: Remove $S \cup C - P$ nodes from the graph.

Related tickets

  • 146088

@andrey-churkin andrey-churkin requested a review from a team as a code owner August 22, 2024 10:16
@github-actions github-actions bot added NNCF Common Pull request that updates NNCF Common NNCF PTQ Pull requests that updates NNCF PTQ NNCF PT Pull requests that updates NNCF PyTorch NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF ONNX Pull requests that updates NNCF ONNX labels Aug 22, 2024
@andrey-churkin
Copy link
Contributor Author

post_training_quantization Build # 456

Copy link
Contributor

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

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

LGTM

@alexsu52 alexsu52 merged commit 6be2fd5 into openvinotoolkit:develop Aug 29, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NNCF Common Pull request that updates NNCF Common NNCF ONNX Pull requests that updates NNCF ONNX NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF PT Pull requests that updates NNCF PyTorch NNCF PTQ Pull requests that updates NNCF PTQ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants