Identifying and visualizing import loops in the PyTorch codebase
Import loop in pytorch/torchgen/model.py
Import loops in pytorch/torchgen/model.py
import_symbol.is_dynamic
property. If any edge in a strongly connected component is dynamic, runtime conflicts are typically resolved.
However, we discovered an import loop worth investigating between flex_decoding.py and flex_attention.py:
flex_decoding.py
imports flex_attention.py
twice — once dynamically and once at top-level. This mixed static/dynamic import pattern from the same module creates potential runtime instability.
Thus, we propose the following refactoring using Codegen:
utils.py
Fileutils.py
as well as resolve the imports from both files to point to the newly created file solving this potential unpredictable error that could lead issues later on.