tfp.experimental.auto_batching.instructions.VariableAllocation
Stay organized with collections
Save and categorize content based on your preferences.
A token indicating how to allocate memory for an autobatched variable.
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.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-11-21 UTC.
[null,null,["Last updated 2023-11-21 UTC."],[],[],null,["# tfp.experimental.auto_batching.instructions.VariableAllocation\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/experimental/auto_batching/instructions.py#L243-L283) |\n\nA token indicating how to allocate memory for an autobatched variable.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`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)\n\n\u003cbr /\u003e\n\n tfp.experimental.auto_batching.instructions.VariableAllocation(\n name\n )\n\nIn general, a variable holding data with a longer or more complex lifetime\nwill need a more expensive storage strategy.\n\nSpecifically, the four variable allocation strategies are:\n\n- `NULL`: Holds nothing. Drops writes, raises on reads. Useful for representing dummy variables that the user program never reads.\n- `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.\n- `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.\n- `FULL`: Holds a complete stack for each thread. Used as a last resort, when a stack is unavoidable.\n\nThe difference between `register` and `temporary` is that `register` is a\n`[batch_size] + event_shape` Tensor in the loop state of the toplevel\n`while_loop`, whereas `temporary` is represented as an empty tuple in the loop\nstate, and only holds a Tensor during the execution of the\n`virtual_machine._run_block` call that uses it. Consequently, `register`\nupdating involves a `where`, but writing to a `temporary` produces 0 TF ops.\nAlso, in the (envisioned) gather-scatter batching mode, the `temporary` Tensor\nwill automatically only hold data for the live threads, whereas reading and\nwriting a `register` will still require the gathers and scatters.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Class Variables --------------- ||\n|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| FULL | Instance of [`tfp.experimental.auto_batching.instructions.VariableAllocation`](../../../../tfp/experimental/auto_batching/instructions/VariableAllocation) |\n| NULL | Instance of [`tfp.experimental.auto_batching.instructions.VariableAllocation`](../../../../tfp/experimental/auto_batching/instructions/VariableAllocation) |\n| REGISTER | Instance of [`tfp.experimental.auto_batching.instructions.VariableAllocation`](../../../../tfp/experimental/auto_batching/instructions/VariableAllocation) |\n| TEMPORARY | Instance of [`tfp.experimental.auto_batching.instructions.VariableAllocation`](../../../../tfp/experimental/auto_batching/instructions/VariableAllocation) |\n\n\u003cbr /\u003e"]]