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

One-line change reduce memory from 11 GB to 2 GB. #8

Closed
AlexanderMath opened this issue Jan 10, 2021 · 2 comments
Closed

One-line change reduce memory from 11 GB to 2 GB. #8

AlexanderMath opened this issue Jan 10, 2021 · 2 comments

Comments

@AlexanderMath
Copy link

AlexanderMath commented Jan 10, 2021

The original glow code uses gradient checkpointing, a very efficient way of reducing peak memory consumption. The following single line adds gradient checkpointing in away that memory consumption from 11 GB to 2 GB. It allowed me to increased batch size from 64 to 256 with no issue. I think 512 is possible, maybe even 1024 if we use float16 for some of the layers.

st = self.nn(x_id)

def forward(self, x, ldj, reverse=False):
        x_change, x_id = x.chunk(2, dim=1)

        #st = self.nn(x_id) # change this line to the one below. 
        st = torch.utils.checkpoint.checkpoint(self.nn, x_id)
        s, t = st[:, 0::2, ...], st[:, 1::2, ...]
        s = self.scale * torch.tanh(s)
@chrischute
Copy link
Owner

Thanks for the suggestion. I added a reference to this issue in the README. If you'd like to add support for checkpointing as a command line argument, feel free to open a pull request and I'll happily review.

@AlexanderMath
Copy link
Author

Thanks for the suggestion. I added a reference to this issue in the README. If you'd like to add support for checkpointing as a command line argument, feel free to open a pull request and I'll happily review.

Will do when I get time after ICML deadline.

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

2 participants