DTActor¶
- class torchrl.modules.DTActor(state_dim: int, action_dim: int, transformer_config: Optional[Union[Dict, DTConfig]] = None, device: Optional[Union[device, str, int]] = None)[source]¶
Decision Transformer Actor class.
Actor class for the Decision Transformer to output deterministic action as presented in “Decision Transformer” <https://arxiv.org/abs/2202.05607.pdf>. Returns the deterministic actions.
- Parameters:
state_dim (int) – state dimension.
action_dim (int) – action dimension.
transformer_config (Dict or
DecisionTransformer.DTConfig
, optional) – config for the GPT2 transformer. Defaults todefault_config()
.device (torch.device, optional) – device to use. Defaults to None.
Examples
>>> model = DTActor(state_dim=4, action_dim=2, ... transformer_config=DTActor.default_config()) >>> observation = torch.randn(32, 10, 4) >>> action = torch.randn(32, 10, 2) >>> return_to_go = torch.randn(32, 10, 1) >>> output = model(observation, action, return_to_go) >>> output.shape torch.Size([32, 10, 2])
- forward(observation: Tensor, action: Tensor, return_to_go: Tensor) Tensor [source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.