<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/experimental/auto_batching/instructions.py#L243-L283) |

A token indicating how to allocate memory for an autobatched variable.

#### View aliases


**Main aliases**

[`tfp.experimental.auto_batching.frontend.instructions.VariableAllocation`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/auto_batching/instructions/VariableAllocation), [`tfp.experimental.auto_batching.frontend.st.inst.VariableAllocation`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/auto_batching/instructions/VariableAllocation), [`tfp.experimental.auto_batching.frontend.stack.inst.VariableAllocation`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/auto_batching/instructions/VariableAllocation), [`tfp.experimental.auto_batching.stack_optimization.inst.VariableAllocation`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/auto_batching/instructions/VariableAllocation), [`tfp.experimental.auto_batching.stackless.inst.VariableAllocation`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/auto_batching/instructions/VariableAllocation)

<br />

    tfp.experimental.auto_batching.instructions.VariableAllocation(
        name
    )

In general, a variable holding data with a longer or more complex lifetime
will need a more expensive storage strategy.

Specifically, the four variable allocation strategies are:

- `NULL`: Holds nothing. Drops writes, raises on reads. Useful for representing dummy variables that the user program never reads.
- `TEMPORARY`: Holds one value per thread, but not across basic block boundaries. Only usable for temporaries that live in a single basic block, and thus never experience joins (or vm execution loop crossings). For such a variable, `push` just overwrites the whole Tensor; `pop` nulls the whole Tensor out.
- `REGISTER`: Holds one value per thread, with no associated stack. Useful for representing temporaries that do not cross (recursive) function calls, but do span multiple basic blocks. For such a variable, `push` amounts to a `where`, with an optional runtime safety check for overwriting a defined value.
- `FULL`: Holds a complete stack for each thread. Used as a last resort, when a stack is unavoidable.

The difference between `register` and `temporary` is that `register` is a
`[batch_size] + event_shape` Tensor in the loop state of the toplevel
`while_loop`, whereas `temporary` is represented as an empty tuple in the loop
state, and only holds a Tensor during the execution of the
`virtual_machine._run_block` call that uses it. Consequently, `register`
updating involves a `where`, but writing to a `temporary` produces 0 TF ops.
Also, in the (envisioned) gather-scatter batching mode, the `temporary` Tensor
will automatically only hold data for the live threads, whereas reading and
writing a `register` will still require the gathers and scatters.

<br />

<br />

<br />

| ## Class Variables ||
|---|---|
| FULL | Instance of [`tfp.experimental.auto_batching.instructions.VariableAllocation`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/auto_batching/instructions/VariableAllocation) |
| NULL | Instance of [`tfp.experimental.auto_batching.instructions.VariableAllocation`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/auto_batching/instructions/VariableAllocation) |
| REGISTER | Instance of [`tfp.experimental.auto_batching.instructions.VariableAllocation`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/auto_batching/instructions/VariableAllocation) |
| TEMPORARY | Instance of [`tfp.experimental.auto_batching.instructions.VariableAllocation`](https://www.tensorflow.org/probability/api_docs/python/tfp/experimental/auto_batching/instructions/VariableAllocation) |

<br />