Repository navigation
[Data] Support GPU shuffle - #61371
Conversation
Signed-off-by: Lee Yang <[email protected]>
Signed-off-by: Lee Yang <[email protected]>
There was a problem hiding this comment.
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.
…sMPFShuffler Signed-off-by: Lee Yang <[email protected]>
Signed-off-by: Lee Yang <[email protected]>
| _, 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] | ||
| ) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
|
|
||
| def _on_bundle_ready(bundle: RefBundle, rank: int = rank_idx) -> None: | ||
| self._output_queue.append(bundle) | ||
| self._reduce_metrics.on_output_queued(bundle) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Actually we should be able to reuse the _on_bundle_ready function in HashShufflingOperatorBase, which does this work already
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
Does each insertion task need 1 GPU? That seems excessive, correct me if I'm wrong.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Added some code to improve gpu resource tracking.
Signed-off-by: Lee Yang <[email protected]>
|
@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 |
There was a problem hiding this comment.
We'll have to lazy import this cause otherwise it will doctests:
https://buildkite.com/ray-project/microcheck/builds/39988#019cbb28-26d7-4bca-98e8-fdc78f7b4a01
Signed-off-by: Lee Yang <[email protected]>
Signed-off-by: Lee Yang <[email protected]>
alexeykudinkin
left a comment
There was a problem hiding this comment.
LGTM, minor comments
| _, 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] | ||
| ) |
There was a problem hiding this comment.
@goutamvenkat-anyscale let's
- Print more telemetry regarding us setting up UCXX group
- Add timeouts to avoid hanging up forever
| # 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() |
There was a problem hiding this comment.
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
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() |
There was a problem hiding this comment.
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.
Signed-off-by: Goutam <[email protected]>
| except Exception: | ||
| return None | ||
| finally: | ||
| pynvml.nvmlShutdown() |
There was a problem hiding this comment.
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.
## 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]>
## 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]>
## 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]>
## 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]>
## 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]>


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