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 failure to trace densenet #23

Merged
merged 2 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ known_first_party = ["paddlefx"]
minversion = "7.0.0"
pythonpath = "tests"
testpaths = ["tests"]
filterwarnings = [
# Ignore warnings raised by paddlepaddle 2.4
"ignore::DeprecationWarning",
]

[tool.setuptools_scm]
write_to = "src/paddlefx/_version.py"
2 changes: 2 additions & 0 deletions src/paddlefx/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def python_code(self, root_module):
for node in self.nodes:
if node.op == 'placeholder':
free_vars.append(node.target)
if node.target != node.name:
body.append(f'{node.name} = {node.target}\n')
continue
elif node.op == 'call_method':
body.append(
Expand Down
8 changes: 6 additions & 2 deletions src/paddlefx/symbolic_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ def _find_module(root, m):


def _is_leaf_module(m) -> bool:
return m.__module__.startswith("paddle.nn") and not isinstance(
m, paddle.nn.Sequential
return (
m.__module__.startswith("paddle.nn")
# `paddle.fluid.dygraph.nn` has removed in paddlepaddle 2.5.0 (develop),
# but still keep it for compatibility with paddlepaddle <= 2.4
or m.__module__.startswith("paddle.fluid.dygraph.nn")
and not isinstance(m, paddle.nn.Sequential)
)


Expand Down
3 changes: 1 addition & 2 deletions tests/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def setUp(self):
self.models_to_track = [
(paddle.vision.models.resnet18(), paddle.randn([2, 3, 224, 224])),
(paddle.vision.models.alexnet(), paddle.randn([2, 3, 224, 224])),
# DenseNet will fail, since it calls into _C_ops
# (paddle.vision.models.densenet121(), paddle.randn([2, 3, 224, 224])),
(paddle.vision.models.densenet121(), paddle.randn([2, 3, 224, 224])),
(paddle.vision.models.googlenet(), paddle.randn([2, 3, 224, 224])),
(paddle.vision.models.inception_v3(), paddle.randn([2, 3, 299, 299])),
(paddle.vision.models.mobilenet_v2(), paddle.randn([2, 3, 224, 224])),
Expand Down