mirror of
https://github.com/wassname/ray.git
synced 2026-07-03 15:27:36 +08:00
Refactor code about ray.ObjectID. (#3674)
* Refactor code about ray.ObjectID. * remove from_random and use nil_id instead of constructor * remove id() in hash * Lint and fix * Change driver id to ObjectID * Replace binary_to_hex(ObjectID.id()) to ObjectID.hex()
This commit is contained in:
committed by
Philipp Moritz
parent
c4b058739b
commit
d2cf8561f2
+17
-19
@@ -17,6 +17,7 @@ import ray.ray_constants as ray_constants
|
||||
import ray.signature as signature
|
||||
import ray.worker
|
||||
from ray.utils import _random_string
|
||||
from ray import ObjectID
|
||||
|
||||
DEFAULT_ACTOR_METHOD_NUM_RETURN_VALS = 1
|
||||
|
||||
@@ -41,8 +42,7 @@ def compute_actor_handle_id(actor_handle_id, num_forks):
|
||||
handle_id_hash.update(actor_handle_id.id())
|
||||
handle_id_hash.update(str(num_forks).encode("ascii"))
|
||||
handle_id = handle_id_hash.digest()
|
||||
assert len(handle_id) == ray_constants.ID_SIZE
|
||||
return ray.ObjectID(handle_id)
|
||||
return ObjectID(handle_id)
|
||||
|
||||
|
||||
def compute_actor_handle_id_non_forked(actor_handle_id, current_task_id):
|
||||
@@ -69,8 +69,7 @@ def compute_actor_handle_id_non_forked(actor_handle_id, current_task_id):
|
||||
handle_id_hash.update(actor_handle_id.id())
|
||||
handle_id_hash.update(current_task_id.id())
|
||||
handle_id = handle_id_hash.digest()
|
||||
assert len(handle_id) == ray_constants.ID_SIZE
|
||||
return ray.ObjectID(handle_id)
|
||||
return ObjectID(handle_id)
|
||||
|
||||
|
||||
def set_actor_checkpoint(worker, actor_id, checkpoint_index, checkpoint,
|
||||
@@ -84,7 +83,7 @@ def set_actor_checkpoint(worker, actor_id, checkpoint_index, checkpoint,
|
||||
checkpoint: The state object to save.
|
||||
frontier: The task frontier at the time of the checkpoint.
|
||||
"""
|
||||
actor_key = b"Actor:" + actor_id
|
||||
actor_key = b"Actor:" + actor_id.id()
|
||||
worker.redis_client.hmset(
|
||||
actor_key, {
|
||||
"checkpoint_index": checkpoint_index,
|
||||
@@ -110,7 +109,7 @@ def save_and_log_checkpoint(worker, actor):
|
||||
worker,
|
||||
ray_constants.CHECKPOINT_PUSH_ERROR,
|
||||
traceback_str,
|
||||
driver_id=worker.task_driver_id.id(),
|
||||
driver_id=worker.task_driver_id,
|
||||
data={
|
||||
"actor_class": actor.__class__.__name__,
|
||||
"function_name": actor.__ray_checkpoint__.__name__
|
||||
@@ -134,7 +133,7 @@ def restore_and_log_checkpoint(worker, actor):
|
||||
worker,
|
||||
ray_constants.CHECKPOINT_PUSH_ERROR,
|
||||
traceback_str,
|
||||
driver_id=worker.task_driver_id.id(),
|
||||
driver_id=worker.task_driver_id,
|
||||
data={
|
||||
"actor_class": actor.__class__.__name__,
|
||||
"function_name": actor.__ray_checkpoint_restore__.__name__
|
||||
@@ -156,7 +155,7 @@ def get_actor_checkpoint(worker, actor_id):
|
||||
exists, all objects are set to None. The checkpoint index is the .
|
||||
executed on the actor before the checkpoint was made.
|
||||
"""
|
||||
actor_key = b"Actor:" + actor_id
|
||||
actor_key = b"Actor:" + actor_id.id()
|
||||
checkpoint_index, checkpoint, frontier = worker.redis_client.hmget(
|
||||
actor_key, ["checkpoint_index", "checkpoint", "frontier"])
|
||||
if checkpoint_index is not None:
|
||||
@@ -371,7 +370,7 @@ class ActorClass(object):
|
||||
raise Exception("Actors cannot be created before ray.init() "
|
||||
"has been called.")
|
||||
|
||||
actor_id = ray.ObjectID(_random_string())
|
||||
actor_id = ObjectID(_random_string())
|
||||
# The actor cursor is a dummy object representing the most recent
|
||||
# actor method invocation. For each subsequent method invocation,
|
||||
# the current cursor should be added as a dependency, and then
|
||||
@@ -509,8 +508,7 @@ class ActorHandle(object):
|
||||
# if it was created by the _serialization_helper function.
|
||||
self._ray_original_handle = actor_handle_id is None
|
||||
if self._ray_original_handle:
|
||||
self._ray_actor_handle_id = ray.ObjectID(
|
||||
ray.worker.NIL_ACTOR_HANDLE_ID)
|
||||
self._ray_actor_handle_id = ObjectID.nil_id()
|
||||
else:
|
||||
self._ray_actor_handle_id = actor_handle_id
|
||||
self._ray_actor_cursor = actor_cursor
|
||||
@@ -713,7 +711,7 @@ class ActorHandle(object):
|
||||
# to release, since it could be unpickled and submit another
|
||||
# dependent task at any time. Therefore, we notify the backend of a
|
||||
# random handle ID that will never actually be used.
|
||||
new_actor_handle_id = ray.ObjectID(_random_string())
|
||||
new_actor_handle_id = ObjectID(_random_string())
|
||||
# Notify the backend to expect this new actor handle. The backend will
|
||||
# not release the cursor for any new handles until the first task for
|
||||
# each of the new handles is submitted.
|
||||
@@ -735,7 +733,7 @@ class ActorHandle(object):
|
||||
worker.check_connected()
|
||||
|
||||
if state["ray_forking"]:
|
||||
actor_handle_id = ray.ObjectID(state["actor_handle_id"])
|
||||
actor_handle_id = ObjectID(state["actor_handle_id"])
|
||||
else:
|
||||
# Right now, if the actor handle has been pickled, we create a
|
||||
# temporary actor handle id for invocations.
|
||||
@@ -749,22 +747,22 @@ class ActorHandle(object):
|
||||
# same actor is likely a performance bug. We should consider
|
||||
# logging a warning in these cases.
|
||||
actor_handle_id = compute_actor_handle_id_non_forked(
|
||||
ray.ObjectID(state["actor_handle_id"]), worker.current_task_id)
|
||||
ObjectID(state["actor_handle_id"]), worker.current_task_id)
|
||||
|
||||
# This is the driver ID of the driver that owns the actor, not
|
||||
# necessarily the driver that owns this actor handle.
|
||||
actor_driver_id = ray.ObjectID(state["actor_driver_id"])
|
||||
actor_driver_id = ObjectID(state["actor_driver_id"])
|
||||
|
||||
self.__init__(
|
||||
ray.ObjectID(state["actor_id"]),
|
||||
ObjectID(state["actor_id"]),
|
||||
state["module_name"],
|
||||
state["class_name"],
|
||||
ray.ObjectID(state["actor_cursor"])
|
||||
ObjectID(state["actor_cursor"])
|
||||
if state["actor_cursor"] is not None else None,
|
||||
state["actor_method_names"],
|
||||
state["method_signatures"],
|
||||
state["method_num_return_vals"],
|
||||
ray.ObjectID(state["actor_creation_dummy_object_id"])
|
||||
ObjectID(state["actor_creation_dummy_object_id"])
|
||||
if state["actor_creation_dummy_object_id"] is not None else None,
|
||||
state["actor_method_cpus"],
|
||||
actor_driver_id,
|
||||
@@ -843,7 +841,7 @@ def make_actor(cls, num_cpus, num_gpus, resources, actor_method_cpus,
|
||||
# scheduler has seen. Handle IDs for which no task has yet reached
|
||||
# the local scheduler will not be included, and may not be runnable
|
||||
# on checkpoint resumption.
|
||||
actor_id = ray.ObjectID(worker.actor_id)
|
||||
actor_id = worker.actor_id
|
||||
frontier = worker.raylet_client.get_actor_frontier(actor_id)
|
||||
# Save the checkpoint in Redis. TODO(rkn): Checkpoints
|
||||
# should not be stored in Redis. Fix this.
|
||||
|
||||
Reference in New Issue
Block a user