Given batched, batch-major inputs, DynamicUnroll unrolls
an RNN using cell; at each time step it feeds a frame of inputs as input
to cell.call().
If at least one tensor in inputs has rank 3 or above (shaped
[batch_size, n, ...] where n is the number of time steps),
the RNN will run for exactly n steps.
If n == 1 is known statically, then only a single step is executed.
This is done via a static unroll without using a tf.while_loop.
If all of the tensors in inputs have rank at most 2 (i.e., shaped
[batch_size] or [batch_size, d], then it is assumed that a single step
is being taken (i.e. n = 1) and the outputs will also not have a time
dimension in their output.
Args
cell
A tf.nn.rnn_cell.RNNCell or Keras RNNCell (e.g. LSTMCell)
whose call() method has the signature call(input, state, ...). Each
tensor in the tuple is shaped [batch_size, ...].
parallel_iterations
Parallel iterations to pass to tf.while_loop. The
default value is a good trades off between memory use and performance.
See documentation of tf.while_loop for more details.
swap_memory
Python bool. Whether to swap memory from GPU to CPU when
storing activations for backprop. This may sometimes have a negligible
performance impact, but can improve memory usage. See documentation of
tf.while_loop for more details.
**kwargs
Additional layer arguments, such as dtype and name.
Raises
TypeError
if cell lacks get_initial_state, output_size, or
state_size property.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf_agents.keras_layers.DynamicUnroll\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/keras_layers/dynamic_unroll_layer.py#L111-L350) |\n\nProcess a history of sequences that are concatenated without padding.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf_agents.keras_layers.dynamic_unroll_layer.DynamicUnroll`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/keras_layers/DynamicUnroll)\n\n\u003cbr /\u003e\n\n tf_agents.keras_layers.DynamicUnroll(\n cell, parallel_iterations=20, swap_memory=None, **kwargs\n )\n\nGiven batched, batch-major `inputs`, `DynamicUnroll` unrolls\nan RNN using `cell`; at each time step it feeds a frame of `inputs` as input\nto `cell.call()`.\n\nIf at least one tensor in `inputs` has rank 3 or above (shaped\n`[batch_size, n, ...]` where `n` is the number of time steps),\nthe RNN will run for exactly `n` steps.\n\nIf `n == 1` is known statically, then only a single step is executed.\nThis is done via a static unroll without using a [`tf.while_loop`](https://www.tensorflow.org/api_docs/python/tf/while_loop).\n\nIf all of the tensors in `inputs` have rank at most `2` (i.e., shaped\n`[batch_size]` or `[batch_size, d]`, then it is assumed that a single step\nis being taken (i.e. `n = 1`) and the outputs will also not have a time\ndimension in their output.\n| **Note:** The `call` method optionally accepts `reset_mask` argument, which allows for state resets partway through a batch, at the cost of more computation.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `cell` | A `tf.nn.rnn_cell.RNNCell` or Keras `RNNCell` (e.g. `LSTMCell`) whose `call()` method has the signature `call(input, state, ...)`. Each tensor in the tuple is shaped `[batch_size, ...]`. |\n| `parallel_iterations` | Parallel iterations to pass to [`tf.while_loop`](https://www.tensorflow.org/api_docs/python/tf/while_loop). The default value is a good trades off between memory use and performance. See documentation of [`tf.while_loop`](https://www.tensorflow.org/api_docs/python/tf/while_loop) for more details. |\n| `swap_memory` | Python bool. Whether to swap memory from GPU to CPU when storing activations for backprop. This may sometimes have a negligible performance impact, but can improve memory usage. See documentation of [`tf.while_loop`](https://www.tensorflow.org/api_docs/python/tf/while_loop) for more details. |\n| `**kwargs` | Additional layer arguments, such as `dtype` and `name`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|-------------------------------------------------------------------------------|\n| `TypeError` | if `cell` lacks `get_initial_state`, `output_size`, or `state_size` property. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|--------------|---------------|\n| `state_size` | \u003cbr /\u003e \u003cbr /\u003e |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `get_initial_state`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/keras_layers/dynamic_unroll_layer.py#L220-L226) \n\n get_initial_state(\n inputs=None, batch_size=None, dtype=None\n )"]]