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

Method from_yaml

torchgen/model.py:544–900  ·  view source on GitHub ↗

Parse a NativeFunction from a dictionary as directly parsed from native_functions.yaml

(
        ei: Dict[str, object],
        loc: "Location",
        valid_tags: Set[str],
        ignore_keys: Optional[Set[DispatchKey]] = None,
    )

Source from the content-addressed store, hash-verified

542 # We parse both the NativeFunction + backend-specific information about it, which it stored in a corresponding BackendIndex.
543 @staticmethod
544 def from_yaml(
545 ei: Dict[str, object],
546 loc: "Location",
547 valid_tags: Set[str],
548 ignore_keys: Optional[Set[DispatchKey]] = None,
549 ) -> Tuple[
550 "NativeFunction", Dict[DispatchKey, Dict["OperatorName", "BackendMetadata"]]
551 ]:
552 """
553 Parse a NativeFunction from a dictionary as directly parsed
554 from native_functions.yaml
555 """
556 e = ei.copy()
557
558 funcs = e.pop("func")
559 assert isinstance(funcs, str), f"not a str: {funcs}"
560 # only support one level of namespace. E.g., aten::add
561 namespace_helper = NamespaceHelper.from_namespaced_entity(
562 namespaced_entity=funcs, max_level=1
563 )
564 namespace = namespace_helper.get_cpp_namespace(default="aten")
565 func = FunctionSchema.parse(namespace_helper.entity_name)
566
567 cpp_no_default_args_list = e.pop("cpp_no_default_args", [])
568 assert isinstance(cpp_no_default_args_list, list)
569 cpp_no_default_args = set(cpp_no_default_args_list)
570
571 use_const_ref_for_mutable_tensors = e.pop(
572 "use_const_ref_for_mutable_tensors", False
573 )
574 assert isinstance(use_const_ref_for_mutable_tensors, bool)
575
576 variants_s = e.pop("variants", "function")
577 assert isinstance(variants_s, str)
578 variants: Set[Variant] = set()
579 for v in variants_s.split(", "):
580 if v == "function":
581 variants.add(Variant.function)
582 elif v == "method":
583 variants.add(Variant.method)
584 else:
585 raise AssertionError(f"illegal variant {v}")
586
587 manual_kernel_registration = e.pop("manual_kernel_registration", False)
588 assert isinstance(
589 manual_kernel_registration, bool
590 ), f"not a bool: {manual_kernel_registration}"
591
592 manual_cpp_binding = e.pop("manual_cpp_binding", False)
593 assert isinstance(manual_cpp_binding, bool), f"not a bool: {manual_cpp_binding}"
594
595 device_guard = e.pop("device_guard", True)
596 assert isinstance(device_guard, bool), f"not a bool: {device_guard}"
597
598 device_check_s = e.pop("device_check", None)
599 assert device_check_s is None or isinstance(
600 device_check_s, str
601 ), f"not a str: {device_check_s}"

Callers 12

setUpMethod · 0.80
setUpMethod · 0.80
setUpMethod · 0.80
setUpMethod · 0.80
test_codegen.pyFile · 0.80
setUpMethod · 0.80
setUpMethod · 0.80
parse_native_yaml_structFunction · 0.80

Calls 15

isinstanceFunction · 0.85
BackendMetadataClass · 0.85
NativeFunctionClass · 0.85
get_cpp_namespaceMethod · 0.80
stripMethod · 0.80
supports_symintMethod · 0.80
has_tensor_argMethod · 0.80
copyMethod · 0.45
popMethod · 0.45
parseMethod · 0.45

Tested by 9

setUpMethod · 0.64
setUpMethod · 0.64
setUpMethod · 0.64
setUpMethod · 0.64
setUpMethod · 0.64
setUpMethod · 0.64