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

Method call_function

torch/_dynamo/variables/misc.py:731–959  ·  view source on GitHub ↗
(
        self, tx, args: "List[VariableTracker]", kwargs: "Dict[str, VariableTracker]"
    )

Source from the content-addressed store, hash-verified

729 }
730
731 def call_function(
732 self, tx, args: "List[VariableTracker]", kwargs: "Dict[str, VariableTracker]"
733 ) -> "VariableTracker":
734 from .builtin import BuiltinVariable
735
736 if inspect.getattr_static(self.value, "_torchdynamo_disable", False):
737 unimplemented(f"call torch._dynamo.disable() wrapped function {self.value}")
738 # Allowlist a few popular classes(e.g, collections.OrderedDict) calls in skip files.
739 elif self.value is collections.OrderedDict:
740 return BuiltinVariable.call_custom_dict(
741 tx, collections.OrderedDict, *args, **kwargs
742 )
743 elif (
744 self.value is collections.defaultdict
745 and len(args) <= 1
746 and DefaultDictVariable.is_supported_arg(args[0])
747 ):
748 return DefaultDictVariable(
749 {},
750 collections.defaultdict,
751 args[0],
752 mutable_local=MutableLocal(),
753 )
754 # Fold through the functions(e.g, collections.namedtuple)
755 # that inputs & outputs are all python constants
756 elif (
757 self.value in self.fold_through_function_to_wrapper().keys()
758 and check_constant_args(args, kwargs)
759 ):
760 value = self.value(
761 *[x.as_python_constant() for x in args],
762 **{k: v.as_python_constant() for k, v in kwargs.items()},
763 )
764 return self.fold_through_function_to_wrapper().get(self.value)(
765 value, mutable_local=MutableLocal()
766 )
767 elif (
768 self.value is itertools.product
769 and not kwargs
770 and all(arg.has_unpack_var_sequence(tx) for arg in args)
771 ):
772 seqs = [arg.unpack_var_sequence(tx) for arg in args]
773 items = []
774 for item in itertools.product(*seqs):
775 items.append(variables.TupleVariable(list(item)))
776 return variables.ListIteratorVariable(items, mutable_local=MutableLocal())
777 elif (
778 self.value is itertools.chain
779 and not kwargs
780 and all(arg.has_unpack_var_sequence(tx) for arg in args)
781 ):
782 seqs = [arg.unpack_var_sequence(tx) for arg in args]
783 items = []
784 for item in itertools.chain(*seqs):
785 items.append(item)
786 return variables.ListIteratorVariable(items, mutable_local=MutableLocal())
787 elif self.value is itertools.accumulate:
788 from .builtin import BuiltinVariable

Callers

nothing calls this directly

Calls 15

unimplementedFunction · 0.85
DefaultDictVariableClass · 0.85
MutableLocalClass · 0.85
check_constant_argsFunction · 0.85
listFunction · 0.85
BuiltinVariableClass · 0.85
SourcelessBuilderClass · 0.85
call_custom_dictMethod · 0.80
is_supported_argMethod · 0.80
groupbyMethod · 0.80
is_literalMethod · 0.80

Tested by

no test coverage detected