message: Fetch OpDefs from C API instead of using python op registry in ops.py.
diff: @@ -1657,7 +1657,7 @@ class Operation(object):
  self._c_op = c_op
  elif self._graph._c_graph: # pylint: disable=protected-access
  if op_def is None:
  - op_def = self._graph._registered_ops[node_def.op]
  + op_def = self._graph._get_op_def(node_def.op)
  # TODO(skyewm): op_def_library.apply_op() flattens the incoming inputs.
  # Refactor so we don't have to do this here.
  grouped_inputs = self._reconstruct_sequence_inputs(
  @@ -2164,16 +2164,7 @@ class Operation(object):
  """
  # pylint: enable=line-too-long
  if self._c_op:
  - with c_api_util.tf_buffer() as buf:
  - with errors.raise_exception_on_not_ok_status() as status:
  - # pylint: disable=protected-access
  - c_api.TF_GraphGetOpDef(self._graph._c_graph,
  - compat.as_bytes(self.type), buf, status)
  - # pylint: enable=protected-access
  - data = c_api.TF_GetBuffer(buf)
  - op_def = op_def_pb2.OpDef()
  - op_def.ParseFromString(compat.as_bytes(data))
  - return op_def
  + return self._graph._get_op_def(self.type)
  else:
  return self._op_def_val
  @@ -3377,8 +3368,8 @@ class Graph(object):
  # (2) "is_stateful" is set in OpDef
  # (3) "container" attribute is in OpDef
  # (4) "container" attribute is None
  - if (self._container and op.type in self._registered_ops and
  - self._registered_ops[op.type].is_stateful):
  + # TODO(skyewm): remove op.op_def check when _USE_C_API is removed.
  + if self._container and op.op_def and op.op_def.is_stateful:
  try:
  container_attr = op.get_attr("container")
  except ValueError:
  @@ -3658,6 +3649,22 @@ class Graph(object):
  def _last_id(self):
  return self._next_id_counter
  + def _get_op_def(self, type):
  + """Returns the `OpDef` proto for `type`. `type` is a string."""
  + if self._c_graph:
  + with c_api_util.tf_buffer() as buf:
  + with errors.raise_exception_on_not_ok_status() as status:
  + # pylint: disable=protected-access
  + c_api.TF_GraphGetOpDef(self._c_graph,
  + compat.as_bytes(type), buf, status)
  + # pylint: enable=protected-access
  + data = c_api.TF_GetBuffer(buf)
  + op_def = op_def_pb2.OpDef()
  + op_def.ParseFromString(compat.as_bytes(data))
  + return op_def
  + else:
  + return self._registered_ops[type]
  +
  def as_default(self):
  """Returns a context manager that makes this `Graph` the default graph.
  