Skip to content

Calling pad_packed_sequence with tensors on cuda and enforce_sorted=false causes issue #1170

@shaltielshmid

Description

@shaltielshmid

This bug is actually rooted in LibTorch, as reported here: pytorch/pytorch#115027

The issue is that when enforce_sorted=false the unsorted_indices are used to index on the lengths tensor, but the indices are stored on the same device as the input tensor, and lengths is stored on the CPU.

Example code to replicated:

var input = torch.randn(new[] { 5L, 5L }).@float().cuda();
var lengths = torch.full(5, 5);

var packed = torch.nn.utils.rnn.pack_padded_sequence(input, lengths, enforce_sorted: false);
var error = torch.nn.utils.rnn.pad_packed_sequence(packed);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions