Beispiel #1
0
 def get_actor(self, name: str) -> ClientActorHandle:
     task = ray_client_pb2.ClientTask()
     task.type = ray_client_pb2.ClientTask.NAMED_ACTOR
     task.name = name
     ids = self._call_schedule_for_task(task)
     assert len(ids) == 1
     return ClientActorHandle(ClientActorRef(ids[0]))
Beispiel #2
0
def chunk_task(req: ray_client_pb2.DataRequest):
    """
    Chunks a client task. Doing this lazily is important with large arguments,
    since taking slices of bytes objects does a copy. This means if we
    immediately materialized every chunk of a large argument and inserted them
    into the result_queue, we would effectively double the memory needed
    on the client to handle the task.
    """
    total_size = len(req.task.data)
    assert total_size > 0, "Cannot chunk object with missing data"
    total_chunks = math.ceil(total_size / OBJECT_TRANSFER_CHUNK_SIZE)
    for chunk_id in range(0, total_chunks):
        start = chunk_id * OBJECT_TRANSFER_CHUNK_SIZE
        end = min(total_size, (chunk_id + 1) * OBJECT_TRANSFER_CHUNK_SIZE)
        chunk = ray_client_pb2.ClientTask(
            type=req.task.type,
            name=req.task.name,
            payload_id=req.task.payload_id,
            client_id=req.task.client_id,
            options=req.task.options,
            baseline_options=req.task.baseline_options,
            namespace=req.task.namespace,
            data=req.task.data[start:end],
            chunk_id=chunk_id,
            total_chunks=total_chunks,
        )
        yield ray_client_pb2.DataRequest(req_id=req.req_id, task=chunk)
Beispiel #3
0
 def _prepare_client_task(self) -> ray_client_pb2.ClientTask:
     self._ensure_ref()
     task = ray_client_pb2.ClientTask()
     task.type = ray_client_pb2.ClientTask.FUNCTION
     task.name = self._name
     task.payload_id = self._ref.id
     return task
Beispiel #4
0
 def _prepare_client_task(self) -> ray_client_pb2.ClientTask:
     self._ensure_ref()
     task = ray_client_pb2.ClientTask()
     task.type = ray_client_pb2.ClientTask.ACTOR
     task.name = self._name
     task.payload_id = self._ref.id
     set_task_options(task, self._options, "baseline_options")
     return task
Beispiel #5
0
 def _prepare_client_task(self) -> ray_client_pb2.ClientTask:
     if self._ref is None:
         self._ref = ray.put(self._func)
     task = ray_client_pb2.ClientTask()
     task.type = ray_client_pb2.ClientTask.FUNCTION
     task.name = self._name
     task.payload_id = self._ref.handle
     return task
Beispiel #6
0
 def _prepare_client_task(self) -> ray_client_pb2.ClientTask:
     if self._ref is None:
         self._ref = ray.put(self.actor_cls)
     task = ray_client_pb2.ClientTask()
     task.type = ray_client_pb2.ClientTask.ACTOR
     task.name = self._name
     task.payload_id = self._ref.handle
     return task
Beispiel #7
0
 def get_actor(self, name: str,
               namespace: Optional[str] = None) -> ClientActorHandle:
     task = ray_client_pb2.ClientTask()
     task.type = ray_client_pb2.ClientTask.NAMED_ACTOR
     task.name = name
     task.namespace = namespace or ""
     ids = self._call_schedule_for_task(task, num_returns=1)
     assert len(ids) == 1
     return ClientActorHandle(ClientActorRef(ids[0]))
Beispiel #8
0
 def call_remote(self, func, *args, **kwargs):
     if not isinstance(func, ClientRemoteFunc):
         raise TypeError("Client not passing a ClientRemoteFunc stub")
     func_ref = self._put(func)
     task = ray_client_pb2.ClientTask()
     task.name = func._name
     task.payload_id = func_ref.id
     for arg in args:
         pb_arg = convert_to_arg(arg)
         task.args.append(pb_arg)
     ticket = self.server.Schedule(task)
     return ClientObjectRef(ticket.return_id)
 def _call_method(self, instance: ClientRemoteMethod, *args, **kwargs):
     if not isinstance(instance, ClientRemoteMethod):
         raise TypeError("Client not passing a ClientRemoteMethod stub")
     task = ray_client_pb2.ClientTask()
     task.type = ray_client_pb2.ClientTask.METHOD
     task.name = instance.method_name
     task.payload_id = instance.actor_handle.actor_id.id
     for arg in args:
         pb_arg = convert_to_arg(arg)
         task.args.append(pb_arg)
     ticket = self.server.Schedule(task, metadata=self.metadata)
     return ticket
Beispiel #10
0
 def get_actor(self,
               name: str,
               namespace: Optional[str] = None) -> ClientActorHandle:
     task = ray_client_pb2.ClientTask()
     task.type = ray_client_pb2.ClientTask.NAMED_ACTOR
     task.name = name
     task.namespace = namespace or ""
     futures = self._call_schedule_for_task(task, 1)
     assert len(futures) == 1
     handle = ClientActorHandle(ClientActorRef(futures[0]))
     # `actor_ref.is_nil()` waits until the underlying ID is resolved.
     # This is needed because `get_actor` is often used to check the
     # existence of an actor.
     if handle.actor_ref.is_nil():
         raise ValueError(f"ActorID for {name} is empty")
     return handle
Beispiel #11
0
 def _put_and_schedule(self, item, task_type, *args, **kwargs):
     if isinstance(item, ClientRemoteFunc):
         ref = self._put(item)
     elif isinstance(item, ClientActorClass):
         ref = self._put(item.actor_cls)
     else:
         raise TypeError("Client not passing a ClientRemoteFunc stub")
     task = ray_client_pb2.ClientTask()
     task.type = task_type
     task.name = item._name
     task.payload_id = ref.id
     for arg in args:
         pb_arg = convert_to_arg(arg)
         task.args.append(pb_arg)
     ticket = self.server.Schedule(task, metadata=self.metadata)
     return ticket
Beispiel #12
0
 def _prepare_client_task(self) -> ray_client_pb2.ClientTask:
     task = ray_client_pb2.ClientTask()
     task.type = ray_client_pb2.ClientTask.METHOD
     task.name = self._method_name
     task.payload_id = self._actor_handle.actor_ref.id
     return task