Missed TensorFlow Dev Summit? Check out the video playlist. Watch recordings

tf_agents.replay_buffers.table.Table

View source on GitHub

A table that can store Tensors or nested Tensors.

tf_agents.replay_buffers.table.Table(
    tensor_spec, capacity, scope='Table'
)

Args:

  • tensor_spec: A nest of TensorSpec representing each value that can be stored in the table.
  • capacity: Maximum number of values the table can store.
  • scope: Variable scope for the Table.

Attributes:

  • name: Returns the name of this module as passed or determined in the ctor.

    NOTE: This is not the same as the self.name_scope.name which includes parent module names.

  • name_scope: Returns a tf.name_scope instance for this class.

  • slots

  • submodules: Sequence of all sub-modules.

    Submodules are modules which are properties of this module, or found as properties of modules which are properties of this module (and so on).

a = tf.Module()
b = tf.Module()
c = tf.Module()
a.b = b
b.c = c
assert list(a.submodules) == [b, c]
assert list(b.submodules) == [c]
assert list(c.submodules) == []
  • trainable_variables: Sequence of trainable variables owned by this module and its submodules.

Raises:

  • ValueError: If the names in tensor_spec are empty or not unique.

Methods

read

View source

read(
    rows, slots=None
)

Returns values for the given rows.

Args:

  • rows: A scalar/list/tensor of location(s) to read values from. If rows is a scalar, a single value is returned without a batch dimension. If rows is a list of integers or a rank-1 int Tensor a batch of values will be returned with each Tensor having an extra first dimension equal to the length of rows.
  • slots: Optional list/tuple/nest of slots to read from. If None, all tensors at the given rows are retrieved and the return value has the same structure as the tensor_spec. Otherwise, only tensors with names matching the slots are retrieved, and the return value has the same structure as slots.

Returns:

Values at given rows.

variables

View source

variables()

Sequence of variables owned by this module and its submodules.

Returns:

A sequence of variables for the current module (sorted by attribute name) followed by variables from all submodules recursively (breadth first).

with_name_scope

@classmethod
with_name_scope(
    cls, method
)

Decorator to automatically enter the module name scope.

class MyModule(tf.Module):
  @tf.Module.with_name_scope
  def __call__(self, x):
    if not hasattr(self, 'w'):
      self.w = tf.Variable(tf.random.normal([x.shape[1], 64]))
    return tf.matmul(x, self.w)

Using the above module would produce tf.Variables and tf.Tensors whose names included the module name:

mod = MyModule()
mod(tf.ones([8, 32]))
# ==> <tf.Tensor: ...>
mod.w
# ==> <tf.Variable ...'my_module/w:0'>

Args:

  • method: The method to wrap.

Returns:

The original method wrapped such that it enters the module's name scope.

write

View source

write(
    rows, values, slots=None
)

Returns ops for writing values at the given rows.

Args:

  • rows: A scalar/list/tensor of location(s) to write values at.
  • values: A nest of Tensors to write. If rows has more than one element, values can have an extra first dimension representing the batch size. Values must have the same structure as the tensor_spec of this class if slots is None, otherwise it must have the same structure as slots.
  • slots: Optional list/tuple/nest of slots to write. If None, all tensors in the table are updated. Otherwise, only tensors with names matching the slots are updated.

Returns:

Ops for writing values at rows.