def _get_handle_mover(graph, feeder, handle): """Return a move subgraph for this pair of feeder and handle.""" dtype = _get_handle_feeder(graph, feeder) if dtype is None: return None handle_device = TensorHandle._get_device_name(handle) if feeder.op.device == handle_device: return None # Now we know we have to move the tensor. graph_key = TensorHandle._get_mover_key(feeder, handle) result = graph._handle_movers.get(graph_key) if result is None: # Create mover if we haven't done it. holder, reader = _get_handle_reader(graph, handle, dtype) with graph.as_default(), graph.device(feeder.op.device): mover = gen_data_flow_ops._get_session_handle(reader) result = (holder, mover) graph._handle_movers[graph_key] = result return result
def _get_handle_mover(graph, feeder, handle): """Return a move subgraph for this pair of feeder and handle.""" dtype = _get_handle_feeder(graph, feeder) if dtype is None: return None handle_device = TensorHandle._get_device_name(handle) if feeder.op.device == handle_device: return None # Now we know we have to move the tensor. graph_key = TensorHandle._get_mover_key(feeder, handle) result = graph._handle_movers.get(graph_key) if result is None: # Create mover if we haven't done it. holder, reader = _get_handle_reader(graph, handle, dtype) with graph.as_default(), graph.device(feeder.op.device): mover = gen_data_flow_ops._get_session_handle(reader) # pylint: disable=protected-access result = (holder, mover) graph._handle_movers[graph_key] = result return result
def get_session_handle(data, name=None): """Return the handle of `data`. This is EXPERIMENTAL and subject to change. Keep `data` "in-place" in the runtime and create a handle that can be used to retrieve `data` in a subsequent run(). Combined with `get_session_tensor`, we can keep a tensor produced in one run call in place, and use it as the input in a future run call. Args: data: A tensor to be stored in the session. name: Optional name prefix for the return tensor. Returns: A scalar string tensor representing a unique handle for `data`. Raises: TypeError: if `data` is not a Tensor. Example: ```python c = tf.multiply(a, b) h = tf.get_session_handle(c) h = sess.run(h) p, a = tf.get_session_tensor(h.handle, tf.float32) b = tf.multiply(a, 10) c = sess.run(b, feed_dict={p: h.handle}) ``` """ if not isinstance(data, ops.Tensor): raise TypeError("`data` must be of type Tensor.") # Colocate this operation with data. with ops.colocate_with(data): return gen_data_flow_ops._get_session_handle(data, name=name)
def get_session_handle(data, name=None): """Return the handle of `data`. This is EXPERIMENTAL and subject to change. Keep `data` "in-place" in the runtime and create a handle that can be used to retrieve `data` in a subsequent run(). Combined with `get_session_tensor`, we can keep a tensor produced in one run call in place, and use it as the input in a future run call. Args: data: A tensor to be stored in the session. name: Optional name prefix for the return tensor. Returns: A scalar string tensor representing a unique handle for `data`. Raises: TypeError: if `data` is not a Tensor. Example: ```python c = tf.multiply(a, b) h = tf.get_session_handle(c) h = sess.run(h) p, a = tf.get_session_tensor(h.handle, tf.float32) b = tf.multiply(a, 10) c = sess.run(b, feed_dict={p: h.handle}) ``` """ if not isinstance(data, ops.Tensor): raise TypeError("`data` must be of type Tensor.") # Colocate this operation with data. with ops.colocate_with(data): return gen_data_flow_ops._get_session_handle(data, name=name) # pylint: disable=protected-access
def _get_handle_mover(graph, feeder, handle): """Return a move subgraph for this pair of feeder and handle.""" dtype = _get_handle_feeder(graph, feeder) if dtype is None: return None handle_device = TensorHandle._get_device_name(handle) if not feeder.op.device: feeder.op._set_device(handle_device) feeder.consumers()[0]._set_device(handle_device) return None if feeder.op.device == handle_device: return None # Now we know we have to move the tensor. graph_key = TensorHandle._get_mover_key(feeder, handle) result = graph._handle_movers.get(graph_key) if result is None: # Create mover if we haven't done it. holder, reader = _get_handle_reader(graph, handle, dtype) with ops.device(feeder.op.device): mover = gen_data_flow_ops._get_session_handle(reader) result = (holder, mover) graph._handle_movers[graph_key] = result return result