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

[Dy2Static]Add param_guard in ParameterList to support @to_static #32859

Merged
merged 1 commit into from
May 14, 2021

Conversation

Aurelius84
Copy link
Contributor

PR types

Bug fixes

PR changes

APIs

Describe

Add param_guard in ParameterList to support @to_static

Before this PR, if Model codes use ParameterList as container in __init__() function, it will cause No Input(X) error while applying @to_static to convert into static program.

See the following code, this PR fixed this bug.

class NetWithParameterList(paddle.nn.Layer):
    def __init__(self, in_size, out_size):
        super(NetWithParameterList, self).__init__()
        weight = self.create_parameter([in_size, out_size])
        bias = self.create_parameter([out_size], is_bias=True)
        self.params = paddle.nn.ParameterList([weight, bias])

    @to_static
    def forward(self, x):
        out = paddle.matmul(x, self.params[0])   # Cause `No Input(X)` error 
        out = paddle.add(out, self.params[1])
        out = paddle.tanh(out)
        return out

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copy link
Contributor

@liym27 liym27 left a comment

Choose a reason for hiding this comment

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

LGTM

@Aurelius84 Aurelius84 merged commit e48091d into PaddlePaddle:develop May 14, 2021
lanxianghit pushed a commit that referenced this pull request May 20, 2021
… (#32985)

* [Dy2Static]Add param_guard in ParameterList to support @to_static

* [Dy2Static] Refactor param_guard logic of @to_static (#32867)

* Add param_guard in ParameterList to support @to_static

* Refactor param_guard of @to_static

* fix unittest failed

* add more unittest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants