Skip to content

[Data] Support GPU shuffle - #61371

Merged
alexeykudinkin merged 15 commits into
ray-project:masterfrom
leewyang:gpu_shuffle
Mar 17, 2026
Merged

alexeykudinkin merged 15 commits into
ray-project:masterfrom
leewyang:gpu_shuffle

Conversation

@leewyang

Copy link
Copy Markdown
Contributor

Description

This PR adds support for GPU-based shuffle using rapidsmpf shuffle (and building upon work from NeMo Curator team).

@leewyang
leewyang requested a review from a team as a code owner February 26, 2026 22:44
@leewyang
leewyang marked this pull request as draft February 26, 2026 22:44

@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 PR introduces GPU-based shuffle using rapidsmpf. The implementation is well-structured, adding a new GPUShuffleOperator, a GPUShuffleActor for GPU-specific work, and a rapidsmpf backend. The changes are integrated into the planner and DataContext. The test coverage is excellent, including both mocked unit tests and integration tests for real GPU environments.

I have a couple of suggestions. One is to align a default configuration value in DataContext with the new tests to provide a more sensible default behavior. The other is to consider removing some unused code from the adapted rapidsmpf backend to improve maintainability.

Comment thread python/ray/data/context.py Resolved
Comment thread python/ray/data/context.py Resolved
Comment on lines +226 to +229
_, root_address_bytes = ray.get(self._actors[0].setup_root.remote())
ray.get(
[actor.setup_worker.remote(root_address_bytes) for actor in self._actors]
)

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.

Is there a difference between https://docs.rapids.ai/api/rapidsmpf/stable/api/#module-rapidsmpf.shuffler setup_ray_ucxx_cluster and setting up the workers individually?

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.

Because GPUShuffleActor doesn't inherit from RapidsMPFActor (to avoid requiring GPU packages), [this check|https://github.com/rapidsai/rapidsmpf/blob/main/python/rapidsmpf/rapidsmpf/integrations/ray.py#L214-L217] fails, so ended up with this nearly identical code. Ideally, we should just use setup_ray_ucxx_cluster, but I'm not sure how to structure this otherwise.

# ---------------------------------------------------------------------------


class GPUShuffleOperator(PhysicalOperator, SubProgressBarMixin):

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.

This is a todo for me. Need to create an abstraction that allows us to share the shuffle lifecycle between CPU and GPU.

classDiagram
    class PhysicalOperator
    class SubProgressBarMixin

    class ShuffleOperatorCore {
      -engine: ShuffleEngine
      -state: ShuffleCoreState
      -hooks: ShuffleHooks
      +start(options)
      +_add_input_inner(bundle, input_index)
      +has_next()
      +_get_next_inner()
      +get_active_tasks()
      +has_completed()
      +current_logical_usage()
      +incremental_resource_usage()
      +_do_shutdown(force)
      +get_sub_progress_bar_names()
      +set_sub_progress_bar(name, pg)
      +get_stats()
    }

    class ShuffleEngine {
      <<interface>>
      +start()
      +submit_input(bundle, input_index)
      +try_finalize()
      +drain_ready_outputs() RefBundle[]
      +get_active_tasks() OpTask[]
      +has_completed() bool
      +base_resource_usage() ExecutionResources
      +incremental_resource_usage() ExecutionResources
      +shutdown(force)
      +debug_stats() dict
    }

    class CpuHashShuffleEngine
    class GpuShuffleEngine

    class ShuffleCoreState {
      +output_queue
      +shuffle_metrics
      +reduce_metrics
      +shuffle_bar
      +reduce_bar
      +shuffled_block_stats
      +output_block_stats
    }

    class ShuffleHooks {
      +on_output_ready(bundle)
      +on_task_submitted(...)
      +on_task_finished(...)
      +on_finalize_progress(...)
    }

    PhysicalOperator <|-- ShuffleOperatorCore
    SubProgressBarMixin <|-- ShuffleOperatorCore
    ShuffleOperatorCore *-- ShuffleCoreState
    ShuffleOperatorCore o-- ShuffleEngine
    ShuffleOperatorCore o-- ShuffleHooks
    ShuffleEngine <|.. CpuHashShuffleEngine
    ShuffleEngine <|.. GpuShuffleEngine
Loading

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.

#61636 is the refactored version


def _on_bundle_ready(bundle: RefBundle, rank: int = rank_idx) -> None:
self._output_queue.append(bundle)
self._reduce_metrics.on_output_queued(bundle)

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.

I believe we also need to call self._reduce_metrics.on_task_output_generated( task_index=partition_id, output=bundle ) which tracks outputs as they are streamed out from tasks

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.

Actually we should be able to reuse the _on_bundle_ready function in HashShufflingOperatorBase, which does this work already

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.

Re-used the code from HashShufflingOperatorBase.

self._extraction_tasks[rank_idx] = data_task

empty_bundle = RefBundle([], schema=None, owns_blocks=False)
self._reduce_metrics.on_task_submitted(

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.

I believe this call should be in _add_input_inner cause this is on task submission

task_index=task_idx,
object_ref=insert_ref,
task_done_callback=_on_insert_done,
task_resource_bundle=ExecutionResources(gpu=1),

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.

Does each insertion task need 1 GPU? That seems excessive, correct me if I'm wrong.

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.

This is apparently not actually used at the moment, so set it to None for now. That said, I think the whole resource tracking may still need more work.

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.

Added some code to improve gpu resource tracking.

@leewyang

leewyang commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor Author

@goutamvenkat-anyscale Thanks for the review! I've updated the code accordingly.

Signed-off-by: Lee Yang <[email protected]>

from typing import TYPE_CHECKING, Any, Literal

import cudf

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.

@goutamvenkat-anyscale
goutamvenkat-anyscale marked this pull request as ready for review March 10, 2026 18:18
@goutamvenkat-anyscale goutamvenkat-anyscale changed the title [DRAFT] Support GPU shuffle [Data] Support GPU shuffle Mar 10, 2026
@goutamvenkat-anyscale goutamvenkat-anyscale added the data Ray Data-related issues label Mar 10, 2026
@goutamvenkat-anyscale goutamvenkat-anyscale added the go add ONLY when ready to merge, run all tests label Mar 16, 2026

@alexeykudinkin alexeykudinkin 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, minor comments

Comment on lines +234 to +237
_, root_address_bytes = ray.get(self._actors[0].setup_root.remote())
ray.get(
[actor.setup_worker.remote(root_address_bytes) for actor in self._actors]
)

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.

@goutamvenkat-anyscale let's

  • Print more telemetry regarding us setting up UCXX group
  • Add timeouts to avoid hanging up forever

Comment on lines +426 to +431
# Fire-and-forget: Ray serialises actor tasks per actor, so
# insert_finished is guaranteed to run before extract_partitions.
actor.insert_finished.remote()
block_gen = actor.extract_partitions.options(
num_returns="streaming"
).remote()

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.

This is assuming that we're not gonna allow out-of-order execution for the actors (which we might).

Instead of this fire-and forget let's just combine these methods into 1

@goutamvenkat-anyscale

Signed-off-by: Goutam <[email protected]>
Signed-off-by: Goutam <[email protected]>
Signed-off-by: Goutam <[email protected]>
Signed-off-by: Goutam <[email protected]>
except Exception:
return None
finally:
pynvml.nvmlShutdown()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Finally block crashes when pynvml import fails

High Severity

get_device_free_memory is designed to gracefully return None on any failure via except Exception: return None, but the finally block unconditionally calls pynvml.nvmlShutdown(). If import pynvml fails (e.g., package not installed), the name pynvml is undefined, causing a NameError in the finally block. In Python, an exception raised in finally replaces the pending return None, so the function crashes with NameError instead of gracefully returning None. Similarly, if pynvml.nvmlInit() fails, calling nvmlShutdown() on an uninitialized library may also raise and mask the original error.

Fix in Cursor Fix in Web

Signed-off-by: Goutam <[email protected]>

@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 and found 1 potential issue.

Fix All in Cursor

except Exception:
return None
finally:
pynvml.nvmlShutdown()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

finally block crashes when pynvml import fails

High Severity

The finally block unconditionally calls pynvml.nvmlShutdown(), but if import pynvml on line 34 fails (e.g., package not installed), pynvml is not defined. The except Exception block catches the ImportError and attempts to return None, but the finally block runs afterward and raises a NameError, which replaces the intended return None. This defeats the function's fault-tolerant design. The same issue occurs if pynvml.nvmlInit() itself raises before NVML is initialized — calling nvmlShutdown() on an uninitialized library can also fail.

Fix in Cursor Fix in Web

@alexeykudinkin
alexeykudinkin merged commit 770dca3 into ray-project:master Mar 17, 2026
3 checks passed
goutamvenkat-anyscale pushed a commit that referenced this pull request Mar 26, 2026
## Description
This PR adds support for rapidsmpf 26.02, which had a breaking API
change.

## Related issues
Related to #61371

---------

Signed-off-by: Lee Yang <[email protected]>
goutamvenkat-anyscale added a commit that referenced this pull request Apr 21, 2026
## Description
This PR enables GPU_SHUFFLE in grouped_data.py, i.e. `groupby()`. The
`map_groups()` is still left on CPU for now.

## Related issues
Related to #61371

## Additional information
- Also adds `should_sort` argument to the GPU shuffle path so the groups
are correctly ordered.
- Fixes a bug in test_gpu_shuffle.py

---------

Signed-off-by: Lee Yang <[email protected]>
Co-authored-by: Goutam <[email protected]>
HLDKNotFound pushed a commit to chichic21039/ray that referenced this pull request Apr 22, 2026
## Description
This PR enables GPU_SHUFFLE in grouped_data.py, i.e. `groupby()`. The
`map_groups()` is still left on CPU for now.

## Related issues
Related to ray-project#61371

## Additional information
- Also adds `should_sort` argument to the GPU shuffle path so the groups
are correctly ordered.
- Fixes a bug in test_gpu_shuffle.py

---------

Signed-off-by: Lee Yang <[email protected]>
Co-authored-by: Goutam <[email protected]>
@leewyang
leewyang deleted the gpu_shuffle branch May 6, 2026 21:52
Lucas61000 pushed a commit to Lucas61000/ray that referenced this pull request May 15, 2026
Lucas61000 pushed a commit to Lucas61000/ray that referenced this pull request May 15, 2026
## Description
This PR adds support for rapidsmpf 26.02, which had a breaking API
change.

## Related issues
Related to ray-project#61371

---------

Signed-off-by: Lee Yang <[email protected]>
Lucas61000 pushed a commit to Lucas61000/ray that referenced this pull request May 15, 2026
## Description
This PR enables GPU_SHUFFLE in grouped_data.py, i.e. `groupby()`. The
`map_groups()` is still left on CPU for now.

## Related issues
Related to ray-project#61371

## Additional information
- Also adds `should_sort` argument to the GPU shuffle path so the groups
are correctly ordered.
- Fixes a bug in test_gpu_shuffle.py

---------

Signed-off-by: Lee Yang <[email protected]>
Co-authored-by: Goutam <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants