# Tuning fcnet\_hiddens with RLlib PPO ValueError: loaded state dict

**URL:** <https://discuss.ray.io/t/tuning-fcnet-hiddens-with-rllib-ppo-valueerror-loaded-state-dict/7137>\
**Category:** RLlib\
**Created:** [August 9, 2022, 4:32pm UTC](https://discuss.ray.io/t/tuning-fcnet-hiddens-with-rllib-ppo-valueerror-loaded-state-dict/7137 "2022-08-09T16:32:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dejan\_Grubisic](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/dejan_grubisic/32/2987_2.png) [@Dejan\_Grubisic](https://discuss.ray.io/u/Dejan_Grubisic)\
**Post date:** [August 9, 2022, 4:32pm UTC](https://discuss.ray.io/t/tuning-fcnet-hiddens-with-rllib-ppo-valueerror-loaded-state-dict/7137/1 "2022-08-09T16:32:58Z")

</div>

I am trying to tune fcnet\_hiddens for a simple PPO default network with ray.tune, but it fails on restoring checkpoint. Here is what I did:

```auto
hiddens_layers = [3, 10, 20]
hiddens_width = [50, 100, 500]
config['model']['fcnet_hiddens'] = tune.choice([[w] * l for w in hiddens_width for l in hiddens_layers ])
...
analysis = tune.run(PPOTrainer, config=config, num_samples=5)
checkpoint_path = analysis.get_best_checkpoint(
            metric="episode_reward_mean",
            mode="max",
            trial=analysis.trials[0]
        )

best_config = analysis.get_best_config()
best_config['explore'] = False
agent = PPOTrainer(
    env="my_env",
    config=best_config
)

agent.restore(checkpoint_path) # <<<<<<<< This fails with error

```

> Error:  
> ValueError: loaded state dict contains a parameter group that doesn’t match the size of optimizer’s group

Any idea how to tune fcnet\_hiddens?

---

<div class="post-metadata">

**Author:** ![Dejan\_Grubisic](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/dejan_grubisic/32/2987_2.png) [@Dejan\_Grubisic](https://discuss.ray.io/u/Dejan_Grubisic)\
**Post date:** [August 10, 2022, 7:04pm UTC](https://discuss.ray.io/t/tuning-fcnet-hiddens-with-rllib-ppo-valueerror-loaded-state-dict/7137/2 "2022-08-10T19:04:18Z")

</div>

> analysis.get\_best\_checkpoint

depends on the trial and we need to find the best trial and to find the best config for it. Here is the running code:

```auto
hiddens_layers = [3, 10, 20]
hiddens_width = [50, 100, 500]
config['model']['fcnet_hiddens'] = tune.choice([[w] * l for w in hiddens_width for l in hiddens_layers ])
...
analysis = tune.run(PPOTrainer, config=config, num_samples=5)
checkpoint_path = analysis.get_best_checkpoint(
            metric="episode_reward_mean",
            mode="max",
            trial=analysis.best_trial # instead of analysis.trials[0]
        )

best_config = analysis.get_best_config()
best_config['explore'] = False
agent = PPOTrainer(
    env="my_env",
    config=best_config
)

agent.restore(checkpoint_path)

```

---

<div class="post-metadata">

**Author:** ![starkj](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/starkj/32/3266_2.png) [@starkj](https://discuss.ray.io/u/starkj)\
**Post date:** [October 20, 2022, 2:58am UTC](https://discuss.ray.io/t/tuning-fcnet-hiddens-with-rllib-ppo-valueerror-loaded-state-dict/7137/3 "2022-10-20T02:58:34Z")

</div>

@Dejan_Grubisic I am seeing the same error when restoring a checkpoint for a 3-layer network. However, if my network has only 2 layers, the restore works fine. See my post at [ValueError when restoring checkpoint with PPO](https://discuss.ray.io/t/valueerror-when-restoring-checkpoint-with-ppo/7967). I suspect you are seeing the same issue I was. I’m a little sleepy, but is it possible that your restore using `checkpoint_path` is loading a network with different structure than what is defined in `best_config`?
