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

**URL:** <https://discuss.ray.io/t/tuneerror-improper-run-not-string-nor-trainable/8154>\
**Category:** RLlib\
**Created:** [November 7, 2022, 9:36am UTC](https://discuss.ray.io/t/tuneerror-improper-run-not-string-nor-trainable/8154 "2022-11-07T09:36:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Alexandrov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/alexander_alexandrov/32/2033_2.png) [@Alexander\_Alexandrov](https://discuss.ray.io/u/Alexander_Alexandrov)\
**Post date:** [November 7, 2022, 9:36am UTC](https://discuss.ray.io/t/tuneerror-improper-run-not-string-nor-trainable/8154/1 "2022-11-07T09:36:13Z")

</div>

```auto
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:

```auto
---------------------------------------------------------------------------
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 🙂

---

<div class="post-metadata">

**Author:** ![xwjiang2010](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xwjiang2010/32/1476_2.png) [@xwjiang2010](https://discuss.ray.io/u/xwjiang2010)\
**Post date:** [November 7, 2022, 9:54pm UTC](https://discuss.ray.io/t/tuneerror-improper-run-not-string-nor-trainable/8154/2 "2022-11-07T21:54:45Z")

</div>

Hi,  
Could you take a look at the PPO training/tuning example here? [Training APIs — Ray 2.0.1](https://docs.ray.io/en/latest/rllib/rllib-training.html#basic-python-api)  
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.

---

<div class="post-metadata">

**Author:** ![Alexander\_Alexandrov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/alexander_alexandrov/32/2033_2.png) [@Alexander\_Alexandrov](https://discuss.ray.io/u/Alexander_Alexandrov)\
**Post date:** [November 8, 2022, 4:01am UTC](https://discuss.ray.io/t/tuneerror-improper-run-not-string-nor-trainable/8154/3 "2022-11-08T04:01:07Z")

</div>

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

In other words i can either do:

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

```

or

```auto
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))

---

<div class="post-metadata">

**Author:** ![xwjiang2010](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xwjiang2010/32/1476_2.png) [@xwjiang2010](https://discuss.ray.io/u/xwjiang2010)\
**Post date:** [November 9, 2022, 12:09am UTC](https://discuss.ray.io/t/tuneerror-improper-run-not-string-nor-trainable/8154/4 "2022-11-09T00:09:01Z")

</div>

wrap ppo.train in a self-contained function → take a look [here](https://github.com/ray-project/ray/blob/master/rllib/examples/custom_experiment.py).

or you can do

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

```

---

<div class="post-metadata">

**Author:** ![xwjiang2010](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xwjiang2010/32/1476_2.png) [@xwjiang2010](https://discuss.ray.io/u/xwjiang2010)\
**Post date:** [November 9, 2022, 12:09am UTC](https://discuss.ray.io/t/tuneerror-improper-run-not-string-nor-trainable/8154/5 "2022-11-09T00:09:27Z")

</div>

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