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

Feature request: e2cnn equivalent to torch.nn.ModuleList #32

Closed
drewm1980 opened this issue Mar 30, 2021 · 2 comments
Closed

Feature request: e2cnn equivalent to torch.nn.ModuleList #32

drewm1980 opened this issue Mar 30, 2021 · 2 comments

Comments

@drewm1980
Copy link

As a minor convenience, it would be nice to have an equivariant equivalent to torch.nn.ModuleList.

The main use cases:

  • Same as ModuleList, contain modules that are (elsewhere) hooked up in some arbitrary DAG, rather than Sequential, and still have them get registered properly.
  • Support .export() to a torch.nn.ModuleList containing .exported() children.
  • Aid mechanical 1:1 porting from pytorch to e2cnn equivalents.

It would not subclass EquivariantModule, since it can't meaningfully conform to most of that API, but it would probably get used mostly in EquivariantModule subclass implementations.

I'm currently trying out the following pattern in my code:

# Inside a bigger class that is itself implementing .export()... with self.up_path also a ModuleList...
def export(self):
        self.eval()
        up_path_exported = torch.nn.ModuleList()
        for module in self.up_path:
            up_path_exported.append(module.export())

If the EquivariantModules were already living in a e2cnn.nn.ModuleList, it would just be:

def export(self):
    self.eval()
    up_path_exported = self.up_path.export()

So a couple lines of boilerplate would be saved, but the discovery aspect is probably worth more... "just build everything using e2cnn 1:1 equivalents, train, then .export()"

@Gabri95
Copy link
Collaborator

Gabri95 commented Apr 6, 2021

Hi @drewm1980 ,

I see your point here.
I usually define another export method in the class defining the full model, where then I loop over self.named_modules() to find all equivariant modules to export.
Having an EquivariantModuleList would mostly automate this.

I think it is a nice idea, thanks for suggesting it!
I will add it later today or tomorrow.

Thanks again!
Gabriele

@Gabri95 Gabri95 closed this as completed in 7afb73a Apr 7, 2021
Gabri95 added a commit that referenced this issue Apr 7, 2021
@Gabri95
Copy link
Collaborator

Gabri95 commented Apr 7, 2021

I implemented it as a subclass of torch.nn.ModuleList to reuse its functionalities.
The only difference with it is that it should only accept EquivariantModules.

Let me know if this works well for you.

P.S.: I have not pushed the new code on pypi yet, so you should intall it using pip install git+https://github.com/QUVA-Lab/e2cnn

Best,
Gabriele

@Gabri95 Gabri95 reopened this Apr 7, 2021
@Gabri95 Gabri95 closed this as completed Apr 12, 2021
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