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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make adding buffers more like adding parameters to modules. #35735
Comments
Is anyone working on this? Would be nice to have this to streamline dealing with buffers. |
I agree. It Would be more consistent to have |
This would be a great thing to have. |
Is this coming anytime soon? |
I'm afraid no-one is working on this at the moment no. |
@albanD Just posted a PR for this. Mostly test changes, actual product code changes are not that much. Let me know what you think and whether I've missed any important considerations. Thanks! |
I believe this has in the end not been merged, right? Is there any chance that the PR will be merged or a different implementation will be considered? |
Add similar semantics for creating a buffer object similar to creating a parameter. This is done by introducing a new Buffer class that can be used for type disambiguation. The underlying functionality of registering a buffer remains the same as the register_buffer method has not been changed. The persistent parameter in the Buffer type is to indicate whether a buffer object should be persistent or not. Other non-test changes have to do with getting the new Buffer type recognized by inductor and dynamo. Remaining changes are test changes to make sure that the Buffer type can be used as a drop in replacement for register_buffer as it just leads to register_buffer being called. The addition of this new functionality still allows for normal tensors to be used as buffers so these changes are intended to be backwards compatible. Fixes pytorch#35735
馃殌 Feature
Add a
nn.Buffer
type to mirror the behavior ofnn.Parameter
without the need to explicity callnn.Module.register_buffer
.Motivation
It's currently intuitive and easy to add a parameter to an
nn.Module
by wrapping it in ann.Parameter
. To the best of my knowledge a buffer is very similar to a parameter from an end user perspective except it doesn't get returned bynn.Module.parameters()
.It would therefore make sense to have a similar method for adding buffers to modules. Currently you have to explicitly call
nn.Module.register_buffer
which, in my opinion, is not very elegant as it requires you to provide the name of the member variable you want to create as a string.cc @albanD @mruberry @jbschlosser @walterddr @kshitij12345 @saketh-are
The text was updated successfully, but these errors were encountered: