MCPcopy Create free account
hub / github.com/pytorch/executorch / parse_yaml_files

Function parse_yaml_files

codegen/gen.py:798–865  ·  view source on GitHub ↗

Parses functions.yaml and custom_ops.yaml files. Args: tags_yaml_path: Path to a tags.yaml file to satisfy codegen parsing. It is not optional. aten_yaml_path: Path to ATen operator yaml file native_functions.yaml. native_yaml_path: Path to a functions.yaml f

(
    tags_yaml_path: str,
    aten_yaml_path: str,
    native_yaml_path: str | None,
    custom_ops_yaml_path: str | None,
    selector: SelectiveBuilder,
    use_aten_lib: bool,
)

Source from the content-addressed store, hash-verified

796
797
798def parse_yaml_files(
799 tags_yaml_path: str,
800 aten_yaml_path: str,
801 native_yaml_path: str | None,
802 custom_ops_yaml_path: str | None,
803 selector: SelectiveBuilder,
804 use_aten_lib: bool,
805) -> tuple[ETParsedYaml, ETParsedYaml | None]:
806 """Parses functions.yaml and custom_ops.yaml files.
807
808 Args:
809 tags_yaml_path: Path to a tags.yaml file to satisfy codegen parsing.
810 It is not optional.
811 aten_yaml_path: Path to ATen operator yaml file native_functions.yaml.
812 native_yaml_path: Path to a functions.yaml file to parse.
813 If the path does not exist in the filesystem, it is treated as an
814 empty file. If `custom_ops_yaml_path` exists, the contents of that
815 file are appended to the yaml input to be parsed.
816 custom_ops_yaml_path: Path to a custom_ops.yaml file to parse. If
817 the path does not exist in the filesystem, it is ignored.
818 selector: For selective build.
819 use_aten_lib: We use this flag to determine if we want to generate native
820 functions. In ATen mode we should generate out= variants.
821 Returns:
822 A tuple with two elements:
823 [0]: The parsed results of concatenating the contents of
824 `native_yaml_path` and `custom_ops_yaml_path`.
825 [1]: The parsed results of the contents of `custom_ops_yaml_path`, if
826 present. If not present, None.
827 """
828 import tempfile
829
830 # only include selected ops, this is because we want to avoid
831 def function_filter(f: NativeFunction) -> bool:
832 return selector.is_native_function_selected(f)
833
834 with tempfile.TemporaryDirectory() as tmpdirname:
835 translated_yaml_path = os.path.join(tmpdirname, "translated.yaml")
836 with open(translated_yaml_path, "w") as translated:
837 translate_native_yaml(
838 tags_yaml_path,
839 aten_yaml_path,
840 native_yaml_path,
841 use_aten_lib,
842 translated,
843 )
844
845 translated_functions, translated_indices = parse_yaml(
846 translated_yaml_path, tags_yaml_path, function_filter, not use_aten_lib
847 )
848 custom_ops_functions, custom_ops_indices = parse_yaml(
849 custom_ops_yaml_path, tags_yaml_path, function_filter, True
850 )
851
852 # Convert BackendIndices to ETKernelIndex
853 if not isinstance(translated_indices, ETKernelIndex):
854 translated_indices = ETKernelIndex.from_backend_indices(translated_indices)
855 if not isinstance(custom_ops_indices, ETKernelIndex):

Callers 3

test_parse_yaml_filesMethod · 0.90
test_parse_yaml_filesMethod · 0.90
mainFunction · 0.85

Calls 4

translate_native_yamlFunction · 0.85
parse_yamlFunction · 0.85
from_backend_indicesMethod · 0.80
merge_indicesMethod · 0.80

Tested by 2

test_parse_yaml_filesMethod · 0.72
test_parse_yaml_filesMethod · 0.72