Skip to content

[core][gpu-objects] Support ray.get on the driver process for GPU objects#53902

Merged
jjyao merged 7 commits intoray-project:masterfrom
kevin85421:20250616-devbox1-tmux1-ray1
Jun 19, 2025
Merged

[core][gpu-objects] Support ray.get on the driver process for GPU objects#53902
jjyao merged 7 commits intoray-project:masterfrom
kevin85421:20250616-devbox1-tmux1-ray1

Conversation

@kevin85421
Copy link
Copy Markdown
Member

@kevin85421 kevin85421 commented Jun 17, 2025

Why are these changes needed?

If an object ID exists in gpu_object_ref, it means that the driver is attempting to fetch the GPU objects. In that case, tensors will not be transferred out of band. Instead, we need to transfer the tensors via object store.

Related issue number

Closes #51272

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: kaihsun <kaihsun@anyscale.com>
@kevin85421 kevin85421 added the go add ONLY when ready to merge, run all tests label Jun 17, 2025
@kevin85421 kevin85421 marked this pull request as ready for review June 18, 2025 03:31
Copilot AI review requested due to automatic review settings June 18, 2025 03:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables the driver process to use ray.get on GPU-backed object references by fetching tensors through the object store rather than out-of-band transfers.

  • Added a new end-to-end test covering driver-side GPU object fetch.
  • Extended _deserialize_pickle5_data to detect driver-managed GPU objects and trigger a fetch.
  • Augmented GPUObjectManager with an is_driver check, an obj_idObjectRef mapping, and a fetch_gpu_object helper.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
python/ray/tests/test_gpu_objects_gloo.py Added test_fetch_gpu_object_to_driver covering single, multiple, and mixed CPU/GPU cases.
python/ray/_private/serialization.py Updated deserialization to call fetch_gpu_object when the driver process owns the object.
python/ray/_private/gpu_object_manager_util.py Introduced __ray_fetch_gpu_object__ to pull tensors via the object store.
python/ray/_private/gpu_object_manager.py Added gpu_object_id_to_obj_ref mapping, is_driver, and fetch_gpu_object.
Comments suppressed due to low confidence (2)

python/ray/_private/serialization.py:280

  • [nitpick] The variable name enable_gpu_objects is ambiguous. It might be clearer to rename it to should_handle_gpu_object or is_gpu_object_relevant to better reflect its boolean purpose.
        enable_gpu_objects = gpu_object_manager.has_gpu_object(

python/ray/_private/gpu_object_manager.py:185

  • The symbol util is not imported in this file, so util.__ray_fetch_gpu_object__ will raise a NameError. Add import ray._private.gpu_object_manager_util as util or reference the function directly.
        tensors = ray.get(

obj_ref = self.gpu_object_id_to_obj_ref[obj_id]
gpu_object_meta = self.gpu_object_refs[obj_ref]
src_actor = gpu_object_meta.src_actor
tensors = ray.get(
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.

Instead of caching the raw tensors (which will occupy memory and can cause OOM), let's cache the ObjectRef returned by ray_fetch_gpu_object.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  • serialization.py: The object will be immediately removed by remove_gpu_object.

    if enable_gpu_objects:
        if gpu_object_manager.is_driver(object_id):
            gpu_object_manager.fetch_gpu_object(object_id)
        tensors = gpu_object_manager.get_gpu_object(object_id)
        ctx.reset_out_of_band_tensors(tensors)
        # TODO(kevin85421): The current garbage collection implementation for the in-actor object store
        # is naive. We garbage collect each object after it is consumed once.
        gpu_object_manager.remove_gpu_object(object_id)

Signed-off-by: kaihsun <kaihsun@anyscale.com>
Signed-off-by: kaihsun <kaihsun@anyscale.com>
Co-authored-by: Stephanie Wang <swang@cs.berkeley.edu>
Signed-off-by: Kai-Hsun Chen <kaihsun@apache.org>
Signed-off-by: kaihsun <kaihsun@anyscale.com>
Signed-off-by: kaihsun <kaihsun@anyscale.com>
@kevin85421
Copy link
Copy Markdown
Member Author

cc @jjyao @stephanie-wang @edoakes would you mind merging this PR? Thanks!

@jjyao jjyao merged commit addab25 into ray-project:master Jun 19, 2025
5 checks passed
minerharry pushed a commit to minerharry/ray that referenced this pull request Jun 27, 2025
…bjects (ray-project#53902)

Signed-off-by: kaihsun <kaihsun@anyscale.com>
Signed-off-by: Kai-Hsun Chen <kaihsun@apache.org>
Co-authored-by: Stephanie Wang <swang@cs.berkeley.edu>
elliot-barn pushed a commit that referenced this pull request Jul 2, 2025
…bjects (#53902)

Signed-off-by: kaihsun <kaihsun@anyscale.com>
Signed-off-by: Kai-Hsun Chen <kaihsun@apache.org>
Co-authored-by: Stephanie Wang <swang@cs.berkeley.edu>
Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[core][gpu-objects] Driver tries to get the data from in-actor store

6 participants