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 optimizer dtype #29917

Merged
merged 1 commit into from
Dec 28, 2020
Merged

Fix optimizer dtype #29917

merged 1 commit into from
Dec 28, 2020

Conversation

zhiqiu
Copy link
Contributor

@zhiqiu zhiqiu commented Dec 25, 2020

PR types

Bug fixes

PR changes

APIs

Describe

The dtype of Optimizer should be inferred by given parameters, which will be used in learning rate and other vars in optimizer.

For example,

class MyLayer(paddle.nn.Layer):
    def __init__(self, dtype):
        super(MyLayer, self).__init__()
        self._w = self.create_parameter([2, 3], dtype='float64')
        self._b = self.create_parameter([2, 3], dtype='float64')

    def forward(self, x):
        return x * self._w + self._b
            model = MyLayer(dtype)

x = paddle.rand([10, 2, 3], dtype=dtype)
loss = model(x)
adam = paddle.optimizer.Adam(parameters=model.parameters())
loss.backward()
adam.step()

@paddle-bot-old
Copy link

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

@zhiqiu zhiqiu requested a review from chenwhql December 27, 2020 08:25
Copy link
Contributor

@chenwhql chenwhql left a comment

Choose a reason for hiding this comment

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

LGTM

@zhiqiu zhiqiu merged commit a4b9daf into PaddlePaddle:develop Dec 28, 2020
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