ModuleList not showing up in summary
See original GitHub issueHi,
it looks like modules wrapped in a ModuleList don’t show up in the summary (looks like the params are counted in the total though).
Minimal example:
import torch
from torchsummary import summary
class TestModule(torch.nn.Module):
def __init__(self):
super().__init__()
self._layers = torch.nn.ModuleList()
self._layers.append(torch.nn.Linear(5,5))
self._layers.append(torch.nn.Linear(5,5))
def forward(self, x):
out = x
for l in self._layers:
out = l(x)
return out
if __name__ == "__main__":
my_module = TestModule()
summary(my_module, (5,))
Gives
------------------------------------------------------------------------------------------
Layer (type:depth-idx) Output Shape Param #
==========================================================================================
==========================================================================================
Total params: 60
Trainable params: 60
Non-trainable params: 0
Total mult-adds (M): 0.00
------------------------------------------------------------------------------------------
Input size (MB): 0.00
Forward/backward pass size (MB): 0.00
Params size (MB): 0.00
Estimated Total Size (MB): 0.00
------------------------------------------------------------------------------------------
Whereas the print(str(model)) gives
TestModule(
(_layers): ModuleList(
(0): Linear(in_features=5, out_features=5, bias=True)
(1): Linear(in_features=5, out_features=5, bias=True)
)
)
Is this expected behavior? I could probably work on a PR if you think this should be changed and you have no quick fix for it.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
nn.Parameter not showing up in model.parameters but it is ...
I define both a bias parameter and some other module in MyModule, the bias parameter doesn't show up in model.parameters.
Read more >Why listing model components in pyTorch is not useful?
ModuleList and ModuleDict are python list and dictionaries respectively, but they tell torch that the list/dict contains a nn module.
Read more >ModuleList — PyTorch 1.13 documentation
ModuleList can be indexed like a regular Python list, but modules it contains are properly registered, and will be visible by all Module...
Read more >Module not showing up in Module list : r/FoundryVTT - Reddit
So I'm positive I installed the module Let's Trade, but when I look in my list of modules in-game, it doesn't show up....
Read more >Converting PyTorch to Keras: Internal Blocks Not Showing Up
Keras/Pytorch implementation of N-BEATS: Neural basis expansion analysis for interpretable time series forecasting. - GitHub - philipperemy/n- ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This should be changed! If you would like to start a PR, that would be awesome!
The changes look really great! I left a few minor comments on the PR. Functionality-wise it looks good to merge, but it would be great if you could add tests for all of the models you tried.
To do so, just add models to fixtures/models.py, and add each call to torchsummary_test.py. Output tests are optional, since the ModuleList output is subject to change.
I will think about the indexing strategy a bit more, but seeing as none of the previous test cases have broken, these changes seem good to merge - I’ll add a note that Sequential and ModuleList support is in-progress.