Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use backward immediately after loss computation to increase memory efficiency #240

Open
lyx-x opened this issue Feb 14, 2018 · 0 comments
Open

Comments

@lyx-x
Copy link
Contributor

lyx-x commented Feb 14, 2018

This is a general remark after I got memory issue with PCL on Atari games. I noticed that losses are sometimes appended into a list (as shown below) and a weighted loss is computed (much) later. This is in theory correct, but memory inefficient as Chainer retrains all intermediate computation result in memory, e.g. when we apply a network on 2 inputs, there will be 2 copies of intermediate results and 2 losses.

pi_losses.append(C_pi ** 2)

Since Functions and Links accumulates gradients and gradients are linearly additives, I would suggest we call backward immediately after getting a loss instead of saving them to a list. The cleargrads can be called in some high level function such as act_and_train.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant