Repository navigation
Closed
dask/dask
#7391Description
What happened:
Exception raised: IndexError("Too many indices for array") as a direct result of following the steps from the K-Means|| example.
What you expected to happen:
The K-Means algorithm to successfully complete the fitting stage.
Minimal Complete Verifiable Example:
Reproducible via following the steps from the K-Means|| example.
import dask_ml.datasets
import dask_ml.cluster
X, y = dask_ml.datasets.make_blobs(n_samples=10000000,
chunks=1000000,
random_state=0,
centers=3)
X = X.persist()
km = dask_ml.cluster.KMeans(n_clusters=3, init_max_iter=2, oversampling_factor=10)
km.fit(X)Anything else we need to know?:
Traceback:
In []: km.fit(X)
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-4-e41873a7fbf2> in <module>
----> 1 km.fit(X)
~/anaconda3/lib/python3.8/site-packages/dask_ml/cluster/k_means.py in fit(self, X, y)
194 def fit(self, X, y=None):
195 X = self._check_array(X)
--> 196 labels, centroids, inertia, n_iter = k_means(
197 X,
198 self.n_clusters,
~/anaconda3/lib/python3.8/site-packages/dask_ml/cluster/k_means.py in k_means(X, n_clusters, init, precompute_distances, n_init, max_iter, verbose, tol, random_state, copy_x, n_jobs, algorithm, return_n_iter, oversampling_factor, init_max_iter)
266 * n_jobs=-1
267 """
--> 268 labels, inertia, centers, n_iter = _kmeans_single_lloyd(
269 X,
270 n_clusters,
~/anaconda3/lib/python3.8/site-packages/dask_ml/cluster/k_means.py in _kmeans_single_lloyd(X, n_clusters, max_iter, init, verbose, x_squared_norms, random_state, tol, precompute_distances, oversampling_factor, init_max_iter)
569 # Require at least one per bucket, to avoid division by 0.
570 counts = da.maximum(counts, 1)
--> 571 new_centers = new_centers / counts[:, None]
572 (new_centers,) = compute(new_centers)
573
~/anaconda3/lib/python3.8/site-packages/dask/array/core.py in __getitem__(self, index)
1694 )
1695
-> 1696 index2 = normalize_index(index, self.shape)
1697 dependencies = {self.name}
1698 for i in index2:
~/anaconda3/lib/python3.8/site-packages/dask/array/slicing.py in normalize_index(idx, shape)
895 idx = idx + (slice(None),) * (len(shape) - n_sliced_dims)
896 if len([i for i in idx if i is not None]) > len(shape):
--> 897 raise IndexError("Too many indices for array")
898
899 none_shape = []
IndexError: Too many indices for arrayInspection of values via ipdb:
In []: km.fit(X)
> /root/anaconda3/lib/python3.8/site-packages/dask/array/slicing.py(898)normalize_index()
897 import ipdb; ipdb.set_trace()
--> 898 raise IndexError("Too many indices for array")
899
ipdb> list
893 n_sliced_dims += 1
894
895 idx = idx + (slice(None),) * (len(shape) - n_sliced_dims)
896 if len([i for i in idx if i is not None]) > len(shape):
897 import ipdb; ipdb.set_trace()
--> 898 raise IndexError("Too many indices for array")
899
900 none_shape = []
901 i = 0
902 for ind in idx:
903 if ind is not None:
ipdb> pp idx
(slice(None, None, None), None)
ipdb> pp n_sliced_dims
1
ipdb> pp len([i for i in idx if i is not None])
1
ipdb> pp shape
()Possibly related to #802.
Environment:
- Dask version: 2021.03.0
- Dask_ml version: 1.8.0
- Python version: 3.8.5 (default, Sep 4 2020, 07:30:14), [GCC 7.3.0]
- Operating System: Debian Buster
- Install method (conda, pip, source): pip
If this is not reproducible on the maintainers' side, I'll be happy to provide a Dockerfile with a bit more concrete details about the underlying environment.
Also, please, let me know if this should be moved to the Dask repository instead.
Thanks!
Metadata
Metadata
Assignees
Labels
No labels
Activity
nils-braun commentedon Mar 11, 2021
I see the same issue here. One additional information: it works with Dask 2021.2.0 (which would also be a quickfix, @hristog, if you need one).
hristog commentedon Mar 11, 2021
Hi @nils-braun, thanks very much! I'll give it a go, yes.
TomAugspurger commentedon Mar 12, 2021
hristog commentedon Mar 12, 2021
@TomAugspurger, it might've been dask/dask#7326. I'll check if it was indeed that one (or something else), when I get a chance.
Update: Turns out it wasn't that PR. Please, see the next comment below.
hristog commentedon Mar 12, 2021
Reporting some partial update on this one (partial, because I haven't looked into the underlying specifics too much).
I could be wrong, but according to
git bisect, it seems that the erroneous behavior originated in the following commit and PR: dask/dask@bf1c65c4 / dask/dask#7183:Apparently, the same commit/PR is one of the culprits behind dask/dask#7324.
Would the
daskcode base benefit from some associated unit-tests, rather than having to rely upon unit-tests from dependent libraries?Update: I've created a proposal for utilizing repository dispatch events in
daskunder dask/dask#7385.TomAugspurger commentedon Mar 14, 2021
Yep, definitely (assuming this is an actual regression, and not dask-ml relying on buggy behavior).
GenevieveBuckley commentedon Mar 15, 2021
I don't think this is dask-ml relying on buggy behaviour, we're seeing tests in scikit-image and cupy failing too. So I think that particular side effect was unintentional.
GenevieveBuckley commentedon Mar 15, 2021
Can someone from dask-ml try this change and see if it fixes your issue?
dask/dask#7391
It seems like this helps fix similar issues in scikit-image, and I don't think I'm introducing more problems than it solves (should have a better idea of that soon though)
hristog commentedon Mar 15, 2021
I've run some tests in correspondence to dask/dask#7391. It'd be best if somebody from the dask/dask-ml team could have a bit more thorough look, because I'm new to the ecosystem.
My findings are that using the same
random_state, indeed givess the same results (in terms of cluster centers) for the K-Means|| example, as it does with the code-base version prior to introducing dask/dask@bf1c65c4.In the table below, I've summarized the corresponding unit-test results (with respect to my local environment) for:
py.test dask/array/ --verbose --doctest-modules(dask)py.test tests/ --verbose --doctest-modules(dask-ml)daskcommit datedaskcode-base versionTable notes:
*: These numbers correspond to a code-base version that's 3 weeks older than the other two versions**: These numbers are obtained using the samedask-mlversion (the latestmainfrom Feb 24), that was used in the other two table rows, whilst thedaskcode-base versions are different.Hope this provides a better idea about the impact of the proposed fix.
GenevieveBuckley commentedon Mar 16, 2021
Confirmed, with the change proposed in dask/dask#7391 we can now run the dask-ml K-means example code again:
GenevieveBuckley commentedon Mar 16, 2021
The rest of the dask-ml test suite passes on my local machine with this fix, so I'm happy about that
RichardScottOZ commentedon Jun 6, 2021
Additionally, I had the above fail with this combination
Dask version: 2021.03.0
Dask_ml version: 1.9.0
Python version: 3.8.5
Operating System: Ubuntu
Install method (conda, pip, source): pip