Skip to content

Commit

Permalink
Add missing error messages for container modules (pytorch#29991)
Browse files Browse the repository at this point in the history
Summary:
Container `Module`s, including `ModuleList`, `ParameterList` and `ParameterDict`, should not be called like a regular `Module`.
This PR add error messages for these special modules.
Pull Request resolved: pytorch#29991

Differential Revision: D19698535

Pulled By: ezyang

fbshipit-source-id: fe156a0bbb033041086734b38f8c6fde034829bf
  • Loading branch information
songyouwei authored and facebook-github-bot committed Feb 14, 2020
1 parent 92fbf7c commit e5218e3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions torch/nn/modules/container.py
Expand Up @@ -211,6 +211,9 @@ def extend(self, modules):
self.add_module(str(offset + i), module)
return self

def forward(self):
raise NotImplementedError()


class ModuleDict(Module):
r"""Holds submodules in a dictionary.
Expand Down Expand Up @@ -451,6 +454,9 @@ def extra_repr(self):
tmpstr = '\n'.join(child_lines)
return tmpstr

def __call__(self, input):
raise RuntimeError('ParameterList should not be called.')


class ParameterDict(Module):
r"""Holds parameters in a dictionary.
Expand Down Expand Up @@ -590,3 +596,6 @@ def extra_repr(self):
child_lines.append(' (' + k + '): ' + parastr)
tmpstr = '\n'.join(child_lines)
return tmpstr

def __call__(self, input):
raise RuntimeError('ParameterDict should not be called.')

0 comments on commit e5218e3

Please sign in to comment.