Repository navigation
Add common test for mixed y string and array API X for estimators - #34142
Conversation
|
Thanks for starting this PR. I think we should expand the documentation to document the expectations we encode in this new test. |
|
I would like to clean up I think the changes I have in mind are too significant to be part of this PR, so although I find the current test code messy, I think it is best if I make the refactoring and clean up in a separate PR. |
|
ping maybe @OmarManzoor @betatim ? |
OmarManzoor
left a comment
There was a problem hiding this comment.
@lucyleeow thank you for the PR. A few questions?
| GaussianNB: { | ||
| "check_array_api_mixed_inputs": "mixed array API input support not added yet", | ||
| "check_array_api_string_and_numeric_inputs": ( | ||
| "mixed string and numeric array API input support not added yet" | ||
| ), | ||
| "check_array_api_same_namespace": "check_same_namespace not yet added", | ||
| }, |
There was a problem hiding this comment.
I think you tried out GaussianMixture instead of GaussianNB. Does this not work with GaussianNB?
There was a problem hiding this comment.
Interestingly GaussianNB passes check_array_api_string_and_numeric_inputs but fails check_array_api_mixed_inputs.
The failure is because torch.asarray does not work on an array api strict boolean array (though it does work on numpy boolean array). I am looking into whether/how this is a torch bug.
Details
In [6]: import array_api_strict as xp
In [7]: a_strict = xp.asarray([True,False])
In [8]: torch.asarray(a_strict)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[8], line 1
----> 1 torch.asarray(a_strict)
ValueError: buffer length (2 bytes) after offset (0 bytes) must be a multiple of element size (4)AFAICT the test should pass for GaussianNB
There was a problem hiding this comment.
Would it help to use move_to at the point where this fails?
There was a problem hiding this comment.
I can't quite tell if this is a torch bug but I opened an issue: pytorch/pytorch#188128
I don't quite understand why locally I get a different error vs what we get in CI, from https://github.com/scikit-learn/scikit-learn/actions/runs/28084989224/job/83148860207?pr=34142:
> return torch.asarray(obj, dtype=dtype, device=device, copy=copy, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E RuntimeError: could not retrieve buffer from object
copy = None
device = device(type='cpu')
dtype = None
kwargs = {}
obj = Array([ True,
True,
True,
True,
False,
False,
False,
True,
...lse,
True,
False,
True], dtype=array_api_strict.bool, device=array_api_strict.Device('device1'))This should be equivalent to torch.asarray(a_strict) - I think cpu is the default device.
I have the same pytorch version as in CI (2.12), though I installed through pip and CI is through conda-forge. What do other people get?
Would it help to use move_to at the point where this fails?
Yes torch.from_dlpack(a_strict, device='cpu') will give a boolean tensor. Is this what we want to do? 🤔 I think one problem is that move_to does not always handle lists (#34046)
There was a problem hiding this comment.
Okay, this is indeed a pytorch bug.
Why don't I keep the xfail with the reason being the pytorch bug and it can be removed once fixed in pytorch and released.
There was a problem hiding this comment.
Yes I think we can keep the xfail and merge this PR
|
Thanks all! I think this is ready for another review 🙏 |
OmarManzoor
left a comment
There was a problem hiding this comment.
Minor comments related to the documentation otherwise looks good now. Thank you @lucyleeow
Co-authored-by: Omar Salman <[email protected]> Co-authored-by: Olivier Grisel <[email protected]>
ogrisel
left a comment
There was a problem hiding this comment.
I just triggered the Intel and CUDA GPU CI on this branch:
If all is green, LGTM.
|
Thanks @lucyleeow! Now we have to fix those XFAILed test cases :) |
…ikit-learn#34142) Co-authored-by: Olivier Grisel <[email protected]> Co-authored-by: Omar Salman <[email protected]>
Reference Issues/PRs
closes #34094
What does this implement/fix? Explain your changes.
AI usage disclosure
I used AI assistance for:
Any other comments?