1#!/usr/bin/env python3 2import os 3 4from torch._inductor import pattern_matcher 5from torch._inductor.fx_passes import joint_graph 6 7 8if __name__ == "__main__": 9 # Start by deleting all the existing patterns. 10 for path in pattern_matcher.SERIALIZED_PATTERN_PATH.iterdir(): 11 if path.name in {"__init__.py", "__pycache__"}: 12 continue 13 if path.is_file(): 14 path.unlink() 15 16 # Now have joint_graph load all known patterns and tell the pattern matcher 17 # to serialize the patterns as it goes. 18 os.environ["PYTORCH_GEN_PATTERNS"] = "1" 19 joint_graph.lazy_init() 20