GroupKFold inconsistent under ties in group sizes.

### Describe the bug

Due to the use of argsort (a non stable sort withthout the stable parameter introduced in numpy 2.0), GroupKFold is not always reproducible when there are ties in group sizes.

### Steps/Code to Reproduce

You may need to run this on different machines, but you can reproduce this issue with even less code than GroupKFold by simply testing `np.argsort`.
```
import numpy as np

x = np.array([0.37454012, 0.95071431, 0.73199394, 0.        , 0.15601864,
       0.        , 0.05808361, 0.86617615, 0.60111501, 0.70807258,
       0.02058449, 0.96990985, 0.83244264, 0.21233911, 0.18182497,
       0.18340451, 0.30424224, 0.52475643, 0.43194502, 0.29122914,
       0.61185289, 0.13949386, 0.29214465, 0.36636184, 0.45606998,
       0.78517596, 0.19967378, 0.51423444, 0.59241457, 0.        ,
       0.60754485, 0.17052412, 0.06505159, 0.        , 0.96563203,
       0.80839735, 0.        , 0.        , 0.68423303, 0.44015249,
       0.12203823])

print(np.argsort(x))
```
Both times with numpy version: 1.26.4
machine a: `array(3,5,29,33,36,37,10,6,32,40...`
machine b: `array(37,36,3,29,5,33,10,6,32,40...`

### Expected Results

Technically a stable sort isn't required, no need to maintain the original ordering. However a consistent sort result is required for reproducibility.  Stable sort is an easy way to achieve this that is already built into numpy.

### Actual Results

Both times with numpy version: 1.26.4
machine a: `array(3,5,29,33,36,37,10,6,32,40...`
machine b: `array(37,36,3,29,5,33,10,6,32,40...`

### Versions

```shell
sklearn versions are mostly irrelevant here as the issue is with calling a numpy method that requires additional changes.
```

COMMENT:
> Are you able to reproduce this issue with GroupKFold? Perhaps I'm missing something
> 
> I have the following code, which seems to work:
> 
> ```
> def test_group_kfold_reproducible():
>     # Check that iterating twice on the GroupKFold gives the same
>     # sequence of train-test when the random_state is given
>     # make many groups of same size
>     for idx in range(100):
>         groups = np.repeat(np.arange(50), 20)
> 
>         X = np.random.rand(1000)
>         gkf = GroupKFold()
> 
>         first_split = [a for a in gkf.split(X, groups=groups)]
>         second_split = [a for a in gkf.split(X, groups=groups)]
>         for (train1, test1), (train2, test2) in zip(first_split, second_split):
>             assert_array_equal(train1, train2)
>             assert_array_equal(test1, test2)
> ```

Yes I actually found this in one of my models when trying to reproduce it. The group sizes have a very common mode size and it causes very many ties. Once I made this switch to stable sort, by extending the GroupKFold class, I was able to make it reproducible. I only have been able to see different results on different runs of kubeflow where each instantiation of GroupKFold is on a different pod (same docker image).

When trying to reproduce even the subproblem (of the argsort inconsistency) I've only been able to see that when running in separate machines, for example on my mac vs on AWS ECS. Though in the actual model the instances should be the same type and in a container.

Labels: Bug