Skip to content

[DONOTMERGE] POC for Ray+torch.distributed - #51078

Closed
stephanie-wang wants to merge 11 commits into
ray-project:masterfrom
stephanie-wang:ray-gpu
Closed

stephanie-wang wants to merge 11 commits into
ray-project:masterfrom
stephanie-wang:ray-gpu

Conversation

@stephanie-wang

Copy link
Copy Markdown
Contributor

Why are these changes needed?

Related issue number

Checks

Signed-off-by: Stephanie wang <[email protected]>
Signed-off-by: Stephanie wang <[email protected]>
Signed-off-by: Stephanie wang <[email protected]>
Signed-off-by: Stephanie wang <[email protected]>
Signed-off-by: Stephanie wang <[email protected]>
Signed-off-by: Stephanie wang <[email protected]>
@stephanie-wang
stephanie-wang requested review from a team, pcmoritz and raulchen as code owners March 4, 2025 23:32

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

just note for myself.

Comment thread dev/test_gpu.py

if __name__ == "__main__":
actors = [Actor.remote() for _ in range(WORLD_SIZE)]
ray.get([a.ping.remote() for a in actors])

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.

doesn't need

Comment thread dev/test_gpu.py
init_method = "tcp://localhost:8889"
ray.get([actor.setup.remote(WORLD_SIZE, rank, init_method) for rank, actor in enumerate(actors)])
actor_ids = [actor._ray_actor_id for actor in actors]
ray._private.worker.global_worker.core_worker.register_actor_nccl_group(actor_ids)

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.

driver knows the (actor id -> rank) mapping

Comment thread dev/test_gpu.py

shape = (100, )

ref = actors[0].randn.remote(shape)

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.

actors[0] is sender, and actors[1] is receiver.

Comment thread python/ray/_raylet.pyx
@@ -4362,6 +4423,8 @@ cdef class CoreWorker:
task_output_inlined_bytes = 0
i = -1
for i, output in enumerate(outputs):

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.

Step 1: after the sender finishes task executions, it needs to handle the output. If the output is tensor,

(1) Store the tensor in in_actor_object_store.
(2) Return RayActorObjectMetadata to driver and only serialize the RayActorObjectMetadata (shape, dtype, src_rank, obj_id(?))
(3) Return error code OBJECT_IN_ACTOR.

Comment thread python/ray/_raylet.pyx Outdated
# Replace with OBJECT_IN_ACTOR metadata, so that the driver can
# see that this object is actually stored on the actor.
metadata_str = str(ray.core.generated.common_pb2.ErrorType.OBJECT_IN_ACTOR)
# TODO:

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.

this is outdated

else:
actor_id = None
return ActorUnavailableError(error_info.error_message, actor_id)
elif error_type == ErrorType.Value(

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.

The receiver task execution handler reads the data from in_actor_object_store which is NCCL recv by fetch_p2p_dependency_handler.

Comment thread python/ray/_raylet.pyx
self._task_id_to_future = {}
self.event_loop_executor = None

def register_actor_nccl_group(self, actor_ids):

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.

Used in test_gpu.py. This should not be called by users in the future.

std::unordered_map<ObjectID, std::shared_ptr<Buffer>> TaskSpecification::GetInActorDependenciesMetadata() const {
std::unordered_map<ObjectID, std::shared_ptr<Buffer>> deps;
for (const auto &dep : message_->in_actor_dependencies()) {
deps[ObjectID::FromBinary(dep.object_id())] = std::make_shared<LocalMemoryBuffer>(reinterpret_cast<const uint8_t *>(dep.metadata().data()), dep.metadata().size());

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.

metadata = RayActorObjectMetadata

const auto it = in_actor_dependencies_metadata.find(task.ArgId(i));
RAY_CHECK(it != in_actor_dependencies_metadata.end());
data = it->second;
metadata = std::make_shared<LocalMemoryBuffer>(const_cast<uint8_t *>(task.ArgMetadata(i)),

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.

RayActorObjectMetadata this is passed to task_execution_handler by args, and then Cython can use the src_rank from metadata to call NCCL recv.

RAY_LOG(INFO) << "Adding IN_ACTOR dep " << id << " to task " << task.TaskId();
// Add the IN_ACTOR error as the metadata value.
RAY_CHECK(it->second->HasMetadata());
const auto &metadata = it->second->GetMetadata();

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.

Metadata here is OBJECT_IN_ACTOR, and the data is RayActorObjectMetadata. This is called by driver.

Signed-off-by: Stephanie wang <[email protected]>
@stale

stale Bot commented Apr 26, 2025

Copy link
Copy Markdown

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

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

@stale stale Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Apr 26, 2025
@stale stale Bot removed the stale The issue is stale. It will be closed within 7 days unless there are further conversation label May 22, 2025
@github-actions

github-actions Bot commented Jun 6, 2025

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 Jun 6, 2025
@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 Jun 21, 2025
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.

3 participants