Skip to content

[Data] GPU enabled ray.data.preprocessor APIs - #66012

Closed
leewyang wants to merge 9 commits into
ray-project:masterfrom
leewyang:gpu_preprocessor
Closed

leewyang wants to merge 9 commits into
ray-project:masterfrom
leewyang:gpu_preprocessor

Conversation

@leewyang

@leewyang leewyang commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds GPU support for ray.data.preprocessor APIs.

Key changes:

  • Adds GPU variants of the following preprocessors: HashingVectorizer, OneHotEncoder, OrdinalEncoder, PowerTransformer, SimpleImputer, StandardScaler.
  • Adds a GPUChain implementation that fuses the fit/transform stages of chained preprocessors.
  • Improved global aggregations on GPU (which don't require GPU shuffle).
  • Improved scheduling, metrics, backpressure for GPU ops.
  • Added min_evidence argument to OrdinalEncoder to exclude categories below a count threshold.

Related issues

Related to #63708

Additional information

Automatic conversion to GPU implementations (for supported preprocessors) is enabled via new arguments in the standard API:

chain.fit_transform(
      dataset,
      accelerator="gpu",
      num_gpus=4,
      num_gpus_per_worker=1,
  )

@leewyang
leewyang requested a review from a team as a code owner September 8, 2026 23:11
@leewyang
leewyang marked this pull request as draft September 8, 2026 23:11
@leewyang leewyang changed the title [DRAFT] GPU enabled ray.data.preprocessor APIs GPU enabled ray.data.preprocessor APIs Sep 8, 2026
@leewyang

leewyang commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces GPU-native global aggregation and standard deviation operators, adds a suite of GPU-native preprocessors with a fused GPUChain execution path, and optimizes GPU hash aggregation with actor-local compaction and improved backpressure handling. The review feedback highlights three critical issues: a potential TypeError in the CPU fallback path of Chain.fit_transform due to unsupported keyword arguments, a missing import of cast in hash_aggregate.py causing a runtime NameError, and incorrect null-checking logic in encoder.py that fails to handle pandas NaN and pd.NA values.

Comment thread python/ray/data/preprocessors/chain.py Resolved

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

Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 137bd0d. Configure here.

@leewyang leewyang changed the title GPU enabled ray.data.preprocessor APIs [Data] GPU enabled ray.data.preprocessor APIs Sep 11, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Sep 26, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no more activity in the 14 days
since being marked stale.

Please feel free to reopen or open a new pull request if you'd still like this to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for your contribution!

@github-actions github-actions Bot closed this Oct 10, 2026
goutamvenkat-anyscale pushed a commit that referenced this pull request Oct 16, 2026
…ggregation (#66088)

## Why are these changes needed?

Encoder preprocessors (`OrdinalEncoder`, `OneHotEncoder`,
`MultiHotEncoder`,
`LabelEncoder`, `Categorizer`) currently fit through
`compute_unique_value_indices`: a `map_batches` that emits per-block
value
counters, followed by a loop **on the driver** that merges them into
global
counts. `SimpleImputer(strategy="most_frequent")` has the same shape via
`_get_most_frequent_values`. That driver-side merge is a scalability
bottleneck, and because it is registered as a *callable stat*, it can
never be
batched with other statistics into a single `Dataset.aggregate()` query.

This PR moves those fits onto the stat computation plan as real
distributed
aggregations:

- The five encoders register `Unique` (or `TopKUnique` when
`max_categories`
is set) with the same `unique_values({col})` alias the transform code
reads.
- `SimpleImputer("most_frequent")` registers `TopKUnique(k=1,
ignore_nulls=True)`.
It returns the most frequent non-null value, breaks frequency ties by
picking
the smallest value, and yields no value for an all-null column, which
gives
the same results as before. It uses the vectorized column-wise merge, so
no
  driver-side argmax helper is needed.
- `Unique` (and `TopKUnique`) fall back to collecting values in Python
when
the vectorized path can't handle a column's type: types without an Arrow
  `unique`/`value_counts` kernel, such as tensor columns, and list-typed
  columns when the optional `polars` package isn't installed. Lists and
  arrays become tuples, so the encoders produce the same categories as
  before. `HASH` list encoding still requires `polars`, since a Python
  fallback can't reproduce polars' hashes.

Behavior is preserved: `stats_` key names, the "contains null values …
consider imputing" errors, list-column encoding (flatten vs whole-list),
and
global cross-partition top-k semantics for `max_categories` are all
unchanged,
which the existing suites verify. Each fit is now a single
`Dataset.aggregate()` query per preprocessor with no driver-side merge.

The legacy helpers `compute_unique_value_indices` and
`_get_most_frequent_values` are removed; nothing uses them.

Behavior notes for reviewers:

- `ds.aggregate(Unique(...))` on a tensor column, or on a list column
without
  `polars` installed, now works instead of raising. This comes from the
  fallback above and benefits any `Unique` user, not only the encoders.
- Whole-list categories stay whole lists when merged from several
partial
  aggregates, with or without `polars` (see the new tests below).
- With `max_categories`, a null tied with a real value at the cut-off no
longer raises "contains null values": nulls now rank last, whereas the
old
path broke ties by insertion order. Otherwise it raises in the same
cases
  as before.
- Pre-existing and unchanged: a block that holds *only* null rows of a
list
column is typed `null` rather than `list`, so its nulls count as a value
and the fit raises. This depends on how rows are split into blocks, as
it
  did before this PR; I'll file a follow-up.

## Related issue number

N/A. Not a duplicate: searched open PRs/issues for encoder/imputer fit
work;
no overlap found (#66012 covers GPU transforms, not fitting).

Part 2 of 4 of the preprocessor fitting series (RFC: #66090). Part 1
(`TopKUnique`, #66087) has merged; parts 3 and 4 (#66091, #66092) build
on this.

## Checks

- [x] I've signed off every commit (DCO).
- [x] I've run pre-commit hooks — all hooks pass.
- [x] Testing (macOS / Python 3.12, source build):
- `pytest python/ray/data/tests/preprocessors/
--ignore=.../test_torch.py`
    (torch not installed) — 411 passed, 5 skipped, 0 failed
    (clean master at the same base: 392 passed). Includes
`test_preprocessors_arrow_backed.py`. Env matches CI pins (pandas 2.3.3,
    pyarrow 23.0.1, cloudpickle 3.1.1).
  - `pytest python/ray/data/tests/test_aggregations.py` — 62 passed
    (clean master: 57).
- New tests: encoders/imputer assert they register plan aggregators (no
callable stats); most_frequent never imputes null (including `None`,
`NaN`,
`pd.NA` and float32 `NaN`, even when they outnumber every real value);
deterministic tie-break; most_frequent picks the value from counts
summed
across blocks; whole-list categories
(`OrdinalEncoder(encode_lists=False)`,
    `OneHotEncoder`) stay whole lists when merged from several partial
aggregates; encoders fit tensor columns (whole arrays, flattened arrays,
    `max_categories`); whole-list encoding with and without `polars`;
`Unique` on tensor columns and on list columns without `polars`; `HASH`
    mode still requires `polars`; a null row in a list column adds no
    categories.

AI assistance was used to draft this change (Claude Code); every line
has been
reviewed by the submitter.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Abhishek Verma <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant