data-apis / array-api-compat

Compatibility layer for common array libraries to support the Array API
https://data-apis.org/array-api-compat/
MIT License
79 stars 28 forks source link

Should array-api-compat torch `from_dlpack` accept `copy`? #204

Open mdhaber opened 4 days ago

mdhaber commented 4 days ago

Currently, neither vanilla torch nor array-api-compat torch seem to accept the copy keyword. (Or the device keyword, of course, but that is probably harder to deal with.)

import numpy as np
import torch
from array_api_compat import array_namespace
xp = array_namespace(torch.asarray([1, 2, 3]))
x = np.asarray([1, 2, 3])
y = xp.from_dlpack(x, copy=False)  # TypeError: from_dlpack() got an unexpected keyword argument 'copy'
y = torch.from_dlpack(x, copy=False)  # TypeError: from_dlpack() got an unexpected keyword argument 'copy'

Should the array-api-compat version accept it, or does it need to wait for PyTorch itself?

Crossref scipy/scipy#21890

rgommers commented 4 days ago

Needs to wait I think, that's also DLPack 1.0. from_dlpack only passes the copy keyword on to dlpack, and the copying is expected to be done by the producer.