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

Fold homogeneous layers for deep learning models #109

Open
2catycm opened this issue Apr 20, 2024 · 0 comments
Open

Fold homogeneous layers for deep learning models #109

2catycm opened this issue Apr 20, 2024 · 0 comments

Comments

@2catycm
Copy link

2catycm commented Apr 20, 2024

Is your feature request related to a problem? Please describe.
Deep Learning models usually are stacked layers, from shallow layers to deep layers. With Transform models being prevalent, it is worth mentioning that Transformer Encoder Layers are homogeneous, i.e., different depths of layers are of the same class and the same initialization parameters, only different in which the positions that they are placed in the sequential connected ModuleList.

Therefore, when we visualize the model, it is ugly to see all the 12/24/40 and even more duplicated graph structures in the big svg generated. We should fold them.

Describe the solution you'd like
My solution may be, after we generated the graphviz graph, we can do a traversal on the graph and recognize whether there are such subgraphs a and b that satisfies:

  1. a and b have the same input shape and output shape.
  2. a and b are identical and isomorphic.
  3. a's only output is b's only input

Then we should fold a and b to
a*2

Additional context
another visualization lib called bigmodelvis can implement this, we can refer to their algorithms.

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