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

[Dy2Stat]Support Mixed Precision training in @to_static #34562

Merged
merged 4 commits into from
Aug 5, 2021

Conversation

Aurelius84
Copy link
Contributor

@Aurelius84 Aurelius84 commented Aug 2, 2021

PR types

New features

PR changes

Others

Describe

[Dy2Stat]Support Mixed Precision training in @to_static.

Examle:

# suppose the forward has beed decorated by @to_static
model = MNIST()

adam = AdamOptimizer(
            learning_rate=0.001, parameter_list=mnist.parameters())

scaler = paddle.amp.GradScaler(init_loss_scaling=1024)

for batch in batch_iter_reader:
    with paddle.amp.auto_cast():
            prediction, acc, avg_loss = mnist(img, label=label)

    scaled = scaler.scale(avg_loss)
    scaled.backward()
    scaler.minimize(adam, scaled)
    mnist.clear_gradients()
  1. 此 PR 为主体功能PR,后续会添加更多模型单测验证和完善@to_static 支持混合精度训练的功能

@paddle-bot-old
Copy link

paddle-bot-old bot commented Aug 2, 2021

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

@Aurelius84 Aurelius84 requested review from zhiqiu and zhhsplendid and removed request for zhhsplendid August 3, 2021 09:16
Copy link
Member

@zhhsplendid zhhsplendid left a comment

Choose a reason for hiding this comment

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

LGTM

@zhangbo9674
Copy link
Contributor

LGTM

@Aurelius84 Aurelius84 requested a review from chenwhql August 4, 2021 08:10
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 for framework.py

@Aurelius84 Aurelius84 merged commit a842828 into PaddlePaddle:develop Aug 5, 2021
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.

4 participants