-
Notifications
You must be signed in to change notification settings - Fork 469
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
Support Enum Modules #726
Comments
Yesss ! |
Related ticket: #583. Someone shared how to use enum for sequential forward. |
Someone filed a ticket regarding this: #983 |
Hey folks, My case is that I have a Pytorch model with Sequential and without Enum type support with derive, it would mean implementing Module by hand just to support a It seems that, loading something like this is not really trivial at the moment. import torch
class CustomLayer(torch.nn.Module):
def __init__(self, channels, val):
super().__init__()
self.something = torch.ones(1, channels, 1) * val
def forward(self, x):
return x * self.something
class Net(torch.nn.Module):
def __init__(self):
super().__init__()
self.block = torch.nn.Sequential(
*[torch.nn.Conv1d(1, 32, 7), torch.nn.Tanh(), torch.nn.ConvTranspose1d(32, 22, 8), CustomLayer(22, 100)]
)
def forward(self, x):
return self.block(x)
model = Net()
res = model(torch.ones(1,1,400))
torch.save(model.state_dict(), "dummy.pt") I haven't tried to see if the PyTorchRecorder would actually allow this if I implemented Module for an enum manually because I haven't grasped yet how to do that as mentioned above. I appreciate that my case this point is focused in part on the PyTorchRecorder capability but it seems like it depends on Are there any examples in the codebase I'm missing that can be used to guide an implementation of something like this from scratch? |
@finnkauski, based on your example, I believe it would be optimal to encapsulate each module within a struct. The usage of |
I think this is a toy example, there are dynamic things at play in the real model which dictate the structure of the model and how many of certain layers there would be based on say the config values. |
Feature description
Support deriving
Module
for enums to enable code such asFeature motivation
This feature would make it easy to switch between layer variants and enable storing a vector of layers of different types.
The text was updated successfully, but these errors were encountered: