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

allow custom modules with custom RETURNN layer #129

Merged
merged 3 commits into from
Nov 23, 2022
Merged

Conversation

vieting
Copy link
Contributor

@vieting vieting commented Nov 23, 2022

I'd like to create a module which has a torch forward function, but nevertheless is mapped to a custom RETURNN layer call. The basic idea is to have something like

class MyModule(torch.nn.Module):
  is_original_torch_module = False

  def forward(self, x):
    y = foo(x)
    return y

  def create_returnn_layer_dict(self, input):
    return {"class": "<some_layer>", "from": self._get_input_layer_name(input)}

Right now, the custom create_returnn_layer_dict is ignored and the code inside forward is wrapped. This PR changes this behavior to make sure to use the custom create_returnn_layer_dict.

@vieting vieting requested a review from albertz November 23, 2022 13:14
@vieting
Copy link
Contributor Author

vieting commented Nov 23, 2022

I added test_dct as an example test case because that's what I was interested in. We can also simplify in general or reformat the code in dct() if you don't like it.

@albertz
Copy link
Member

albertz commented Nov 23, 2022

There are three failing tests. Did you check them?

@vieting
Copy link
Contributor Author

vieting commented Nov 23, 2022

There are three failing tests. Did you check them?

Yes, they are the same as in #125.

@albertz albertz merged commit 8fa7e93 into main Nov 23, 2022
@albertz albertz deleted the peter_custom_returnn branch November 23, 2022 20:39
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

Successfully merging this pull request may close these issues.

2 participants