# Specify trial resources when using search algorithm to tune hyper-parameters

**URL:** <https://discuss.ray.io/t/specify-trial-resources-when-using-search-algorithm-to-tune-hyper-parameters/7468>\
**Category:** RLlib\
**Created:** [September 7, 2022, 12:43am UTC](https://discuss.ray.io/t/specify-trial-resources-when-using-search-algorithm-to-tune-hyper-parameters/7468 "2022-09-07T00:43:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![steff](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@steff](https://discuss.ray.io/u/steff)\
**Post date:** [September 7, 2022, 12:43am UTC](https://discuss.ray.io/t/specify-trial-resources-when-using-search-algorithm-to-tune-hyper-parameters/7468/1 "2022-09-07T00:43:55Z")

</div>

**How severe does this issue affect your experience of using Ray?**

- High: It blocks me to complete my task.

Trying to use ray.tune.Tuner, ray.tune.search.optuna.OptunaSearch, ray.tune.schedulers.ASHAScheduler using Ray 2 to find the best hyper-parameters for a PPO policy that maximizes mean reward while also performing early termination of bad trials.

Code snippet below highlights the current process, but that generates the following error:

ray.tune.error.TuneError: No trial resources are available for launching the actor `ray.rllib.evaluation.rollout_worker.RolloutWorker. __init__ `. To resolve this, specify the Tune option: resources\_per\_trial=tune.PlacementGroupFactory([{‘CPU’: 1.0}] + [{‘CPU’: 1.0}] \* N)

Tuning resources documentation ([A Guide To Parallelism and Resources — Ray 2.0.0](https://docs.ray.io/en/latest/tune/tutorials/tune-resources.html) ) provides an example for how to specify resources when passing a trainable to ray.tune.Tuner, but haven’t found documentation for how to do this when passing an objective function used by Optuna or some other hyper-parameter search algorithm during the hyper-parameter tuning optimization process.

def train\_policy(self):

```
# create hyper-parameter search space 
search_space = self.create_search_space() 

# create search algorithm 
algo = OptunaSearch( 
    metric=self.metric, 
    mode=self.mode 
) 

# create scheduler that enables aggressive early stopping of bad trials 
scheduler = ASHAScheduler(...) 

# create tuner 
tuner = tune.Tuner( 

    # objective function that trains PPO policy using hyper-parameters selected by Optuna 
    self.objective, 

    # specify tune configuration 
    tune_config=tune.TuneConfig( 
        num_samples=self.num_samples, 
        search_alg=algo, 
        scheduler=scheduler 
    ), 

    # specify run configuration 
    run_config=air.RunConfig( 
        stop=dict(training_iteration=self.num_train_iters), 
        verbose=3 
    ), 

    # specify hyper-parameter search space 
    param_space=search_space, 
) 

# run tuner 
result_grid = tuner.fit() 

```

def objective(self, config):

```
# create PPO trainer 
trainer = self.create_ppo_trainer(config) 

# iterate 
for iter in range(self.num_train_iters): 

    # train policy 
    results = trainer.train() 

    # update tuner 
    session.report(dict( 
        episode_reward_mean=results[self.metric] 
    )) 

```

Greatly appreciate any help with this.

Thanks,  
Stefan

---

<div class="post-metadata">

**Author:** ![arturn](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/arturn/32/2096_2.png) [@arturn](https://discuss.ray.io/u/arturn)\
**Post date:** [September 7, 2022, 2:01pm UTC](https://discuss.ray.io/t/specify-trial-resources-when-using-search-algorithm-to-tune-hyper-parameters/7468/2 "2022-09-07T14:01:04Z")

</div>

Hey @steff

Could you please post this in the [Ray AIR](https://discuss.ray.io/c/ray-air/18) forums? That’s where we discussed questions related to Tune and it’s handling of resources 🙂

---

<div class="post-metadata">

**Author:** ![steff](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@steff](https://discuss.ray.io/u/steff)\
**Post date:** [September 7, 2022, 3:09pm UTC](https://discuss.ray.io/t/specify-trial-resources-when-using-search-algorithm-to-tune-hyper-parameters/7468/3 "2022-09-07T15:09:04Z")

</div>

Hi Artur. Just posted it to Ray AIR forum: [https://discuss.ray.io/t/specify-trial-resources-when-using-optuna-search-algorithm-to-tune-hyper-parameters/7473](https://discuss.ray.io/t/specify-trial-resources-when-using-optuna-search-algorithm-to-tune-hyper-parameters/7473)
