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

Fix TypeError in pad_sequence for torch>=1.9.0 #163

Merged
merged 2 commits into from
Mar 14, 2022
Merged
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
8 changes: 7 additions & 1 deletion pfrl/utils/recurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ def pack_one_step_batch_as_sequences(xs):
if isinstance(xs, tuple):
return tuple(pack_one_step_batch_as_sequences(x) for x in xs)
else:
return nn.utils.rnn.pack_sequence(xs[:, None])
assert isinstance(xs, torch.Tensor)
# xs: (B, ...)-shaped tensor
# seqs: B-sized list of (1, ...)-shaped tensors
seqs = [x for x in xs.split(1)]
assert len(xs) == len(seqs)
assert (1,) + xs.shape[1:] == seqs[0].shape
return nn.utils.rnn.pack_sequence(seqs)


def unpack_sequences_as_one_step_batch(pack):
Expand Down