Skip to content

Commit

Permalink
set net.forward to original forward function in flops (PaddlePaddle#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
0x45f authored and 0x45f committed Nov 19, 2021
1 parent 027664e commit aa6eb33
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/paddle/hapi/dynamic_flops.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import paddle.nn as nn
import numpy as np
from .static_flops import static_flops, Table
from paddle.fluid.dygraph.dygraph_to_static.program_translator import unwrap_decorators

__all__ = []

Expand Down Expand Up @@ -100,6 +101,10 @@ def count_leaky_relu(m, x, y):
#Total Flops: 347560 Total Params: 61610
"""
if isinstance(net, nn.Layer):
# If net is a dy2stat model, net.forward is StaticFunction instance,
# we set net.forward to original forward function.
_, net.forward = unwrap_decorators(net.forward)

inputs = paddle.randn(input_size)
return dynamic_flops(
net,
Expand Down

0 comments on commit aa6eb33

Please sign in to comment.