Repository navigation
[core][rdt] Support out-of-order actors by extracting metadata when creating - #59610
Conversation
…reating Signed-off-by: dayshah <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces significant refactoring to Ray Direct Transport (RDT) to support out-of-order actor method calls. The core change involves extracting RDT metadata at object creation time and sending it to the object's owner. This allows for queuing transfers if metadata is not yet available, which is handled by a new mechanism in the GPUObjectManager using condition variables and a transfer queue. The changes span across Python, Cython, and C++ layers and appear to be consistent and well-structured. I've identified one medium-severity issue related to timeout handling that could improve error reporting.
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
|
|
||
|
|
||
| def test_send_actor_dies(ray_start_regular): | ||
| def test_send_actor_dies_before_sending(ray_start_regular): |
There was a problem hiding this comment.
I'm making a follow up pr to fix when the sender dies before creating. Right now it'll result in a timeout instead of immediately realizing the upstream actor is dead. Before it relied on the get_metadata failing. Instead we should be failing the task from the C++ dependency resolver if the upstream task failed.
| ray.get(result) | ||
|
|
||
| assert "ActorDiedError" in str(excinfo.value) | ||
| assert "nixlBackendError" in str(excinfo.value) |
There was a problem hiding this comment.
It's a nixl error instead of actor died now because before we would fail in the recv on the ray.get(metadata_ref) and that would raise the ActorDiedError. Now we're failing when nixl tries to connect to the remote agent in the recv.
There was a problem hiding this comment.
Hmm can we catch the nixl error and throw ActorDiedError or at least an extra message saying that the remote actor may have died?
There was a problem hiding this comment.
I don't want to throw an ActorDiedError because it's possible it's just some nixl issue and the actor didn't actually die. But adding an rdt hint that the actor died makes sense, now I'm raising an RDT error with the hint and showing the nixl error, it looks like:
ray.exceptions.RayDirectTransportError: System error: The NIXL recv failed for object id: f4402ec78d3a260771ac7205b42681cfd83c156a0100000001000000. The source actor may have died during the transfer. The exception thrown from the nixl recv was:
Traceback (most recent call last):
File "/home/ubuntu/ray/python/ray/experimental/gpu_object_manager/nixl_tensor_transport.py", line 186, in recv_multiple_tensors
remote_name = nixl_agent.add_remote_agent(remote_nixl_agent_meta)
File "/opt/conda/envs/ray-dev/lib/python3.10/site-packages/nixl_cu12/_api.py", line 797, in add_remote_agent
agent_name = self.agent.loadRemoteMD(metadata)
nixl_cu12._bindings.nixlBackendError: NIXL_ERR_BACKEND
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
| ) | ||
|
|
||
| with self._lock: | ||
| # Since sent_dest_actors is mutable, this whole block needs to be protected. |
There was a problem hiding this comment.
this part is a bit funky, a couple alternatives are:
- Make the set a frozenset, but pay the cost of the set copy per transfer
- Have a separate map for the dest_actors stuff, and the map and everything in it needs to be accessed under the mutex
There was a problem hiding this comment.
Why the whole block and not just the first part where we update the metadata?
There was a problem hiding this comment.
the entire block does things that needs the lock
- update
dest_actorsin metadata - access
dest actorsin metadata (needs to be read under lock since dest actors is mutable) - update
sent_to_src_actor_and_others_warnedin metadata under if condition
I release the lock after 3
| @property | ||
| def gpu_object_store(self) -> "ray.experimental.GPUObjectStore": | ||
| with self.gpu_object_store_lock: | ||
| with self._lock: |
There was a problem hiding this comment.
Hmm I think it is clearer to have a separate lock for singletons vs the tensor metadata. Conceptually they are responsible for different state.
There was a problem hiding this comment.
I had it because I feel like having two locks kinda makes the person reading the code do an extra bit of thinking about possible deadlocks, but ya they are conceptually different, added a separate _init_lock
I do think the thread safetiness model is getting harder to think about than it should be with a couple locks here and a thread-safe queue and an extra lock in the gpu object store. Maybe worth simplifying or protecting the gpu_object_store through the gpu_object_manager or making them one class or something
| up transfers for the object. | ||
| """ | ||
| with self._tensor_transport_meta_cv: | ||
| self._managed_gpu_object_metadata[ |
There was a problem hiding this comment.
Check that the metadata is present in this dictionary before setting? I think GC could run before this method does.
There was a problem hiding this comment.
ya that's true, there's an extra io context post to this after CompletePendingTask too making it more possible, checking if it exists now
There was a problem hiding this comment.
Actually with the new free logic, this isn't possible anymore so not expecting it to exist again now
| if the tensor transport metadata is not available. | ||
| """ | ||
| with self._lock: | ||
| tensor_transport_meta = self._managed_gpu_object_metadata[ |
There was a problem hiding this comment.
Assert metadata is present.
There was a problem hiding this comment.
this will raise a KeyError here anyways if not present? And it always should be since this is only called when your passing a ref to a task
There was a problem hiding this comment.
Prefer assertions so it's clear it's a system bug, but it's okay.
| # TODO(#57962): Metadata is currently not removed on borrowers that borrow through | ||
| # the NIXL ray.put / ray.get | ||
| gpu_object_meta = self.pop_gpu_object_metadata(object_id) | ||
| if gpu_object_meta is None: |
There was a problem hiding this comment.
When can it be None?
There was a problem hiding this comment.
Ya this is only called on out of scope, which is guaranteed to only happen once rn since lineage reconstruction isn't possible. Removed the None block
|
|
||
| src_actor = ray.get_runtime_context().current_actor | ||
| self.gpu_object_store.add_object_primary(obj_ref.hex(), tensors) | ||
| tensor_transport_meta = self.gpu_object_store.add_object_primary( |
There was a problem hiding this comment.
Where is self defined?
There was a problem hiding this comment.
this is in put_object on gpu_object_manager, it isn't static? Or referring to something else?
There was a problem hiding this comment.
? Doesn't this need to remove @staticmethod for self to be defined?
There was a problem hiding this comment.
oh i think the git diff makes it look weird, the @staticmethod is added on actor_has_tensor_transport but this code is inside put_object
| ray.get(result) | ||
|
|
||
| assert "ActorDiedError" in str(excinfo.value) | ||
| assert "nixlBackendError" in str(excinfo.value) |
There was a problem hiding this comment.
Hmm can we catch the nixl error and throw ActorDiedError or at least an extra message saying that the remote actor may have died?
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
Signed-off-by: dayshah <[email protected]>
Problem
Resolves #56398
Today, RDT will launch a get_metadata task when you submit the task that creates an RDT object. This get_metadata task will run on the ray_system concurrency group until the object that it was launched for shows up in the gpu_object_store.
Out of order actors can deadlock when using RDT because the get_metadata tasks aren't ordered. Something like this could cause a deadlock:
Note that there are other possible deadlock scenarios for two-sided communication, but for now we're only supporting two-sided communicators for in-order actors.
Solution
We're now creating the metadata when the object is created, pickling it, and sending it back to the owner in the PushTaskReply. The metadata is now processed on the owner in
TaskManager::CompletePendingTask. From here, we'll call a callback into cython which will unpickle, get the gpu object manager, and add the tensor metadata for the object into the gpu object manager's_managed_gpu_object_metadatamap.If the metadata hasn't arrived at the time the user submits the downstream task, we'll queue the transfer instead of triggering it. When the tensor metadata arrives in the
_managed_gpu_object_metadatamap we'll trigger the transfer. When ray.getting the object through the tensor transport we'll first have a condition variable wait for the tensor metadata to arrive in the map. When ray.getting the RDT object through the object store, I made a change towait_and_get_objectinstead of just asserting it's there and getting (it would've worked before on in-order actors because the task to get through the object store would always be queued up after the get_metadata task).We'll do the same thing for freeing objects. If the tensor metadata hasn't arrived at the time we free, we'll queue up the free and then trigger the actual free once the tensor metadata comes in (once we know the object has actually been created). This does come with the caveat that if the object creation task doesn't successfully complete, we'll leak the object id inside this new
_queued_freesset.Now that
_managed_gpu_object_metadataand_queued_transferscan be accessed from the core worker io context thread or the user python thread, I'm putting them behind a lock. They're now only accessed through accessor functions that access them under the mutex. I'm also putting gpu_object_store initialization and gc thread initialization under the same mutex in the gpu object manager.Drawbacks
We're forcing cuda synchronization at the end of task execution for NIXL on gpu's because we're doing memory registration during ExecuteTask. This means that the actor's main thread will be blocked and will not start executing the next task (which could've been queueing up more kernels / gpu commands during this time) until the previous output has materialized. This could lead to the gpu being idle for the time between the execution of tasks, while it would've not been idle during that time before this change.
Borrowing and doing a ray.get doesn't work unless the object was created with a ray.put or the metadata arrived before the borrow. The metadata we send to the borrower might not have the tensor metadata if the owner doesn't have it at the time we serialize the ref. Today if the metadata hasn't arrived it'll be fine because we'll just send it as an object ref. We can fix this by sending the metadata in the GetObjectStatusReply which borrowers request from
RegisterOwnershipInfoAndResolveFuture.