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

Method Create

tensorflow/core/framework/function.cc:1670–1717  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

1668
1669/* static */
1670FunctionDef FunctionDefHelper::Create(
1671 const string& function_name, gtl::ArraySlice<string> in_def,
1672 gtl::ArraySlice<string> out_def, gtl::ArraySlice<string> attr_def,
1673 gtl::ArraySlice<Node> node_def,
1674 gtl::ArraySlice<std::pair<string, string>> ret_def,
1675 gtl::ArraySlice<std::pair<string, string>> control_ret_def) {
1676 FunctionDef fdef;
1677
1678 // Signature
1679 OpDefBuilder b(function_name);
1680 for (const auto& i : in_def) b.Input(i);
1681 for (const auto& o : out_def) b.Output(o);
1682 for (const auto& a : attr_def) b.Attr(a);
1683 for (const auto& c : control_ret_def) b.ControlOutput(c.first);
1684
1685 OpRegistrationData op_reg_data;
1686 TF_CHECK_OK(b.Finalize(&op_reg_data));
1687 fdef.mutable_signature()->Swap(&op_reg_data.op_def);
1688
1689 // Function body
1690 for (const auto& n : node_def) {
1691 *(fdef.add_node_def()) = n.ToNodeDef();
1692 }
1693
1694 // Returns
1695 for (const auto& r : ret_def) {
1696 fdef.mutable_ret()->insert({r.first, r.second});
1697 }
1698
1699 // Control returns
1700 for (const auto& cr : control_ret_def) {
1701 fdef.mutable_control_ret()->insert({cr.first, cr.second});
1702 }
1703
1704 auto* op_def_registry = OpRegistry::Global();
1705 // Check if any op is stateful.
1706 for (const auto& n : node_def) {
1707 const OpDef* op_def = nullptr;
1708 auto status = op_def_registry->LookUpOpDef(n.op, &op_def);
1709 // Lookup can fail if e.g. we are calling a function that was not yet
1710 // defined. If it happens, conservatively assume the op is stateful.
1711 if (!status.ok() || op_def->is_stateful()) {
1712 fdef.mutable_signature()->set_is_stateful(true);
1713 }
1714 }
1715
1716 return fdef;
1717}
1718
1719/* static */
1720FunctionDef FunctionDefHelper::Create(

Callers 15

SetUpMethod · 0.45
PackGradFunction · 0.45
UnpackGradFunction · 0.45
ConcatGradFunction · 0.45
ConcatGradV2Function · 0.45
SplitGradFunction · 0.45
SplitVGradFunction · 0.45
ReshapeGradFunction · 0.45
ExpandDimsGradFunction · 0.45
SqueezeGradFunction · 0.45
TransposeGradFunction · 0.45
ReverseGradFunction · 0.45

Calls 11

ToNodeDefMethod · 0.80
LookUpOpDefMethod · 0.80
CreateFunction · 0.50
InputMethod · 0.45
OutputMethod · 0.45
AttrMethod · 0.45
FinalizeMethod · 0.45
SwapMethod · 0.45
insertMethod · 0.45
okMethod · 0.45
is_statefulMethod · 0.45

Tested by 15

SetUpMethod · 0.36
PackGradFunction · 0.36
UnpackGradFunction · 0.36
ConcatGradFunction · 0.36
ConcatGradV2Function · 0.36
SplitGradFunction · 0.36
SplitVGradFunction · 0.36
ReshapeGradFunction · 0.36
ExpandDimsGradFunction · 0.36
SqueezeGradFunction · 0.36
TransposeGradFunction · 0.36
ReverseGradFunction · 0.36