# How to set #of cpu and gpu per trial?

**URL:** <https://discuss.ray.io/t/how-to-set-of-cpu-and-gpu-per-trial/4016>\
**Category:** RLlib\
**Created:** [November 2, 2021, 2:32pm UTC](https://discuss.ray.io/t/how-to-set-of-cpu-and-gpu-per-trial/4016 "2021-11-02T14:32:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JingZhang918](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jingzhang918/32/1680_2.png) [@JingZhang918](https://discuss.ray.io/u/JingZhang918)\
**Post date:** [November 2, 2021, 2:32pm UTC](https://discuss.ray.io/t/how-to-set-of-cpu-and-gpu-per-trial/4016/1 "2021-11-02T14:32:33Z")

</div>

I’m trying some really basic code:

```auto
from ray import tune
from ray.rllib.agents.ppo import PPOTrainer
tune.run(PPOTrainer, config={"env": "CartPole-v0"})

```

But it’s always pending with this message:

> 2021-11-02 14:19:26,189 WARNING trial\_executor.py:306 – Ignore this message if the cluster is autoscaling. You asked for 3.0 cpu and 0.0 gpu per trial, but the cluster only has 2.0 cpu and 1.0 gpu. Stop the tuning job and adjust the resources requested per trial (possibly via `resources_per_trial` or via `num_workers` for rllib) and/or add more resources to your Ray runtime.

Then I add this code:

```auto
PPOTrainer.default_resource_request({'cpu':1, "gpu":1})

```

with the intent to request less cpu to make it run. But nothing happened. It still needs “3.0 cpu and 0.0 gpu per trial”.

Then I try to use the parameter resources\_per\_trial from tune.run then I get an error:

```auto
ValueError: Resources for <class 'ray.rllib.agents.trainer_template.PPO'> have been automatically set to <ray.tune.utils.placement_groups.PlacementGroupFactory object at 0x7f1f64833290> by its `default_resource_request()` method. Please clear the `resources_per_trial` option.

```

Now what do I do?

---

<div class="post-metadata">

**Author:** ![Lars\_Simon\_Zehnder](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/lars_simon_zehnder/32/1185_2.png) [@Lars\_Simon\_Zehnder](https://discuss.ray.io/u/Lars_Simon_Zehnder)\
**Post date:** [November 6, 2021, 10:25am UTC](https://discuss.ray.io/t/how-to-set-of-cpu-and-gpu-per-trial/4016/2 "2021-11-06T10:25:13Z")

</div>

Hi @JingZhang918 ,

and welcome to the ray community. You have to set the configurations `num_gpus`, `num_cpus_per_worker` and `num_cpus_per_driver`. `num_gpus_per_worker` is usually only needed, if your environment needs one. See for more infos into the [`Trainer`](https://github.com/ray-project/ray/blob/master/rllib/agents/trainer.py) class.

Hope that helps you get your code to run.
