thu-ml / tianshou

An elegant PyTorch deep reinforcement learning library.
https://tianshou.org
MIT License
7.85k stars 1.12k forks source link

adam optim ERROR:If capturable=False, state_steps should not be CUDA tensors. #681

Closed jaried closed 2 years ago

jaried commented 2 years ago
jaried commented 2 years ago

Before executing offpolicy_trainer, I added the following code:

        actor_optim.param_groups[0]['capturable'] = True
        alpha_optim.param_groups[0]['capturable'] = True
        critic1_optim.param_groups[0]['capturable'] = True
        critic2_optim.param_groups[0]['capturable'] = True

can run, what is the reason?

jaried commented 2 years ago

This article says that it is caused by pressing ctrl+c to end the training? https://github.com/babysor/MockingBird/issues/631

But I use the previous version of the checkpoint file in question, and the same error is reported, why is this?

jaried commented 2 years ago

https://github.com/pytorch/pytorch/issues/80809

Someone said this:

Hi, I am also facing the same issue when I try to load the checkpoint and resume model training on the latest pytorch (1.12).

It seems to be related with a newly introduced parameter (capturable) for the Adam and AdamW optimizers. Currently two workarounds:

  1. forcing capturable = True after loading the checkpoint (as suggested above) optim.param_groups[0]['capturable'] = True . This seems to slow down the model training by approx. 10% (YMMV depending on the setup).
  2. Reverting pytorch back to previous versions (I have been using 1.11.0).

I'm wondering whether enforcing capturable = True may incur unwanted side effects.

I'm also wondering about whether forcing captureable=True would have unwanted side effects. I will also return to torch1.11.