-
Notifications
You must be signed in to change notification settings - Fork 21
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
Refactor mygrad.nnet.layers #399
base: master
Are you sure you want to change the base?
Conversation
4d3f0d0
to
bf3b9eb
Compare
First off, thanks for working on this! It will be really nice to get mynn merged into mygrad 😄
I am in favor of After this change, we should check to see if the docs will need to be updates as well. E.g. both the filename and contents of mygrad.nnet.layers.batchnorm.rst are path-dependent. But if we maintain the namespaces, as mentioned above, I think things will be OK.
We don't need anything fancy here, I think the following is sufficient:
conv_layer = ConvNDLayer(..., bias=True)
out = conv_layer(data) # `data` can be trivial - no need for hypothesis
assert isinstance(out.creator, Add)
conv_out, bias = out.creator.variables
assert bias is conv_layer.bias
assert isinstance(conv_out.creator, ConvND) # the operation-class, not the layer
x, w = conv_out.creator.variables
assert w is conv_layer.w
assert x is data
I am in favor of (2) Perhaps we should make a super-simple base class, just with a |
👍 this all makes sense. thanks for reading through! I'll make these changes over the next few(?) days and get the ball rolling on this merge |
It occurred to me that, for testing So basically: conv_layer = ConvNDLayer(..., bias=True)
out = conv_layer(data) # `data` can be trivial - no need for hypothesis
assert isinstance(out.creator, Add)
conv_out, bias = out.creator.variables
assert bias is conv_layer.bias
assert isinstance(conv_out.creator, ConvND) # the operation-class, not the layer
x, w = conv_out.creator.variables
assert w is conv_layer.w
assert x is data
assert w.grad is None
assert bias.grad is None
out.backward()
assert w.grad is not None
assert bias.grad is not None |
Opening this as a draft so I can get some comments. This changes the overall structure of the
mygrad.nnet.layers
module. The changes are:mygrad.nnet.layers
module has moved tomygrad.nnet.layers.operations
. This reflects the fact that these were all operator implementations of the layer functionality, but don't do any bookkeeping of parameters.mygrad.nnet.layers
module now contains helper class Layers that perform the bookkeeping of parameters. This mimics the structure ofmynn.layers
.I went ahead and added a
BatchNorm
layer as an initial example, and will port overConv
,Dense
(orLinear
or whatever we want to name it),Dropout
, andPReLU
when we're happy with the design. Main questions:torch.nn
where the classes live andtorch.nn.functional
where the operations live.mygrad.nnet.layers
->mygrad.nnet.layers.operations
, then one-by-one add in layers each as their own release.