mirror of
https://github.com/wassname/ray.git
synced 2026-07-21 12:50:45 +08:00
[tune] Better Serialization for Server (#3708)
* Add cloudpickle for serialization * Fix tests
This commit is contained in:
@@ -7,8 +7,10 @@ import logging
|
||||
import sys
|
||||
import threading
|
||||
|
||||
import ray.cloudpickle as cloudpickle
|
||||
from ray.tune.error import TuneError, TuneManagerError
|
||||
from ray.tune.suggest import BasicVariantGenerator
|
||||
from ray.utils import binary_to_hex, hex_to_binary
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
from SimpleHTTPServer import SimpleHTTPRequestHandler
|
||||
@@ -26,6 +28,13 @@ except ImportError:
|
||||
"Be sure to install it on the client side.")
|
||||
|
||||
|
||||
def load_trial_info(trial_info):
|
||||
trial_info["config"] = cloudpickle.loads(
|
||||
hex_to_binary(trial_info["config"]))
|
||||
trial_info["result"] = cloudpickle.loads(
|
||||
hex_to_binary(trial_info["result"]))
|
||||
|
||||
|
||||
class TuneClient(object):
|
||||
"""Client to interact with ongoing Tune experiment.
|
||||
|
||||
@@ -71,6 +80,13 @@ class TuneClient(object):
|
||||
payload = json.dumps(data).encode()
|
||||
response = requests.get(self._path, data=payload)
|
||||
parsed = response.json()
|
||||
|
||||
if "trial_info" in parsed:
|
||||
load_trial_info(parsed["trial_info"])
|
||||
elif "trials" in parsed:
|
||||
for trial_info in parsed["trials"]:
|
||||
load_trial_info(trial_info)
|
||||
|
||||
return parsed
|
||||
|
||||
|
||||
@@ -96,9 +112,9 @@ def RunnerHandler(runner):
|
||||
info_dict = {
|
||||
"id": trial.trial_id,
|
||||
"trainable_name": trial.trainable_name,
|
||||
"config": trial.config,
|
||||
"config": binary_to_hex(cloudpickle.dumps(trial.config)),
|
||||
"status": trial.status,
|
||||
"result": result
|
||||
"result": binary_to_hex(cloudpickle.dumps(result))
|
||||
}
|
||||
return info_dict
|
||||
|
||||
|
||||
Reference in New Issue
Block a user