Fix test failure if no device parameter - #459
Conversation
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
|
I tried testing this PR with MLX since that's the only library which supports DLPack but does not have the |
| x = xp.empty(2, device=device) | ||
| try: | ||
| x = xp.empty(2, device=device) | ||
| except: |
There was a problem hiding this comment.
Maybe we should make this except TypeError (I think this is the exception?) to make sure we only catch errors that are due to the fact that there is no device keyword argument.
Even better would be having a way to inspect the array library/function to determine if there is a device argument or not. This would be explicitly checking what we want to know
Co-authored-by: Tim Head <betatim@gmail.com>
|
@ev-br Care for another look? |
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
| try: | ||
| has_device = "device" in inspect.signature(xp.empty).parameters | ||
| except (TypeError, ValueError): | ||
| has_device = False |
There was a problem hiding this comment.
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, **kwargssignature, depending on thenanobindversion) - CuPy genuinely missing the
deviceargument - 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>
Fixes #458