array-api icon indicating copy to clipboard operation
array-api copied to clipboard

PyTorch 'meta' device needs per-device capabilities

Open crusaderky opened this issue 6 months ago • 3 comments

PyTorch has a special device, meta, which is a dummy device with no underlying data. This is a very powerful testing tool. However, PyTorch has not implemented special support for unknown shapes just for this device. As a result, unique etc. fail.

Proposal

Change capabilities() to capabilities(*, device=None), matching the signature of default_dtypes() and dtypes().

Change array_api_compat.torch:

def capabilities(*, device=None):
    device = torch.get_default_device() if device is None else torch.device(device)
    is_material = device.type != "meta"
    return {
        "boolean indexing": is_material,
        "data-dependent shapes": is_material,
        "max dimensions": 64,
    }

crusaderky avatar May 18 '25 12:05 crusaderky

xref https://github.com/data-apis/array-api-extra/pull/300

crusaderky avatar May 18 '25 12:05 crusaderky

PyTorch has a special device, meta, which is a dummy device with no underlying data. This is a very powerful testing tool.

+1. xref https://github.com/data-apis/array-api/discussions/777 with a bunch of interest and discussion on this kind of functionality.

rgommers avatar May 26 '25 08:05 rgommers

@jakevdp Would you have any objections to adding a device kwarg with the default being None for this API? Would be good to get JAX's input on this.

kgryte avatar May 29 '25 17:05 kgryte