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

[Quant] Use finite hops to check if the quant nodes are connected with producer #108572

Closed
wants to merge 5 commits into from
16 changes: 11 additions & 5 deletions torch/ao/quantization/pt2e/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from torch.ao.quantization.quantizer import QuantizationAnnotation

import queue

__all__ = [
"fold_bn_weights_into_conv_node",
"get_aten_graph_module",
Expand All @@ -35,13 +37,17 @@


def _is_connected(next_node: torch.fx.Node, target: torch.fx.Node) -> bool:
if target.op == "output":
return False
if next_node == target:
return True
q = queue.Queue()

Check failure on line 40 in torch/ao/quantization/pt2e/utils.py

View workflow job for this annotation

GitHub Actions / lintrunner / linux-job

MYPY [var-annotated]

Need type annotation for "q"
for n in next_node.users.keys():
if _is_connected(n, target):
q.put(n)
while not q.empty():
node = q.get()
if node.op == "output":
return False
if node == target:
return True
for n in node.users.keys():
q.put(n)
return False


Expand Down