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

Method container

tensorflow/python/framework/ops.py:4459–4508  ·  view source on GitHub ↗

Returns a context manager that specifies the resource container to use. Stateful operations, such as variables and queues, can maintain their states on devices so that they can be shared by multiple processes. A resource container is a string name under which these stateful operatio

(self, container_name)

Source from the content-addressed store, hash-verified

4457 # pylint: disable=g-doc-return-or-yield
4458 @tf_contextlib.contextmanager
4459 def container(self, container_name):
4460 """Returns a context manager that specifies the resource container to use.
4461
4462 Stateful operations, such as variables and queues, can maintain their
4463 states on devices so that they can be shared by multiple processes.
4464 A resource container is a string name under which these stateful
4465 operations are tracked. These resources can be released or cleared
4466 with `tf.Session.reset()`.
4467
4468 For example:
4469
4470 ```python
4471 with g.container('experiment0'):
4472 # All stateful Operations constructed in this context will be placed
4473 # in resource container "experiment0".
4474 v1 = tf.Variable([1.0])
4475 v2 = tf.Variable([2.0])
4476 with g.container("experiment1"):
4477 # All stateful Operations constructed in this context will be
4478 # placed in resource container "experiment1".
4479 v3 = tf.Variable([3.0])
4480 q1 = tf.queue.FIFOQueue(10, tf.float32)
4481 # All stateful Operations constructed in this context will be
4482 # be created in the "experiment0".
4483 v4 = tf.Variable([4.0])
4484 q1 = tf.queue.FIFOQueue(20, tf.float32)
4485 with g.container(""):
4486 # All stateful Operations constructed in this context will be
4487 # be placed in the default resource container.
4488 v5 = tf.Variable([5.0])
4489 q3 = tf.queue.FIFOQueue(30, tf.float32)
4490
4491 # Resets container "experiment0", after which the state of v1, v2, v4, q1
4492 # will become undefined (such as uninitialized).
4493 tf.Session.reset(target, ["experiment0"])
4494 ```
4495
4496 Args:
4497 container_name: container name string.
4498
4499 Returns:
4500 A context manager for defining resource containers for stateful ops,
4501 yields the container name.
4502 """
4503 original_container = self._container
4504 self._container = container_name
4505 try:
4506 yield self._container
4507 finally:
4508 self._container = original_container
4509
4510 # pylint: enable=g-doc-return-or-yield
4511

Callers 15

~BigtableClientOpMethod · 0.45
LOCKS_EXCLUDEDMethod · 0.45
~BigtableTableOpMethod · 0.45
LOCKS_EXCLUDEDMethod · 0.45
~BigtableTestClientOpMethod · 0.45
LOCKS_EXCLUDEDMethod · 0.45
containerFunction · 0.45
testResetFailsMethod · 0.45
GetVarHandleStringIdFunction · 0.45

Calls

no outgoing calls

Tested by 6

~BigtableTestClientOpMethod · 0.36
LOCKS_EXCLUDEDMethod · 0.36
testResetFailsMethod · 0.36
operator==Function · 0.36