Skip to content

Conversation

@zhangguanheng66
Copy link
Contributor

Remove weak_script. After recently splitting the forward() function in MultiheadAttention module, we notice a memory leak on GPU. Fix the problem by removing those "weak_script" decorator.

@zdevito
Copy link
Contributor

zdevito commented May 16, 2019

The leak is likely because the @weak_script decorator captures the frame information in which the function is executing, inadvertently also capturing tensors. Since the weak script functions are never compiled, it then never frees the frame and the tensors leak.

@zdevito
Copy link
Contributor

zdevito commented May 16, 2019

It also seems like those inner functions are not really closures in the first place. Can't we just move them out of the function, which would avoid the leak?

@zhangguanheng66
Copy link
Contributor Author

It also seems like those inner functions are not really closures in the first place. Can't we just move them out of the function, which would avoid the leak?

Thanks for the explanation. I feel it's worth more investigations. I could create a benchmark case to reproduce the problem or even report an issue for this.

As obvious, we don't expect and want anyone to actually call/use those inner functions. We feel safe to leave them inside.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhangguanheng66 is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@zhangguanheng66 zhangguanheng66 deleted the multi_head_weak_script branch May 16, 2019 03:37
@facebook-github-bot
Copy link
Contributor

@zhangguanheng66 merged this pull request in 3caf4e6.

@cpuhrsch
Copy link
Contributor

@zdevito - the functions are very useful abstractions for multihead attention, but we don't want to make them available at a functional.py level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: nn Related to torch.nn

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants