mirror of
https://github.com/wassname/ray.git
synced 2026-07-18 12:40:56 +08:00
[tune] Fix up examples (#9201)
This commit is contained in:
@@ -2,20 +2,28 @@
|
||||
|
||||
It also checks that it is usable with a separate scheduler.
|
||||
"""
|
||||
import time
|
||||
|
||||
import ray
|
||||
from ray.tune import run
|
||||
from ray import tune
|
||||
from ray.tune.schedulers import AsyncHyperBandScheduler
|
||||
from ray.tune.suggest.sigopt import SigOptSearch
|
||||
|
||||
|
||||
def easy_objective(config, reporter):
|
||||
import time
|
||||
time.sleep(0.2)
|
||||
for i in range(config["iterations"]):
|
||||
reporter(
|
||||
timesteps_total=i,
|
||||
mean_loss=(config["height"] - 14)**2 - abs(config["width"] - 3))
|
||||
time.sleep(0.02)
|
||||
def evaluate(step, width, height):
|
||||
return (0.1 + width * step / 100)**(-1) + height * 0.01
|
||||
|
||||
|
||||
def easy_objective(config):
|
||||
# Hyperparameters
|
||||
width, height = config["width"], config["height"]
|
||||
|
||||
for step in range(config["steps"]):
|
||||
# Iterative training function - can be any arbitrary training procedure
|
||||
intermediate_score = evaluate(step, width, height)
|
||||
# Feed the score back back to Tune.
|
||||
tune.report(iterations=step, mean_loss=intermediate_score)
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -53,11 +61,8 @@ if __name__ == "__main__":
|
||||
config = {
|
||||
"num_samples": 10 if args.smoke_test else 1000,
|
||||
"config": {
|
||||
"iterations": 100,
|
||||
},
|
||||
"stop": {
|
||||
"timesteps_total": 100
|
||||
},
|
||||
"steps": 10
|
||||
}
|
||||
}
|
||||
algo = SigOptSearch(
|
||||
space,
|
||||
@@ -66,7 +71,8 @@ if __name__ == "__main__":
|
||||
metric="mean_loss",
|
||||
mode="min")
|
||||
scheduler = AsyncHyperBandScheduler(metric="mean_loss", mode="min")
|
||||
run(easy_objective,
|
||||
tune.run(
|
||||
easy_objective,
|
||||
name="my_exp",
|
||||
search_alg=algo,
|
||||
scheduler=scheduler,
|
||||
|
||||
Reference in New Issue
Block a user