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

add option for multiple inputs when writing weight summary #543

Merged
merged 1 commit into from
Dec 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions pytorch_lightning/core/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,31 @@ def get_variable_sizes(self):
input_ = self.model.example_input_array

if self.model.on_gpu:
input_ = input_.cuda(0)
device = next(self.model.parameters()).get_device()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very sure about this getting device...
Probably also check if there is a next one?

# test if input is a list or a tuple
if isinstance(input_, (list, tuple)):
input_ = [input_i.cuda(device) if torch.is_tensor(input_i) else input_i
for input_i in input_]
else:
input_ = input_.cuda(device)

if self.model.trainer.use_amp:
input_ = input_.half()
# test if it is not a list or a tuple
if isinstance(input_, (list, tuple)):
input_ = [input_i.half() if torch.is_tensor(input_i) else input_i
for input_i in input_]
else:
input_ = input_.half()

with torch.no_grad():

for _, m in mods:
if type(input_) is list or type(input_) is tuple: # pragma: no cover
if isinstance(input_, (list, tuple)): # pragma: no cover
out = m(*input_)
else:
out = m(input_)

if type(input_) is tuple or type(input_) is list: # pragma: no cover
if isinstance(input_, (list, tuple)): # pragma: no cover
in_size = []
for x in input_:
if type(x) is list:
Expand All @@ -75,7 +86,7 @@ def get_variable_sizes(self):

in_sizes.append(in_size)

if type(out) is tuple or type(out) is list: # pragma: no cover
if isinstance(out, (list, tuple)): # pragma: no cover
out_size = np.asarray([x.size() for x in out])
else:
out_size = np.array(out.size())
Expand Down