[BUG] NoisyLinear uses self.training to turn on/off noise
@vmoens is already working on this.
Since Jan 27, 2023.
- Dominant language
- Python
- Stars
- 3.6k
- Forks
- 484
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 207
Description
Describe the bug
In PyTorch, module.training is used to differentiate training and inference. For example, Normalization layers use training attribute because they should behave differently when training and inference. However, NoisyLinear is not the case, NoisyLinear should stay active both during training and during inference (actually this is the whole point of NoisyLinear, it "learns" noisy parameters during training, and uses noise for exploration during inference). The only time NoisyLinear should be turned off is during policy evaluation/testing. (evaluation is not the same as inference in RL, evaluation should always be inference, while inference can be either evaluation or exploration).
In the current implementation, to correctly allow the policy to explore, module.training must be turned on even for inference during exploration, however, turning on training mode will unavoidably affect normalization layers, dropout, etc. Although Dropout is not widely used in RL yet, normalization layers are sometimes being used in recent years (especially in some works that try to use Transformers in RL). I personally think using training attribute, in this case, is a bug.
To Reproduce
Expected behavior
NoisyLinear should be activated during exploration/training, and deactivated during evaluation/testing. Other pytorch modules like normalization should not be impacted by the behavior of NoisyLinear.
Screenshots
System info
Additional context
Reason and Possible fixes
possible fix: add an additional function or attribute specifically for NoisyLinear to turn on and off noise (just like how its reset_noise resets noise)
Checklist
- I have checked that there is no similar issue in the repo (required)
- I have read the documentation (required)
- I have provided a minimal working example to reproduce the bug (required)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.