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

Function parse_et_yaml_struct

torchgen/executorch/parse.py:74–95  ·  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

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

Callers 1

parse_yamlFunction · 0.90

Calls 7

ETKernelIndexClass · 0.90
isinstanceFunction · 0.85
parse_from_yamlFunction · 0.85
copyMethod · 0.45
popMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…