Skip to content

fix direct_returnn_layer_call() for multiple bases #131

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions pytorch_to_returnn/torch/nn/modules/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,14 +526,24 @@ def direct_returnn_layer_call(cls) -> bool:
"""
if not cls.has_torch_forward():
return True
base = cls
while base is not object:

queue = [cls]
visited = set()
while len(queue) > 0:
base = queue.pop(0)
if base in visited:
continue
visited.add(base)

if cls is object:
return True
if not issubclass(base, Module):
continue
if cls.create_returnn_layer_dict != base.create_returnn_layer_dict:
return True
elif cls.forward != base.forward:
return False
assert len(base.__bases__) == 1, "Not implemented otherwise"
base = base.__bases__[0]
queue += [base for base in cls.__bases__ if issubclass(base, Module)]
return True

def check_returnn_layer(self, layer: LayerBase):
Expand Down