MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / InstantiateFunction

Function InstantiateFunction

tensorflow/core/framework/function.cc:702–784  ·  view source on GitHub ↗

TODO(shikharagarwal): Transmit original node names correctly in file.

Source from the content-addressed store, hash-verified

700
701// TODO(shikharagarwal): Transmit original node names correctly in file.
702Status InstantiateFunction(const FunctionDef& fdef, AttrSlice attr_values,
703 GetFunctionSignature get_function,
704 InstantiationResult* result) {
705 VLOG(4) << "Instantiation Function: " << Print(fdef);
706
707 const OpDef& sig = fdef.signature();
708 TF_RETURN_IF_ERROR(ValidateSignatureWithAttrs(sig, attr_values));
709
710 bool ints_on_device =
711 fdef.attr().count(FunctionLibraryDefinition::kIntsOnDeviceAttr) != 0 &&
712 fdef.attr().at(FunctionLibraryDefinition::kIntsOnDeviceAttr).b();
713
714 FunctionInstantiationHelper helper(get_function, result);
715 Status s;
716 for (const OpDef::ArgDef& arg_def : sig.input_arg()) {
717 s = helper.BuildInputArgIndex(arg_def, attr_values, ints_on_device);
718 if (!s.ok()) {
719 errors::AppendToMessage(&s, "In ", Print(arg_def));
720 return s;
721 }
722 }
723
724 auto substitute = [attr_values](StringPiece name, AttrValue* val) {
725 if (const AttrValue* v = attr_values.Find(name)) {
726 *val = *v;
727 return true;
728 }
729 return false;
730 };
731
732 // Makes a copy of all attrs in fdef and substitutes placeholders.
733 // After this step, every attr is bound to a concrete value.
734 std::vector<AttrValueMap> node_attrs;
735 node_attrs.resize(fdef.node_def_size());
736 for (int i = 0; i < fdef.node_def_size(); ++i) {
737 for (auto attr : fdef.node_def(i).attr()) {
738 if (!SubstitutePlaceholders(substitute, &attr.second)) {
739 return errors::InvalidArgument("Failed to bind all placeholders in ",
740 SummarizeAttrValue(attr.second));
741 }
742 if (!node_attrs[i].insert(attr).second) {
743 return errors::Internal("Somehow duplicated: ", attr.first);
744 }
745 }
746 TF_RETURN_IF_ERROR(
747 AddDefaultAttrs(fdef.node_def(i).op(), get_function, &node_attrs[i]));
748 }
749
750 for (int i = 0; i < fdef.node_def_size(); ++i) {
751 s = helper.BuildNodeOutputIndex(fdef.node_def(i), AttrSlice(&node_attrs[i]),
752 result->nodes.size() + i);
753 if (!s.ok()) {
754 errors::AppendToMessage(&s, "In ",
755 FormatNodeDefForError(fdef.node_def(i)));
756 return s;
757 }
758 }
759 // Emits one node for each fdef.node_def.

Callers 7

TESTFunction · 0.85
CreateMethod · 0.85
OptimizeFunction · 0.85
FunctionDefToBodyHelperFunction · 0.85
RunFunctionMethod · 0.85

Calls 15

AppendToMessageFunction · 0.85
SubstitutePlaceholdersFunction · 0.85
InvalidArgumentFunction · 0.85
SummarizeAttrValueFunction · 0.85
InternalFunction · 0.85
AddDefaultAttrsFunction · 0.85
AttrSliceClass · 0.85
FormatNodeDefForErrorFunction · 0.85
signatureMethod · 0.80
attrMethod · 0.80
BuildInputArgIndexMethod · 0.80

Tested by 5

TESTFunction · 0.68
CreateMethod · 0.68
OptimizeFunction · 0.68
RunFunctionMethod · 0.68