mirror of
https://github.com/wassname/ray.git
synced 2026-07-21 12:50:45 +08:00
[tune] Add algorithms for search space conversion (#10621)
This commit is contained in:
@@ -8,7 +8,7 @@ import ray
|
||||
from ray import tune
|
||||
from ray.tune.suggest.zoopt import ZOOptSearch
|
||||
from ray.tune.schedulers import AsyncHyperBandScheduler
|
||||
from zoopt import ValueType
|
||||
from zoopt import ValueType # noqa: F401
|
||||
|
||||
|
||||
def evaluation_fn(step, width, height):
|
||||
@@ -36,26 +36,27 @@ if __name__ == "__main__":
|
||||
args, _ = parser.parse_known_args()
|
||||
ray.init()
|
||||
|
||||
# This dict could mix continuous dimensions and discrete dimensions,
|
||||
# for example:
|
||||
dim_dict = {
|
||||
# for continuous dimensions: (continuous, search_range, precision)
|
||||
"height": (ValueType.CONTINUOUS, [-10, 10], 1e-2),
|
||||
# for discrete dimensions: (discrete, search_range, has_order)
|
||||
"width": (ValueType.DISCRETE, [0, 10], False)
|
||||
}
|
||||
|
||||
config = {
|
||||
tune_kwargs = {
|
||||
"num_samples": 10 if args.smoke_test else 1000,
|
||||
"config": {
|
||||
"steps": 10, # evaluation times
|
||||
"steps": 10,
|
||||
"height": tune.quniform(-10, 10, 1e-2),
|
||||
"width": tune.randint(0, 10)
|
||||
}
|
||||
}
|
||||
|
||||
# Optional: Pass the parameter space yourself
|
||||
# space = {
|
||||
# # for continuous dimensions: (continuous, search_range, precision)
|
||||
# "height": (ValueType.CONTINUOUS, [-10, 10], 1e-2),
|
||||
# # for discrete dimensions: (discrete, search_range, has_order)
|
||||
# "width": (ValueType.DISCRETE, [0, 10], True)
|
||||
# }
|
||||
|
||||
zoopt_search = ZOOptSearch(
|
||||
algo="Asracos", # only support ASRacos currently
|
||||
budget=config["num_samples"],
|
||||
dim_dict=dim_dict,
|
||||
budget=tune_kwargs["num_samples"],
|
||||
# dim_dict=space, # If you want to set the space yourself
|
||||
metric="mean_loss",
|
||||
mode="min")
|
||||
|
||||
@@ -66,4 +67,4 @@ if __name__ == "__main__":
|
||||
search_alg=zoopt_search,
|
||||
name="zoopt_search",
|
||||
scheduler=scheduler,
|
||||
**config)
|
||||
**tune_kwargs)
|
||||
|
||||
Reference in New Issue
Block a user