[Quant] Move to BFS instead of DFS to check for connectedness (#108572)
Summary:
Using dfs to check if two nodes are connecgted is making it very slow.
Use of BFS makes it much faster.
Test Plan:
https://gist.github.com/leslie-fang-intel/9cd828623f567a3afbf41564d3546398
Reviewers:
Subscribers:
Tasks:
Tags:
Differential Revision: [D48971710](https://our.internmc.facebook.com/intern/diff/D48971710)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/108572
Approved by: https://github.com/jerryzh168, https://github.com/osalpekar