Exemple #1
0
    def _add_op_and_parents(self, op):
        # pylint: disable=protected-access
        op_def = graph_to_function_def._get_op_def(op)
        # pylint: enable=protected-access
        if op_def.is_stateful and op not in self._whitelisted_stateful_ops:
            raise ValueError(
                "Cannot capture a stateful node (name:%s, type:%s) "
                "by value." % (op.name, op.type))
        elif op.type in ("Placeholder", "PlaceholderV2"):
            raise ValueError("Cannot capture a placeholder (name:%s, type:%s) "
                             "by value." % (op.name, op.type))

        captured_inputs = [self._add_tensor_and_parents(x) for x in op.inputs]

        captured_op = self.create_op(op.type,
                                     captured_inputs,
                                     [o.dtype for o in op.outputs],
                                     name=op.name,
                                     attrs=op.node_def.attr,
                                     op_def=op_def)

        for t, captured_t in zip(op.outputs, captured_op.outputs):
            self._captured[t] = captured_t

        return captured_op
Exemple #2
0
  def _add_op_and_parents(self, op):
    op_def = graph_to_function_def._get_op_def(op)
    if op_def.is_stateful:
      raise ValueError("Cannot capture a stateful node (name:%s, type:%s) "
                       "by value." % (op.name, op.type))
    elif op.type in ("Placeholder", "PlaceholderV2"):
      raise ValueError("Cannot capture a placeholder (name:%s, type:%s) "
                       "by value." % (op.name, op.type))

    captured_inputs = [self._add_tensor_and_parents(x) for x in op.inputs]

    captured_op = self.create_op(op.type, captured_inputs,
                                 [o.dtype for o in op.outputs],
                                 name=op.name, attrs=op.node_def.attr,
                                 op_def=op_def)

    for t, captured_t in zip(op.outputs, captured_op.outputs):
      self._captured[t] = captured_t

    return captured_op
  def _add_op_and_parents(self, op):
    # pylint: disable=protected-access
    op_def = graph_to_function_def._get_op_def(op)
    if op._is_stateful and op not in self._allowlisted_stateful_ops:
      raise ValueError(f"Cannot capture a stateful node (name:{op.name}, "
                       f"type:{op.type}) by value.")
    elif op.type in ("Placeholder", "PlaceholderV2"):
      raise ValueError(f"Cannot capture a placeholder (name:{op.name}, "
                       f"type:{op.type}) by value.")
    # pylint: enable=protected-access

    captured_inputs = [self._add_tensor_and_parents(x) for x in op.inputs]

    captured_op = self._create_op_internal(
        op.type,
        captured_inputs, [o.dtype for o in op.outputs],
        name=op.name,
        attrs=op.node_def.attr,
        op_def=op_def)

    for t, captured_t in zip(op.outputs, captured_op.outputs):
      self._captured[t.ref()] = captured_t

    return captured_op