TuneError: Improper 'run' - not string nor trainable

mario_config={
    "env": "mario",
    "framework": "torch",
    "env_config": {},
    "num_gpus": 1,
    "num_workers": 5, # кол-во паралельно запущенных агентов
    "lr": 0.0001,

    "rollout_fragment_length": 20, # минибатч. Из них состоить основной батч сайз (минимальная единица батча)
    "train_batch_size": 400, # Основной батч. Он формируется из минибатчсайза, перебирая минибатчсайз
    "num_cpus_per_worker": 0,
    "num_gpus_per_worker": 0.2,
    "gamma": 0.99,
    "batch_mode": "truncate_episodes", # complete_episodes
    "shuffle_buffer_size": 10, # перемешивать батчи с такой минимальной длиной
    "recreate_failed_workers": True,
    "horizon": 8000,

    #"output": "/content/drive/My Drive/...",
}

register_env('mario', lambda config: Mario(config))

algo = ppo.PPO(config=mario_config, env="mario")

search_space = {
    "lr": hp.loguniform("lr", 1e-10, 0.1)
}

hyperopt_search = HyperOptSearch(search_space, metric="mean_accuracy", mode="max")

tuner = tune.Tuner(
    algo,
    tune_config=tune.TuneConfig(
        num_samples=20,
        scheduler=ASHAScheduler(metric="mean_accuracy", mode="max"),
    ),
    param_space=search_space,
)


results = tuner.fit()

Error Traceback:

---------------------------------------------------------------------------
TuneError                                 Traceback (most recent call last)
<ipython-input-16-97dfe54f0015> in <module>
      5         scheduler=ASHAScheduler(metric="mean_accuracy", mode="max"),
      6     ),
----> 7     param_space=search_space,
      8 )
      9 results = tuner.fit()

4 frames
/usr/local/lib/python3.7/dist-packages/ray/tune/tuner.py in __init__(self, trainable, param_space, tune_config, run_config, _tuner_kwargs, _tuner_internal)
    142             kwargs.pop(_SELF, None)
    143             if not self._is_ray_client:
--> 144                 self._local_tuner = TunerInternal(**kwargs)
    145             else:
    146                 self._remote_tuner = _force_on_current_node(

/usr/local/lib/python3.7/dist-packages/ray/tune/impl/tuner_internal.py in __init__(self, restore_path, resume_config, trainable, param_space, tune_config, run_config, _tuner_kwargs)
    102         self._tuner_kwargs = copy.deepcopy(_tuner_kwargs) or {}
    103         self._experiment_checkpoint_dir = self._setup_create_experiment_checkpoint_dir(
--> 104             self._run_config
    105         )
    106 

/usr/local/lib/python3.7/dist-packages/ray/tune/impl/tuner_internal.py in _setup_create_experiment_checkpoint_dir(self, run_config)
    256             self._convert_trainable(self._trainable),
    257             run_config.local_dir,
--> 258             run_config.name,
    259         )
    260         if not os.path.exists(path):

/usr/local/lib/python3.7/dist-packages/ray/tune/experiment/experiment.py in get_experiment_checkpoint_dir(cls, run_obj, local_dir, name)
    387         assert run_obj
    388         local_dir = _get_local_dir_with_expand_user(local_dir)
--> 389         run_identifier = cls.get_trainable_name(run_obj)
    390         combined_name = name or run_identifier
    391 

/usr/local/lib/python3.7/dist-packages/ray/tune/experiment/experiment.py in get_trainable_name(cls, run_object)
    328             return name
    329         else:
--> 330             raise TuneError("Improper 'run' - not string nor trainable.")
    331 
    332     @classmethod

TuneError: Improper 'run' - not string nor trainable.

Will be appreciated for any help :slightly_smiling_face:

Hi,
Could you take a look at the PPO training/tuning example here? Training APIs — Ray 2.0.1
That should answer the question.

In short, one can either do
tuner = Tuner("ppo", param_space={# ppo.config that you want to tune can go here})
or wrap ppo.train() in a self-made training function, and supply that training function to Tune.

2 Likes

Thanx for your answer. But i do not believe i get it right.

In other words i can either do:

algo = ppo.PPO(...)
algo.train()

or

search_space = {
    "lr": hp.loguniform("lr", 1e-10, 0.1)
}

hyperopt_search = HyperOptSearch(search_space, metric="mean_accuracy", mode="max")

tuner = tune.Tuner(
    algo,
    tune_config=tune.TuneConfig(
        num_samples=20,
        scheduler=ASHAScheduler(metric="mean_accuracy", mode="max"),
    ),
    param_space=search_space,
)


results = tuner.fit()

Two things im not sure i got right:
what do you mean by wrap ppo.train in a self-made training function.
Could you send link. I looked through documentation. Code from there works great. But i do not understand how to wrap/pass it into Tune.

Thanks for your time and consideration))

wrap ppo.train in a self-contained function → take a look here.

or you can do

tuner = tuner.Tuner("ppo", tune_config=..., param_space={"lr": tune.grid_search([0.01, 0.001]}))
result = tuner.fit()
1 Like

note for the 2nd way, it has to be “ppo” as a string.