Skip to content

Commit 6d1a1b3

Browse files
author
Vincent Moens
committed
[Doc] Better doc for inverse transform semantic
ghstack-source-id: 444ad87 Pull Request resolved: #2459
1 parent c94d07f commit 6d1a1b3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
251 KB
Loading

docs/source/reference/envs.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,9 @@ Since each transform uses a ``"in_keys"``/``"out_keys"`` set of keyword argument
722722
also easy to root the transform graph to each component of the observation data (e.g.
723723
pixels or states etc).
724724

725+
Forward and inverse transforms
726+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
727+
725728
Transforms also have an ``inv`` method that is called before
726729
the action is applied in reverse order over the composed transform chain:
727730
this allows to apply transforms to data in the environment before the action is taken
@@ -733,6 +736,20 @@ in the environment. The keys to be included in this inverse transform are passed
733736
734737
>>> env.append_transform(DoubleToFloat(in_keys_inv=["action"])) # will map the action from float32 to float64 before calling the base_env.step
735738
739+
The way ``in_keys`` relates to ``in_keys_inv`` can be understood by considering the base environment as the "inner" part
740+
of the transform. In constrast, the user inputs and outputs to and from the transform are to be considered as the
741+
outside world. The following figure shows what this means in practice for the :class:`~torchrl.envs.RenameTransform`
742+
class: the input ``TensorDict`` of the ``step`` function must have the ``out_keys_inv`` listed in its entries as they
743+
are part of the outside world. The transform changes these names to make them match the names of the inner, base
744+
environment using the ``in_keys_inv``. The inverse process is executed with the output tensordict, where the ``in_keys``
745+
are mapped to the corresponding ``out_keys``.
746+
747+
.. figure:: /_static/img/rename_transform.png
748+
749+
Rename transform logic
750+
751+
752+
736753
Cloning transforms
737754
~~~~~~~~~~~~~~~~~~
738755

0 commit comments

Comments
 (0)