Skip to content

Fix test failure if no device parameter - #459

Open
prady0t wants to merge 8 commits into
data-apis:masterfrom
prady0t:device-fix
Open

Fix test failure if no device parameter#459
prady0t wants to merge 8 commits into
data-apis:masterfrom
prady0t:device-fix

Conversation

@prady0t

@prady0t prady0t commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #458

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Comment thread array_api_tests/dtype_helpers.py
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
@ev-br

ev-br commented Aug 21, 2026

Copy link
Copy Markdown
Member

I tried testing this PR with MLX since that's the only library which supports DLPack but does not have the .device attribute. Running dlpack tests is blocked on the lack of __array_namespace_info__, thus I think we should come back to this PR after ml-explore/mlx#4334 lands upstream.

Comment thread array_api_tests/dtype_helpers.py Outdated
Comment thread array_api_tests/dtype_helpers.py Outdated
Co-authored-by: Tim Head <betatim@gmail.com>
@prady0t

prady0t commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

@ev-br Care for another look?

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Comment thread array_api_tests/dtype_helpers.py Outdated
try:
has_device = "device" in inspect.signature(xp.empty).parameters
except (TypeError, ValueError):
has_device = False

@ev-br ev-br Aug 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, this is getting messy. IIUC this whole pattern is meant to account for

  • MLX not reacting to inspect.signature (an exception or a non-informative *args, **kwargs signature, depending on the nanobind version)
  • CuPy genuinely missing the device argument
  • PyTorch raising a ValueError in inspect.signature(xp.empty)

However, I don't think this works correctly with e.g. pytorch: inspect.signature raises but the device argument is accepted:

In [10]: torch.empty(3, device="meta")
Out[10]: tensor(..., device='meta', size=(3,))

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test fails if no device parameter.

3 participants