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

Fix paddle.flops AttributeError #38850

Merged
merged 4 commits into from
Jan 19, 2022
Merged
Changes from 1 commit
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
13 changes: 8 additions & 5 deletions python/paddle/hapi/dynamic_flops.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ def count_parameters(m, x, y):

def count_io_info(m, x, y):
m.register_buffer('input_shape', paddle.to_tensor(x[0].shape))
m.register_buffer('output_shape', paddle.to_tensor(y.shape))
if isinstance(y, (list, tuple)):
m.register_buffer('output_shape', paddle.to_tensor(y[0].shape))
else:
m.register_buffer('output_shape', paddle.to_tensor(y.shape))


register_hooks = {
Expand Down Expand Up @@ -258,8 +261,8 @@ def add_hooks(m):
for m in model.sublayers():
if len(list(m.children())) > 0:
continue
if set(['total_ops', 'total_params', 'input_shape',
'output_shape']).issubset(set(list(m._buffers.keys()))):
if {'total_ops', 'total_params', 'input_shape',
'output_shape'}.issubset(set(list(m._buffers.keys()))):
total_ops += m.total_ops
total_params += m.total_params

Expand All @@ -274,8 +277,8 @@ def add_hooks(m):
for n, m in model.named_sublayers():
if len(list(m.children())) > 0:
continue
if set(['total_ops', 'total_params', 'input_shape',
'output_shape']).issubset(set(list(m._buffers.keys()))):
if {'total_ops', 'total_params', 'input_shape',
'output_shape'}.issubset(set(list(m._buffers.keys()))):
table.add_row([
m.full_name(), list(m.input_shape.numpy()),
list(m.output_shape.numpy()), int(m.total_params),
Expand Down