When setting a custom path for local_dir
in RunConfig(), the logs and result records are cleared after the tuner.fit()
run finishes.
If I don’t set local_dir
, the logs and result records can be correctly saved when the program ends.
Sample code:
from ray import train, tune
from ray.air.config import RunConfig
from ray.tune.schedulers import ASHAScheduler
def train_fun(config):
for epoch in range(100):
acc = config["lr"] * config["batch_size"]
train.report({"lr": config["lr"], "accuracy": acc})
print("Finished Training")
if __name__ == "__main__":
metric_str = "accuracy"
config = {
"lr": tune.loguniform(1e-4, 1e-1),
"batch_size": tune.choice([2, 4, 8, 16]),
}
max_t = 100
scheduler = ASHAScheduler(
metric=metric_str,
mode="max",
max_t=max_t,
grace_period=100,
reduction_factor=2,
)
tuner = tune.Tuner(
tune.with_resources(
tune.with_parameters(train_fun),
resources={"cpu": 2},
),
tune_config=tune.TuneConfig(
num_samples=2,
scheduler=scheduler,
),
param_space=config,
run_config=RunConfig(
name="ray_test",
# local_dir="E:/temp_file/",
),
)
results = tuner.fit()
# best_result = results.get_best_result(metric_str, "max")
# print("Best trial config: {}".format(best_result.config))
I’m using ray 2.7.1 and python 3.10.11 on Windows 10 22H2.