Skip to content

Support LabelEncoder in cuml.accel - #8082

Merged
rapids-bot[bot] merged 4 commits into
NVIDIA:mainfrom
jcrist:label-encoder-cuml-accel
May 12, 2026
Merged

Support LabelEncoder in cuml.accel#8082
rapids-bot[bot] merged 4 commits into
NVIDIA:mainfrom
jcrist:label-encoder-cuml-accel

Conversation

@jcrist

@jcrist jcrist commented May 11, 2026

Copy link
Copy Markdown
Member

This adds support for LabelEncoder in cuml.accel.

Fixes #8015.

@jcrist jcrist self-assigned this May 11, 2026
@jcrist
jcrist requested a review from a team as a code owner May 11, 2026 21:16
@jcrist jcrist added feature request New feature or request non-breaking Non-breaking change labels May 11, 2026
@jcrist
jcrist requested a review from csadorf May 11, 2026 21:16
@jcrist jcrist added the cuml-accel Issues related to cuml.accel label May 11, 2026
@github-actions github-actions Bot added the Cython / Python Cython or Python issue label May 11, 2026
@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • GPU-accelerated LabelEncoder with seamless CPU/GPU interoperability and guaranteed CPU-side support (no fallback).
  • Documentation

    • FAQ and limitations updated to list LabelEncoder among accelerated preprocessing components and note its supported cases.
  • Tests

    • Added integration and cross-framework tests validating encoding, decoding, signature behavior, and model round-trip consistency.

Walkthrough

Adds accel support for sklearn.preprocessing.LabelEncoder: proxy generation updates, cuml.preprocessing.LabelEncoder CPU/GPU interop hooks, proxy export and discovery deduplication, tests for transform/round-trip and signature, and FAQ/limitations docs updates.

Changes

LabelEncoder GPU Acceleration via Proxy

Layer / File(s) Summary
ProxyBase Infrastructure Enhancement
python/cuml/cuml/accel/estimator_proxy.py
ProxyBase.__init_subclass__ wraps __init__ for object-initializers, forwards _estimator_type and _parameter_constraints with type checks, updates proxy method generation to respect exclude, and removes the _parameter_constraints classproperty.
GPU LabelEncoder CPU Interoperability
python/cuml/cuml/preprocessing/_label.py
LabelEncoder adds InteropMixin, _cpu_class_path = "sklearn.preprocessing.LabelEncoder", and CPU↔GPU hooks (_params_from_cpu, _params_to_cpu raising UnsupportedOnCPU for unsupported handle_unknown, _attrs_from_cpu, _attrs_to_cpu) mapping classes_.
LabelEncoder Proxy Export and Wiring
python/cuml/cuml/accel/_overrides/sklearn/preprocessing.py, python/cuml/cuml/accel/_patches/sklearn/utils/*, python/cuml/cuml/accel/core.py
Adds LabelEncoder to accel preprocessing overrides as a proxy delegating to cuml.preprocessing.LabelEncoder; implements sklearn.utils.discovery.all_estimators wrapper to deduplicate estimator names preferring proxies; registers sklearn.utils.discovery in accel _PATCHES.
Tests and Documentation
python/cuml/cuml_accel_tests/*, python/cuml/tests/*, docs/source/cuml-accel/faq.rst, docs/source/cuml-accel/limitations.rst
Adds integration and import/export tests validating fit/transform/inverse_transform and CPU/GPU model conversions and a signature regression test; updates FAQ and limitations to include LabelEncoder and state it never falls back to CPU.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • #8015: The linked issue requesting cuml.accel support for LabelEncoder is implemented by this PR (proxy export, CPU/GPU interop, tests, docs).

Possibly related PRs

  • rapidsai/cuml#8039: Modifies cuml.preprocessing._label.py; related to LabelEncoder implementation and tests.
  • rapidsai/cuml#8032: Related changes to estimator proxy machinery and preprocessing overrides.
  • rapidsai/cuml#8041: Overlaps on estimator_proxy.py proxy-class creation/handling changes.

Suggested reviewers

  • csadorf
  • dantegd
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.70% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Support LabelEncoder in cuml.accel' is concise, specific, and clearly summarizes the primary change of adding LabelEncoder support to cuml.accel.
Description check ✅ Passed The description clearly states the pull request adds support for LabelEncoder in cuml.accel and references the related issue #8015, which is directly related to the changeset.
Linked Issues check ✅ Passed The pull request comprehensively implements LabelEncoder support in cuml.accel by adding proxy class overrides, CPU interoperability, integration tests, and documentation.
Out of Scope Changes check ✅ Passed All changes are directly scoped to supporting LabelEncoder in cuml.accel; refactoring of estimator_proxy.py and discovery.py are necessary supporting infrastructure changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/source/cuml-accel/limitations.rst`:
- Line 464: Fix the spelling typo in the documentation sentence mentioning
LabelEncoder: change "neverf" to "never" so the line reads "LabelEncoder
supports all cases and will never fall back to CPU."; update the text around the
symbol "LabelEncoder" accordingly to preserve formatting (e.g., keep the inline
code markers).

In `@python/cuml/cuml/preprocessing/_label.py`:
- Around line 88-93: The error message in the _params_to_cpu method uses a
string with {self.handle_unknown} but lacks the f-string prefix, so the literal
text is shown; update the UnsupportedOnCPU raise in _params_to_cpu to use an
f-string that interpolates self.handle_unknown (i.e., make the message
f"`handle_unknown={self.handle_unknown}` is not supported") so the actual
attribute value appears in the logged exception.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 074d7091-5850-411e-b8a7-d160872cedd6

📥 Commits

Reviewing files that changed from the base of the PR and between 1abaa4a and 0194ee2.

📒 Files selected for processing (7)
  • docs/source/cuml-accel/faq.rst
  • docs/source/cuml-accel/limitations.rst
  • python/cuml/cuml/accel/_overrides/sklearn/preprocessing.py
  • python/cuml/cuml/accel/estimator_proxy.py
  • python/cuml/cuml/preprocessing/_label.py
  • python/cuml/cuml_accel_tests/integration/test_preprocessing.py
  • python/cuml/tests/test_sklearn_import_export.py

Comment thread docs/source/cuml-accel/limitations.rst Outdated
Comment thread python/cuml/cuml/preprocessing/_label.py
@jcrist
jcrist force-pushed the label-encoder-cuml-accel branch from 0194ee2 to 43005b2 Compare May 11, 2026 21:24

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@python/cuml/cuml_accel_tests/integration/test_preprocessing.py`:
- Around line 113-120: Extend test_label_encoder to add edge cases and
multi-type input parity checks: add assertions for empty input and single-sample
input, run the same sequences (fit, transform, inverse_transform) on numpy
arrays, pandas.Series, and cuDF Series (when cuDF is available) and compare
outputs to scikit-learn's LabelEncoder to ensure parity; specifically use the
existing LabelEncoder instance (enc) and methods enc.fit_transform and
enc.inverse_transform and compare enc.classes_, transformed arrays, and
inverse-transformed results against sklearn.preprocessing.LabelEncoder for each
input type and edge case, plus ensure fit/transform consistency is validated for
each case.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: be3b3c93-8313-4b26-b260-2245e0abf9af

📥 Commits

Reviewing files that changed from the base of the PR and between 0194ee2 and 43005b2.

📒 Files selected for processing (7)
  • docs/source/cuml-accel/faq.rst
  • docs/source/cuml-accel/limitations.rst
  • python/cuml/cuml/accel/_overrides/sklearn/preprocessing.py
  • python/cuml/cuml/accel/estimator_proxy.py
  • python/cuml/cuml/preprocessing/_label.py
  • python/cuml/cuml_accel_tests/integration/test_preprocessing.py
  • python/cuml/tests/test_sklearn_import_export.py
✅ Files skipped from review due to trivial changes (3)
  • docs/source/cuml-accel/faq.rst
  • docs/source/cuml-accel/limitations.rst
  • python/cuml/cuml/accel/_overrides/sklearn/preprocessing.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • python/cuml/tests/test_sklearn_import_export.py
  • python/cuml/cuml/accel/estimator_proxy.py
  • python/cuml/cuml/preprocessing/_label.py

Comment thread python/cuml/cuml_accel_tests/integration/test_preprocessing.py

@betatim betatim 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.

LGTM.

For my education: why not use the array API version from scikit-learn?

jcrist added 4 commits May 12, 2026 10:19
This adds support for `LabelEncoder` in `cuml.accel`.
Some tests import `all_estimators` from the full path instead of
`sklearn.utils`. We need to patch both locations.
@jcrist
jcrist force-pushed the label-encoder-cuml-accel branch from 43005b2 to 32ad6db Compare May 12, 2026 15:19
@jcrist

jcrist commented May 12, 2026

Copy link
Copy Markdown
Member Author

For my education: why not use the array API version from scikit-learn?

We can't support non-numeric labels that way w/ cupy. Using our builtin version lets us support all dtypes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@python/cuml/cuml/accel/_patches/sklearn/utils/discovery.py`:
- Around line 42-44: Replace the hard assertion in the duplicate-name resolution
so all_estimators() doesn't crash: instead of assert len(proxied_cls) == 1,
implement a deterministic fallback that (1) if exactly one proxy exists use
proxied_cls[0], (2) if multiple proxies exist pick a consistent choice (e.g.,
the first element of proxied_cls), and (3) if no proxies exist pick a
deterministic class from cls_list (e.g., the first element); then append that
chosen class in the estimators.append((name, ...)) call and optionally emit a
non-fatal warning to aid debugging.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: fe28587d-e480-4f64-ad5f-ad1770c41397

📥 Commits

Reviewing files that changed from the base of the PR and between 43005b2 and 32ad6db.

📒 Files selected for processing (11)
  • docs/source/cuml-accel/faq.rst
  • docs/source/cuml-accel/limitations.rst
  • python/cuml/cuml/accel/_overrides/sklearn/preprocessing.py
  • python/cuml/cuml/accel/_patches/sklearn/utils/__init__.py
  • python/cuml/cuml/accel/_patches/sklearn/utils/discovery.py
  • python/cuml/cuml/accel/core.py
  • python/cuml/cuml/accel/estimator_proxy.py
  • python/cuml/cuml/preprocessing/_label.py
  • python/cuml/cuml_accel_tests/integration/test_preprocessing.py
  • python/cuml/cuml_accel_tests/test_estimator_proxy.py
  • python/cuml/tests/test_sklearn_import_export.py
✅ Files skipped from review due to trivial changes (1)
  • docs/source/cuml-accel/limitations.rst
🚧 Files skipped from review as they are similar to previous changes (5)
  • python/cuml/cuml/accel/_overrides/sklearn/preprocessing.py
  • docs/source/cuml-accel/faq.rst
  • python/cuml/cuml_accel_tests/integration/test_preprocessing.py
  • python/cuml/cuml/preprocessing/_label.py
  • python/cuml/tests/test_sklearn_import_export.py

Comment thread python/cuml/cuml/accel/_patches/sklearn/utils/discovery.py
@jcrist

jcrist commented May 12, 2026

Copy link
Copy Markdown
Member Author

/merge

@rapids-bot
rapids-bot Bot merged commit 3276eed into NVIDIA:main May 12, 2026
93 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuml-accel Issues related to cuml.accel Cython / Python Cython or Python issue feature request New feature or request non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add cuml.accel support for LabelEncoder

3 participants