question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModuleList not showing up in summary

See original GitHub issue

Hi, 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
TylerYepcommented, Jun 22, 2020

This should be changed! If you would like to start a PR, that would be awesome!

0reactions
TylerYepcommented, Jul 6, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found