Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Augmented calls to yaml.load to use the safe loader. #3817

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions build_tools/autogen_ltc_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
TORCHGEN_DIR = Path(torchgen.__path__[0]).resolve()
TORCH_MLIR_DIR = Path(__file__).resolve().parent.parent

# 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]

def reindent(text, prefix=""):
return indent(dedent(text), prefix)
Expand Down Expand Up @@ -175,7 +180,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 +213,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
Loading