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

Method AddEagerInferredAttrs

tensorflow/python/framework/python_op_gen.cc:800–876  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

798}
799
800void GenEagerPythonOp::AddEagerInferredAttrs(const string& indentation) {
801 // Figure out values for inferred attrs, and cast to eager tensors.
802 for (int i = 0; i < op_def_.attr_size(); ++i) {
803 const auto& attr(op_def_.attr(i));
804 const auto& api_def_attr(api_def_.attr(i));
805 auto arg_list = attr_to_args_.find(attr.name());
806 if (arg_list != attr_to_args_.end()) {
807 if (attr.type() == "type") {
808 std::vector<string> output_sizes;
809 const string flattened =
810 FlattenInputs(&arg_list->second, &output_sizes);
811 string conversion = strings::StrCat("_execute.args_to_matching_eager(",
812 flattened, ", _ctx");
813 if (attr.has_default_value()) {
814 strings::StrAppend(
815 &conversion, ", ",
816 python_op_gen_internal::AttrValueToPython(
817 attr.type(), api_def_attr.default_value(), "_dtypes."));
818 }
819 strings::StrAppend(&conversion, ")");
820 const string var_name = AttrVarName(attr.name(), &attr_expressions_);
821 if (output_sizes.size() == 1) {
822 // Avoid creating a temporary variable in the case where
823 // we can easily assign to the right value directly.
824 const string inputs_var =
825 param_names_[arg_list->second.front()].GetRenameTo();
826 if (output_sizes.front().empty()) {
827 strings::StrAppend(&result_, indentation, var_name, ", (",
828 inputs_var, ",) = ", conversion, "\n");
829 } else {
830 strings::StrAppend(&result_, indentation, var_name, ", ",
831 inputs_var, " = ", conversion, "\n");
832 }
833 } else {
834 const string inputs_var = strings::StrCat("_inputs_", attr.name());
835 strings::StrAppend(&result_, indentation, var_name, ", ", inputs_var,
836 " = ", conversion, "\n");
837 // Convert from a flat list of eager tensors back to the
838 // parameter variables.
839 Unflatten(indentation, output_sizes, inputs_var, &result_);
840 std::vector<string> p;
841 for (int j : arg_list->second) {
842 p.emplace_back(param_names_[j].GetRenameTo());
843 }
844 strings::StrAppend(&result_, indentation, VectorToTuple(p), " = ",
845 inputs_var, "\n");
846 }
847 } else if (attr.type() == "list(type)") {
848 // NOTE: We ignore default values for these attrs, since it is
849 // unclear how you would use it, and the one use case is
850 // parse_single_sequence_example which only needs it for
851 // backwards compatibility.
852 const string var_name = AttrVarName(attr.name(), &attr_expressions_);
853 string inputs_var;
854 string conversion;
855 if (arg_list->second.size() > 1) {
856 // If you have more than one list(tensor) argument, their types
857 // have to match.

Callers

nothing calls this directly

Calls 15

AttrValueToPythonFunction · 0.85
AttrVarNameFunction · 0.85
UnflattenFunction · 0.85
VectorToTupleFunction · 0.85
has_default_valueMethod · 0.80
GetRenameToMethod · 0.80
nameMethod · 0.65
typeMethod · 0.65
StrCatFunction · 0.50
StrAppendFunction · 0.50
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected