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

Function parse_yaml

codegen/gen.py:741–795  ·  view source on GitHub ↗
(
    path: str | None,
    tags_yaml_path: str,
    function_filter: Callable[[NativeFunction], bool],
    skip_native_fns_gen: bool = False,
)

Source from the content-addressed store, hash-verified

739
740
741def parse_yaml(
742 path: str | None,
743 tags_yaml_path: str,
744 function_filter: Callable[[NativeFunction], bool],
745 skip_native_fns_gen: bool = False,
746) -> tuple[
747 list[NativeFunction],
748 dict[DispatchKey, dict[OperatorName, BackendMetadata]] | ETKernelIndex,
749]:
750 if path and os.path.exists(path) and os.stat(path).st_size > 0:
751 with open(path) as f:
752 es = yaml.load(f, Loader=LineLoader)
753
754 # Check for kernel index structure
755 kernel_index = (
756 parse_et_yaml_struct(es) if any("kernels" in e for e in es) else None
757 )
758
759 # Remove ET specific fields from entries for BC compatibility
760 for entry in es:
761 for field in ET_FIELDS:
762 entry.pop(field, None)
763
764 parsed_yaml = parse_native_yaml(
765 path,
766 tags_yaml_path,
767 None,
768 skip_native_fns_gen=skip_native_fns_gen,
769 loaded_yaml=es,
770 )
771 native_functions = list(filter(function_filter, parsed_yaml.native_functions))
772 op_names = [f.func.name for f in native_functions]
773
774 # (1) Return ETKernelIndex if kernel index is present
775 if kernel_index is not None:
776 filtered_index = {
777 op_name: kernel_mapping
778 for op_name, kernel_mapping in kernel_index.index.items()
779 if op_name in op_names
780 }
781 return native_functions, ETKernelIndex(index=filtered_index)
782
783 # (2) Return BackendIndices if kernel index is absent
784 def map_index(
785 m: dict[OperatorName, BackendMetadata],
786 ) -> dict[OperatorName, BackendMetadata]:
787 return {op: m[op] for op in m if op in op_names}
788
789 backend_indices = {
790 k: map_index(b.index) for (k, b) in parsed_yaml.backend_indices.items()
791 }
792
793 return native_functions, backend_indices
794 else:
795 return [], {}
796
797
798def parse_yaml_files(

Callers 1

parse_yaml_filesFunction · 0.85

Calls 5

parse_et_yaml_structFunction · 0.85
ETKernelIndexClass · 0.85
map_indexFunction · 0.85
itemsMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected