From 25951c4e1e5b4d4ea499a8a232b631a88ac22cd1 Mon Sep 17 00:00:00 2001 From: TimAtGoogle Date: Thu, 24 Oct 2024 15:47:30 -0500 Subject: [PATCH 1/3] Augmented calls to yaml.load to use the safe loader. --- build_tools/autogen_ltc_backend.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/build_tools/autogen_ltc_backend.py b/build_tools/autogen_ltc_backend.py index 13753a6d5949..4d39efd84341 100644 --- a/build_tools/autogen_ltc_backend.py +++ b/build_tools/autogen_ltc_backend.py @@ -30,7 +30,13 @@ TORCHGEN_DIR = Path(torchgen.__path__[0]).resolve() TORCH_MLIR_DIR = Path(__file__).resolve().parent.parent - +# Safely load fast C Yaml loader/dumper if they are available +try: + from yaml import CSafeLoader as Loader +except ImportError: + from yaml import SafeLoader as Loader #type:ignore[assignment, misc] + +dimsa3-reGdoj-ciqbac def reindent(text, prefix=""): return indent(dedent(text), prefix) @@ -175,7 +181,7 @@ def generate_native_functions(self): ) ts_native_yaml = None if ts_native_yaml_path.exists(): - ts_native_yaml = yaml.load(ts_native_yaml_path.read_text(), yaml.CLoader) + ts_native_yaml = yaml.load(ts_native_yaml_path.read_text(), Loader) else: logging.warning( f"Could not find `ts_native_functions.yaml` at {ts_native_yaml_path}" @@ -208,7 +214,7 @@ def get_opnames(ops): ) with self.config_path.open() as f: - config = yaml.load(f, yaml.CLoader) + config = yaml.load(f, Loader) # List of unsupported ops in LTC autogen because of some error blacklist = set(config.get("blacklist", [])) From 58041a47131a1a32fa25fced05c1403733ca98b1 Mon Sep 17 00:00:00 2001 From: TimAtGoogle Date: Tue, 29 Oct 2024 17:37:17 -0500 Subject: [PATCH 2/3] Augmented calls to yaml.load to use the safe loader. --- build_tools/autogen_ltc_backend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_tools/autogen_ltc_backend.py b/build_tools/autogen_ltc_backend.py index 4d39efd84341..1f62467f1ceb 100644 --- a/build_tools/autogen_ltc_backend.py +++ b/build_tools/autogen_ltc_backend.py @@ -30,12 +30,12 @@ TORCHGEN_DIR = Path(torchgen.__path__[0]).resolve() TORCH_MLIR_DIR = Path(__file__).resolve().parent.parent -# Safely load fast C Yaml loader/dumper if they are available +# Safely load fast C Yaml loader if it is are available try: from yaml import CSafeLoader as Loader except ImportError: from yaml import SafeLoader as Loader #type:ignore[assignment, misc] - + dimsa3-reGdoj-ciqbac def reindent(text, prefix=""): return indent(dedent(text), prefix) From 419b3e2b6e94acf9af69ef13a21db19dccc499c3 Mon Sep 17 00:00:00 2001 From: TimAtGoogle Date: Tue, 29 Oct 2024 18:01:52 -0500 Subject: [PATCH 3/3] Changed calls to yaml.load to explicitly use the safe loader. --- build_tools/autogen_ltc_backend.py | 1 - 1 file changed, 1 deletion(-) diff --git a/build_tools/autogen_ltc_backend.py b/build_tools/autogen_ltc_backend.py index 1f62467f1ceb..2b4c07cf76b3 100644 --- a/build_tools/autogen_ltc_backend.py +++ b/build_tools/autogen_ltc_backend.py @@ -36,7 +36,6 @@ except ImportError: from yaml import SafeLoader as Loader #type:ignore[assignment, misc] -dimsa3-reGdoj-ciqbac def reindent(text, prefix=""): return indent(dedent(text), prefix)