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

Function parse_et_yaml_struct

codegen/parse.py:81–102  ·  view source on GitHub ↗

Given a loaded yaml representing a list of operators, for each op extract the mapping of `kernel keys` to `BackendMetadata` (the latter representing the kernel instance that should be used by the kernel key).

(es: object)

Source from the content-addressed store, hash-verified

79
80
81def parse_et_yaml_struct(es: object) -> ETKernelIndex:
82 """Given a loaded yaml representing a list of operators, for each op extract the mapping
83 of `kernel keys` to `BackendMetadata` (the latter representing the kernel instance
84 that should be used by the kernel key).
85 """
86 indices: dict[OperatorName, dict[ETKernelKey, BackendMetadata]] = {}
87 for ei in es: # type: ignore[attr-defined]
88 e = ei.copy()
89
90 funcs = e.pop("func")
91 assert isinstance(funcs, str), f"not a str: {funcs}"
92 namespace_helper = NamespaceHelper.from_namespaced_entity(
93 namespaced_entity=funcs, max_level=1
94 )
95 opname = FunctionSchema.parse(namespace_helper.entity_name).name
96
97 assert opname not in indices, f"Duplicate func found in yaml: {opname} already"
98
99 if len(index := parse_from_yaml(e)) != 0:
100 indices[opname] = index
101
102 return ETKernelIndex(indices)
103
104
105def extract_kernel_fields(es: object) -> dict[OperatorName, dict[str, Any]]:

Callers 1

parse_yamlFunction · 0.85

Calls 3

parse_from_yamlFunction · 0.85
ETKernelIndexClass · 0.85
copyMethod · 0.45

Tested by

no test coverage detected