As soon as I use ray.cloudpickle.dumps/loads methods, the error about Ray Client is not connected
is reported.
Ray Client is not connected. Please connect by calling `ray.init`.
Env: a ray cluster (head with 2 workers) on k3s installed with ray operator. Code is run from a juypyter notebook on the ray head.
In contrast, running similar code on a local machine ray does not have issue using ray.cloudpickle methods.
Here’s the serve deployment. In the current state, it produces the error. If I comment out the lines with cloudpickle and run the ones with ray.get/put - no problems.
import ray
from ray import serve
import json
# Connect to cluster
try:
# runtime_env = {"pip":["ruptures","pathos"]}
ray_client = ray.init(f"ray://localhost:10001", namespace="serve")
except Exception as e:
print("Exception",e)
pass
finally:
print("Ray serve started")
client = serve.start(detached=True, http_options={"host": "0.0.0.0"})
@serve.deployment(route_prefix="/lastchunker")
class LastChunker:
async def __call__(self, request):
try:
raw_json = await request.json()
id_str = raw_json.get('store_id')
id_pkld = base64.b64decode(id_str.encode())
id_restored = ray.cloudpickle.loads(id_pkld)
ray_data = ray.get(id_restored
# one = ray.put(1)
return {"ray_data": ray_data}
# return {"ray_data": ray.get(one)}
except Exception as ex:
return {"error": ex}
LastChunker.deploy()
Here is the calling code:
import requests
import base64
f = ray.put("foo")
print(f"f: {f}")
fpikl = ray.cloudpickle.dumps(f)
print(f"fpikl: {fpikl}")
b64fpkl = base64.b64encode(fpikl).decode()
print(f"b64fpkl: {b64fpkl}")
data='{"store_id": "' + f"{b64fpkl}" +'"}'
print(f"data: {data}")
id_str = json.loads(data).get('store_id')
print (f"id_str: {id_str}")
id_pkld = base64.b64decode(id_str.encode())
print(f"id_pkld: {id_pkld}")
id_restored = ray.cloudpickle.loads(id_pkld)
print(f"id_restored: {id_restored}")
resp = requests.get("http://localhost:8000/lastchunker", data=data)
resp.json()