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

Profile/fold custom layer #76

Open
matthijsvk opened this issue May 14, 2020 · 0 comments
Open

Profile/fold custom layer #76

matthijsvk opened this issue May 14, 2020 · 0 comments

Comments

@matthijsvk
Copy link

matthijsvk commented May 14, 2020

Hi,

even for very simle wrappers around Pytorch layers the graph can get quite complex.
Is there a way to create subgraphs automatically fold those in 1 block?

example:

class Lin(nn.Module):
    def __init__(self, *args, **kwargs):
        super().__init__()
        self.lin = nn.Linear(*args, **kwargs)
    def forward(self, x):
        x = x.view(x.shape[0], -1)
        return self.lin(x)

model = nn.Sequential(*[ nn.Sequential(Lin(10), nn.ReLU()) for i in range(5)])
batch = torch.randn((4, 10))
print(model)

graph = hl.build_graph(model, batch)
    graph.save("graph", format="pdf")

What I mean is something like:

# profile a submodule
lin_example = Lin(10, 10)
lin_graph = hl.build_graph(lin_example, batch)

# now fold all the submodules in the main graph
graph = graph.fold_submodule(lin_graph)
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

1 participant