Skip to content

Commit

Permalink
Augmented calls to yaml.load to use the safe loader.
Browse files Browse the repository at this point in the history
  • Loading branch information
TimAtGoogle committed Oct 24, 2024
1 parent 76209db commit 7215d30
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions build_tools/autogen_ltc_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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", []))
Expand Down

0 comments on commit 7215d30

Please sign in to comment.