OpenNMT / OpenNMT/CTranslate2

Incorrect device index in `StorageView`

Open
#1,467 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C++
Stars
4.7k
Forks
536
Avg merge
12h 12m
Merged PRs (30d)
4

Description

import torch
import ctranslate2

x0 = torch.ones((2, 4), dtype=torch.int32, device="cuda:0")
y0 = ctranslate2.StorageView.from_array(x0)

print(f"Original tensor is on {x0.device} and StorageView is on {y0.device}:{y0.device_index}")

x1 = torch.ones((2, 4), dtype=torch.int32, device="cuda:1")
y1 = ctranslate2.StorageView.from_array(x1)

print(f"Original tensor is on {x1.device} and StorageView is on {y1.device}:{y1.device_index}")

The output I get is

Original tensor is on cuda:0 and StorageView is on cuda:0
Original tensor is on cuda:1 and StorageView is on cuda:0

The actual data is still on cuda:0 for y0 and on cuda:1 for y1.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Python StorageView.from_array example with tensors on cuda:0 and cuda:1, then trace how device and device_index are reported. Compare the reported index with the actual data placement; done means StorageView.device_index matches the source tensor for both devices without changing the data location.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
backend, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.