Skip to content

Apply new input validation to cuml.multiclass - #8017

Merged
rapids-bot[bot] merged 2 commits into
NVIDIA:mainfrom
mgrauer:enh-multiclass-input-validation
Apr 27, 2026
Merged

Apply new input validation to cuml.multiclass#8017
rapids-bot[bot] merged 2 commits into
NVIDIA:mainfrom
mgrauer:enh-multiclass-input-validation

Conversation

@mgrauer

@mgrauer mgrauer commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Part of #7428, fixes #7999.

Question: check_inputs in fit/predict/decision_function currently enforces dtype=("float32", "float64"). Since the underlying estimator also calls check_inputs with its own dtype constraints, should the wrapper enforce dtype at all, or pass dtype=None and let the estimator handle it?

@mgrauer
mgrauer requested a review from a team as a code owner April 25, 2026 14:35
@mgrauer
mgrauer requested a review from csadorf April 25, 2026 14:35
@github-actions github-actions Bot added the Cython / Python Cython or Python issue label Apr 25, 2026
@mgrauer mgrauer added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change cuml-accel Issues related to cuml.accel sklearn-api-compat Issues around cuml matching sklearn API conventions/standards labels Apr 25, 2026
@coderabbitai

coderabbitai Bot commented Apr 25, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e3a13515-9756-46bb-826e-ed673c733334

📥 Commits

Reviewing files that changed from the base of the PR and between f682419 and ef90bcc.

📒 Files selected for processing (1)
  • python/cuml/cuml/multiclass/multiclass.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • python/cuml/cuml/multiclass/multiclass.py

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Standardized input validation for training and inference to improve consistency and error detection.
    • Improved handling of array and sparse inputs across different memory configurations and numeric dtypes.
    • Fewer unexpected failures when passing diverse data formats to fit, predict, and decision APIs.
  • Refactor

    • Centralized validation/conversion logic to reduce duplication and simplify maintenance.
    • Adjusted internal training metadata handling for clearer reset semantics.

Walkthrough

Replaces legacy input conversion helpers with centralized check_inputs validation across fit, predict, and decision_function in the multiclass module. fit now validates both X and y with enforced float32/float64, accepts sparse input, uses host memory, and the fit decorator’s reset changed from True to "type".

Changes

Cohort / File(s) Summary
Multiclass Input Validation Refactoring
python/cuml/cuml/multiclass/multiclass.py
Replaced input_to_host_array* conversions with centralized check_inputs for fit, predict, and decision_function. fit passes both X and y through check_inputs (float32/float64, accept_sparse=True, mem_type="host", reset=True removed), and the fit decorator now uses reset="type".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • viclafargue
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% 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 clearly and specifically describes the main change: applying new input validation to the cuml.multiclass module.
Description check ✅ Passed The description is related to the changeset, referencing linked issues and explaining the implementation approach with a specific technical question.
Linked Issues check ✅ Passed The changes implement input validation replacement using check_inputs for fit/predict/decision_function methods, which aligns with the objective to update cuml.multiclass to new input validation (issue #7999).
Out of Scope Changes check ✅ Passed All changes focus on replacing input conversion methods with centralized check_inputs validation in multiclass wrapper, which is directly in scope of the input validation update objective.

✏️ 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.

🧹 Nitpick comments (1)
python/cuml/cuml/multiclass/multiclass.py (1)

50-58: Regarding your question on dtype enforcement:

The current approach of enforcing dtype=("float32", "float64") at the wrapper level is reasonable—it provides early validation with clear error messages before data reaches the underlying estimator. While this may result in some validation overlap with the estimator's own check_inputs, the overhead is minimal and the explicit contract makes the wrapper's requirements clear to users.

If you wanted to relax this, using dtype=None would defer entirely to the estimator, but you'd lose the early error messaging at the wrapper boundary. The current implementation is a sound default.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@python/cuml/cuml/multiclass/multiclass.py` around lines 50 - 58, The wrapper
currently enforces dtype=("float32", "float64") via check_inputs in
multiclass.py (call to check_inputs(self, X, y, dtype=(...))), which is
acceptable for early validation; leave it as-is for explicit input contracts, or
if you prefer to defer to the underlying estimator remove the dtype restriction
by changing dtype=("float32", "float64") to dtype=None in the check_inputs call
so the estimator's own validation handles dtype instead.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@python/cuml/cuml/multiclass/multiclass.py`:
- Around line 50-58: The wrapper currently enforces dtype=("float32", "float64")
via check_inputs in multiclass.py (call to check_inputs(self, X, y,
dtype=(...))), which is acceptable for early validation; leave it as-is for
explicit input contracts, or if you prefer to defer to the underlying estimator
remove the dtype restriction by changing dtype=("float32", "float64") to
dtype=None in the check_inputs call so the estimator's own validation handles
dtype instead.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0bbb1663-9314-4e87-9930-c2e565590654

📥 Commits

Reviewing files that changed from the base of the PR and between bfce194 and f682419.

📒 Files selected for processing (1)
  • python/cuml/cuml/multiclass/multiclass.py

@jcrist jcrist left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Thanks!

@jcrist

jcrist commented Apr 27, 2026

Copy link
Copy Markdown
Member

/merge

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 improvement Improvement / enhancement to an existing function non-breaking Non-breaking change sklearn-api-compat Issues around cuml matching sklearn API conventions/standards

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update cuml.multiclass to new input validation

4 participants