def __init__(self): if not os.path.exists(file_path): with open(file_path, "w") as f: # Write first replica tag to local file so that it will # consistently fail even retried on other actor f.write(serve.get_replica_context().replica_tag) raise RuntimeError( "Consistently throwing on same replica.") else: with open(file_path) as f: content = f.read() if content == serve.get_replica_context().replica_tag: raise RuntimeError( "Consistently throwing on same replica.") else: return True
def __init__(self, checkpoint_bytes, checkpoint_tune_meta_bytes): replica_tag = serve.get_replica_context().replica_tag # Cache the checkpoint file locally. checkpoint_path = f"/tmp/checkpoint-{replica_tag}" checkpoint_tune_meta_path = f"/tmp/checkpoint-{replica_tag}.tune_metadata" with open(checkpoint_path, "wb") as f: f.write(checkpoint_bytes) with open(checkpoint_tune_meta_path, "wb") as f: f.write(checkpoint_tune_meta_bytes) # Restore the trainer. self.agent = restore_trainer(checkpoint_path)
def get_current_servable_instance(): from ray import serve return serve.get_replica_context().servable_object
def hello(): return serve.get_replica_context().deployment
def __call__(self, *args): return serve.get_replica_context().replica_tag
def other_method(self, *args): return serve.get_replica_context().replica_tag
def fn(*args): logger.info("user log message") return serve.get_replica_context().replica_tag