Skip to content

Commit

Permalink
Fix a bug where pack_padded_sequence would take a cuda tensor instead…
Browse files Browse the repository at this point in the history
… of a CPU one (#81)

* Fix a bug where pack_padded_sequence would take a cuda tensor instead of a CPU one

* Release 0.3.7c
  • Loading branch information
PonteIneptique authored Feb 17, 2021
1 parent 3638bf1 commit 0ca4311
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pie/models/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def forward(self, char, nchars, nwords):
char, nchars = char[:, sort], nchars[sort]
if isinstance(self.rnn, nn.RNNBase):
outs, emb = self.rnn(
nn.utils.rnn.pack_padded_sequence(char, nchars), hidden)
nn.utils.rnn.pack_padded_sequence(char, nchars.cpu()), hidden)
outs, _ = nn.utils.rnn.pad_packed_sequence(outs)
if isinstance(emb, tuple):
emb, _ = emb
Expand Down
4 changes: 2 additions & 2 deletions pie/models/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ def forward(self, inp, lengths, hidden=None, only_last=False, return_hidden=Fals

_, sort = torch.sort(lengths, descending=True)
_, unsort = sort.sort()
inp = nn.utils.rnn.pack_padded_sequence(inp[:, sort], lengths[sort])
inp = nn.utils.rnn.pack_padded_sequence(inp[:, sort], lengths[sort].cpu())
outs, hiddens = [], []

for layer, rnn in enumerate(self.rnn):
# apply dropout only in between layers (not on the output)
if layer > 0:
inp, lengths = nn.utils.rnn.pad_packed_sequence(inp)
inp = torch_utils.sequential_dropout(inp, self.dropout, self.training)
inp = nn.utils.rnn.pack_padded_sequence(inp, lengths)
inp = nn.utils.rnn.pack_padded_sequence(inp, lengths.cpu())
# run layer
louts, lhidden = rnn(inp, hidden[layer])
# unpack
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
URL = 'https://github.com/emanjavacas/pie'
AUTHOR = 'Enrique Manjavacas; Mike Kestemont; Thibault Clerice'
REQUIRES_PYTHON = '>=3.6.0'
VERSION = "0.3.7b"
VERSION = "0.3.7c"

# What packages are required for this module to be executed?

Expand Down

0 comments on commit 0ca4311

Please sign in to comment.