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

Method HandleGraphMode

tensorflow/python/framework/python_op_gen.cc:363–411  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361}
362
363void GenEagerPythonOp::HandleGraphMode(const string& function_setup) {
364 strings::StrAppend(&result_, " # Add nodes to the TensorFlow graph.\n");
365 strings::StrAppend(&result_, function_setup);
366 if (api_def_.visibility() == ApiDef::VISIBLE) {
367 strings::StrAppend(&result_, " try:\n ");
368 }
369 strings::StrAppend(&result_, " _, _, _op = _op_def_lib._apply_op_helper(\n");
370 AddBodyNoReturn(strings::StrCat(" \"", op_def_.name(), "\", "));
371 AddDispatch(" ");
372
373 if (num_outs_ > 0) {
374 strings::StrAppend(&result_, " _result = _op.outputs[:]\n");
375 // Special case handling for stateful op with single list output
376 // that might be empty.
377 if (num_outs_ == 1 && op_def_.is_stateful() &&
378 (!op_def_.output_arg(0).number_attr().empty() ||
379 !op_def_.output_arg(0).type_list_attr().empty())) {
380 // TODO(josh11b): Can skip this if the number_attr/type_list_attr has
381 // a constraint indicating that this can never be empty.
382 strings::StrAppend(&result_,
383 " if not _result:\n"
384 " return _op\n");
385 }
386 strings::StrAppend(&result_, " _inputs_flat = _op.inputs\n");
387
388 // Compute graph-mode attrs.
389 if (op_def_.attr_size() > 0) {
390 string attr_values;
391 for (int i = 0; i < op_def_.attr_size(); ++i) {
392 if (i > 0) strings::StrAppend(&attr_values, ", ");
393 const auto& attr_name(op_def_.attr(i).name());
394 if (op_def_.attr(i).type() == "type") {
395 strings::StrAppend(&attr_values, "\"", attr_name,
396 "\", _op._get_attr_type(\"", attr_name, "\")");
397 } else {
398 strings::StrAppend(&attr_values, "\"", attr_name,
399 "\", _op.get_attr(\"", attr_name, "\")");
400 }
401 }
402 strings::StrAppend(&attr_values, ")");
403 strings::StrAppend(
404 &result_, WordWrap(" _attrs = (", attr_values, kRightMargin), "\n");
405 } else {
406 strings::StrAppend(&result_, " _attrs = None\n");
407 }
408 } else {
409 strings::StrAppend(&result_, " return _op\n");
410 }
411}
412
413string GenEagerPythonOp::GetEagerNotAllowedError() {
414 bool eager_allowed = true;

Callers

nothing calls this directly

Calls 8

WordWrapFunction · 0.85
attrMethod · 0.80
nameMethod · 0.65
typeMethod · 0.65
StrAppendFunction · 0.50
StrCatFunction · 0.50
is_statefulMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected