Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Fix LSTM - VecEnv compatibility #1427

Merged
merged 31 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
amend
  • Loading branch information
vmoens committed Sep 1, 2023
commit 71d1076791349543bf67334b46963b3059f70abe
32 changes: 18 additions & 14 deletions test/test_tensordictmodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
# LICENSE file in the root directory of this source tree.

import argparse
from mocking_classes import DiscreteActionVecMockEnv
from tensordict.nn import TensorDictSequential
from torchrl.modules import MLP, ProbabilisticActor

import pytest
import torch
from mocking_classes import DiscreteActionVecMockEnv
from tensordict import pad, TensorDict, unravel_key_list
from tensordict.nn import InteractionType, make_functional, TensorDictModule
from tensordict.nn import (
InteractionType,
make_functional,
TensorDictModule,
TensorDictSequential,
)
from torch import nn
from torchrl.data.tensor_specs import (
BoundedTensorSpec,
Expand All @@ -23,6 +27,7 @@
DecisionTransformerInferenceWrapper,
DTActor,
LSTMModule,
MLP,
NormalParamWrapper,
OnlineDTActor,
ProbabilisticActor,
Expand Down Expand Up @@ -1768,21 +1773,20 @@ def test_multi_consecutive(self, shape):
)

def test_lstm_parallel_env(self):
from torchrl.envs import ParallelEnv, TransformedEnv, InitTracker
from torchrl.envs import InitTracker, ParallelEnv, TransformedEnv

# tests that hidden states are carried over with parallel envs
lstm_module = LSTMModule(
input_size=7,
hidden_size=12,
num_layers=2,
in_key="observation",
out_key="features",
)
input_size=7,
hidden_size=12,
num_layers=2,
in_key="observation",
out_key="features",
)

def create_transformed_env():
primer = lstm_module.make_tensordict_primer()
env = DiscreteActionVecMockEnv(
categorical_action_encoding=True
)
env = DiscreteActionVecMockEnv(categorical_action_encoding=True)
env = TransformedEnv(env)
env.append_transform(InitTracker())
env.append_transform(primer)
Expand Down
2 changes: 1 addition & 1 deletion torchrl/modules/tensordict_module/rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Optional, Tuple

import torch
from tensordict import unravel_key_list, unravel_key, TensorDictBase
from tensordict import TensorDictBase, unravel_key_list

from tensordict.nn import TensorDictModuleBase as ModuleBase

Expand Down