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 l1 decay for inplace #32717

Merged
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
8 changes: 5 additions & 3 deletions python/paddle/fluid/regularizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,19 +326,21 @@ def __call__(self, param, grad, block):
assert isinstance(block, framework.Block)

if framework.in_dygraph_mode():
sign = block.create_var(dtype=param.dtype, shape=param.shape)
decay = block.create_var(dtype=param.dtype, shape=param.shape)
else:
sign = block.create_var(
Copy link
Contributor

Choose a reason for hiding this comment

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

静态图里也会遇到var的grad_node被设置两次报错的问题吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这块不会遇到,不过为了和动态图统一写法,就统一这样写了

Copy link
Contributor

Choose a reason for hiding this comment

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

lgtm

dtype=param.dtype, shape=param.shape, lod_level=param.lod_level)
decay = block.create_var(
dtype=param.dtype, shape=param.shape, lod_level=param.lod_level)

# Append sign op
block.append_op(
type='sign', inputs={"X": param}, outputs={"Out": decay})
block.append_op(type='sign', inputs={"X": param}, outputs={"Out": sign})

# Append scale op to the output of sign op
block.append_op(
type='scale',
inputs={"X": decay},
inputs={"X": sign},
outputs={"Out": decay},
attrs={"scale": self._regularization_coeff})

Expand Down