delve-team / delve

PyTorch model training and layer saturation monitor
https://delve-docs.readthedocs.io
MIT License
79 stars 13 forks source link

Does it work with submodules? #7

Closed stared closed 5 years ago

stared commented 5 years ago

Typically I use modules within nn.Sequential or custom-defined modules.

class TwoLayerNet(torch.nn.Module):
    def __init__(self, D_in, H, D_out):
        super(TwoLayerNet, self).__init__()
        self.fc = torch.nn.Sequential(
            torch.nn.Linear(D_in, H),
            torch.nn.Linear(H, D_out)
        )

    def forward(self, x):
        return self.fc(x)

and then layers = model.parameters(). However, I get an error:

Traceback (most recent call last):
  File "example_submodule.py", line 43, in <module>
    stats = CheckLayerSat('regression/h{}'.format(h), layers)
  File "/Users/pmigdal/not_my_repos/delve/delve/main.py", line 50, in __init__
    self.layers = self._get_layers(modules)
  File "/Users/pmigdal/not_my_repos/delve/delve/main.py", line 167, in _get_layers
    for name in modules.state_dict().keys():
AttributeError: 'generator' object has no attribute 'state_dict'

(for full code example, see: https://gist.github.com/stared/b598c03ade397baf3fa03c52bd79e90d)

Does it work with submodules?

JustinShenk commented 5 years ago

Thanks for briging this to my attention. Fixed with 2820262f885b61da0de2f7884b15670bf106c926 in version 0.1.8.

On Wed, Dec 26, 2018 at 12:30 PM Piotr Migdał notifications@github.com wrote:

Typically I use modules within nn.Sequential or custom-defined modules.

class TwoLayerNet(torch.nn.Module): def init(self, D_in, H, D_out): super(TwoLayerNet, self).init() self.fc = torch.nn.Sequential( torch.nn.Linear(D_in, H), torch.nn.Linear(H, D_out) )

def forward(self, x):
    return self.fc(x)

and then layers = model.parameters(). However, I get an error:

Traceback (most recent call last): File "example_submodule.py", line 43, in stats = CheckLayerSat('regression/h{}'.format(h), layers) File "/Users/pmigdal/not_my_repos/delve/delve/main.py", line 50, in init self.layers = self._get_layers(modules) File "/Users/pmigdal/not_my_repos/delve/delve/main.py", line 167, in _get_layers for name in modules.state_dict().keys(): AttributeError: 'generator' object has no attribute 'state_dict'

(for full code example, see: https://gist.github.com/stared/b598c03ade397baf3fa03c52bd79e90d)

Does it work with submodules?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/justinshenk/delve/issues/7, or mute the thread https://github.com/notifications/unsubscribe-auth/AJy2ZIvVEF-4gIQXVbf4R8ArSsDxkGx0ks5u813FgaJpZM4Zhqb9 .

stared commented 5 years ago

@justinshenk Awesome! And I am impressed by your pace. :)