Skip to content

torch.Tensor access via :index() delivers inconsistent results after data moved to CUDA device via :cuda() #877

@goforthanddie

Description

@goforthanddie

Hello there,
the following code reproduces my problem. I want to access a tensor with labels randomly and stumbled across the problem of retrieving inconsistent results when using :index() as access method.

require 'cutorch'
i = torch.LongTensor(3)
i[{1}] = 7816227
i[{2}] = 19206839
i[{3}] = 19206840
torch.manualSeed(101)
labels = torch.Tensor(19206840)
labels = labels:random(1,257)
print(tostring(labels:index(1, i)))
print(tostring(labels[i[{1}]]) .. ' ' .. tostring(labels[i[{2}]]) .. ' ' ..tostring(labels[i[{3}]]))
labels = labels:cuda()
print(tostring(labels:index(1, i)))
print(tostring(labels[i[{1}]]) .. ' ' .. tostring(labels[i[{2}]]) .. ' ' ..tostring(labels[i[{3}]]))

I expect lines 9 and 12 to produce the same results. but they dont. I get 171, 46, 139 before moving labels to the CUDA device and 171, 13, 13 afterwards in line 12. Interestingly the other access method works fine.

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