Skip to content

Commit

Permalink
Fix on torch.argsort only supporting for >PyTorch1.0.0 (songyouwei#24)
Browse files Browse the repository at this point in the history
* Fix version incompatibility of PyTorch

* Update dynamic_rnn.py
  • Loading branch information
GeneZC authored and songyouwei committed Jan 26, 2019
1 parent 7dd9f35 commit b80b895
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Requirement

* PyTorch 0.4.0
* PyTorch >= 0.4.0
* NumPy 1.13.3
* tensorboardX 1.2
* Python 3.6
Expand Down
6 changes: 3 additions & 3 deletions layers/dynamic_rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def forward(self, x, x_len):
:return:
"""
"""sort"""
x_sort_idx = torch.argsort(-x_len)
x_unsort_idx = torch.argsort(x_sort_idx).long()
x_sort_idx = torch.sort(-x_len)[1].long()
x_unsort_idx = torch.sort(x_sort_idx)[1].long()
x_len = x_len[x_sort_idx]
x = x[x_sort_idx.long()]
x = x[x_sort_idx]
"""pack"""
x_emb_p = torch.nn.utils.rnn.pack_padded_sequence(x, x_len, batch_first=self.batch_first)

Expand Down

0 comments on commit b80b895

Please sign in to comment.