Skip to content

[FEA] Skip Device Concat for KmeansMG - #8084

Merged
rapids-bot[bot] merged 40 commits into
rapidsai:release/26.08from
tarang-jain:mnmg-kmeans
Jul 28, 2026
Merged

[FEA] Skip Device Concat for KmeansMG#8084
rapids-bot[bot] merged 40 commits into
rapidsai:release/26.08from
tarang-jain:mnmg-kmeans

Conversation

@tarang-jain

@tarang-jain tarang-jain commented May 11, 2026

Copy link
Copy Markdown
Contributor

NVIDIA/cuvs#2066 allows passing host partitions directly to cuVS KMeans (MNMG). Merge this PR after NVIDIA/cuvs#2066 and #8248
Closes #8201

@copy-pr-bot

copy-pr-bot Bot commented May 11, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@tarang-jain tarang-jain self-assigned this May 11, 2026
@github-actions github-actions Bot added Cython / Python Cython or Python issue CUDA/C++ labels May 11, 2026
@tarang-jain tarang-jain added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change and removed Cython / Python Cython or Python issue CUDA/C++ labels May 11, 2026
@github-actions github-actions Bot added Cython / Python Cython or Python issue CUDA/C++ labels May 13, 2026
@tarang-jain
tarang-jain changed the base branch from main to release/26.06 May 18, 2026 16:26
@tarang-jain
tarang-jain changed the base branch from release/26.06 to main May 22, 2026 21:39
viclafargue

This comment was marked as off-topic.

@tarang-jain tarang-jain changed the title [WIP] [FEA] Skip Device Concat for KmeansMG [FEA] Skip Device Concat for KmeansMG Jun 10, 2026
Enables KMeans to process datasets that do not fit in device memory by
streaming batches through fit/predict. Scales inputs in batches, only
allocates batch_size buffers for uniform sample weights, and wires the
new streaming parameters through the C++ params, Cython bindings, and
Python layer. Includes tests for the streaming path.
@tarang-jain
tarang-jain changed the base branch from main to release/26.08 July 20, 2026 19:53
@github-actions github-actions Bot added the conda conda issue label Jul 20, 2026
Comment thread python/cuml/cuml/cluster/kmeans.pyx Outdated
Comment on lines +855 to +874
# Coerce each partition to a C-contiguous array, preserving its memory
# residency (device stays device, host stays host) via ``mem_type=None``
# so device-accessible partitions are never staged to host and
# host-resident partitions are never staged to device here.
# ``reset=True`` on the first partition records ``n_features_in_``;
# subsequent partitions are validated against it so mismatched shapes
# are rejected.
coerced_parts = []
coerced_weights = [] if has_weights else None
for i, part in enumerate(parts):
sw_in = sample_weight_parts[i] if has_weights else None
part_c, sw_c = check_inputs(
self,
part,
sample_weight=sw_in,
dtype=("float32", "float64"),
order="C",
mem_type=None,
reset=(i == 0),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

device-accessible partitions are never staged to host and host-resident partitions are never staged to device here

check_inputs(..., mem_type=None)

Shouldn't the memory residency be uniform across partitions? It looks like the C++ code dispatches according to the residency of the first partition.

The Python code should be congruent with the C++ code. We should detect the residency of the first partition and then coerce the following ones accordingly.

Additionally, the check_inputs function has a default of ensure_min_samples=1 meaning that if Dask provides any empty partition it would fail despite it being handled correctly on the cuVS implementation side.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I fixed it. We fetch the residency from the first partition and then load the subsequent ones using the same mem_type.

Comment thread python/cuml/cuml/cluster/kmeans.pyx
Comment thread cpp/src/kmeans/kmeans_fit.cu Outdated
@csadorf
csadorf self-requested a review July 27, 2026 18:40

@csadorf csadorf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No major concerns, but a few comments and questions.

Comment thread cpp/src/kmeans/kmeans_fit.cu
Comment thread python/cuml/cuml/cluster/kmeans.pyx
Comment thread python/cuml/cuml/cluster/kmeans_mg.py
Comment thread python/cuml/tests/dask/test_dask_kmeans.py Outdated
Comment thread python/cuml/cuml/cluster/kmeans.pyx Outdated
Comment thread python/cuml/cuml/cluster/kmeans.pyx Outdated
Comment thread python/cuml/cuml/cluster/kmeans_mg.py

@csadorf csadorf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

@csadorf

csadorf commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

/merge

@rapids-bot
rapids-bot Bot merged commit d4e8408 into rapidsai:release/26.08 Jul 28, 2026
102 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci CMake conda conda issue CUDA/C++ Cython / Python Cython or Python issue improvement Improvement / enhancement to an existing function non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEA] Scaling MNMG KMeans

4 participants