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

[Prim]fix attrs loss in creating op #50780

Merged
merged 5 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions python/paddle/fluid/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -2883,6 +2883,8 @@ def __init__(
self._type = type
self.attrs = attrs if attrs else {}
else:
self.legacy_attrs = attrs if attrs else {}

self.block = block
self.desc = desc
# note: not add self.attrs here:
Expand Down Expand Up @@ -3080,13 +3082,22 @@ def find_name(var_list, name):
)

self.desc.check_attrs()

# record all attrs needed by creating op
for item in self.desc.attr_names():
self.legacy_attrs[item] = self.desc.attr(item)

if self._has_kernel(type):
self.desc.infer_var_type(self.block.desc)
self.desc.infer_shape(self.block.desc)

def _has_kernel(self, op_type):
return op_type not in self.OP_WITHOUT_KERNEL_SET

def _get_runtime_attrs(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comments to avoid other one using this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

# record all attrs needed by creating op
return self.legacy_attrs

def to_string(self, throw_on_error):
"""
Get debug string.
Expand Down
6 changes: 4 additions & 2 deletions python/paddle/incubate/autograd/primx.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,10 @@ def expand_nested_list(xs):
outputs[op.output_names[i]] = op.output(op.output_names[i])

attrs = {}
for name in sorted(op.attr_names):
attrs[name] = op.attr(name)
runtime_attrs = op._get_runtime_attrs()
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comments to explain why we need this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

for name in runtime_attrs.keys():
attrs[name] = runtime_attrs[name]

from paddle.fluid.dygraph.base import param_guard

new_op_desc = block.desc.append_op()
Expand Down