这是indexloc提供的服务,不要输入任何密码
Skip to content

Add lr_scheduler option for Onpolicy algorithm #318

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

Merged
merged 3 commits into from
Mar 22, 2021

Conversation

ChenDRAG
Copy link
Collaborator

@ChenDRAG ChenDRAG commented Mar 21, 2021

linear lr decay is important for both PPO and REINFORCEMENT benchmark as in #307, You can do something like below to change lr as you like when training. My solution is quite and easy forwarded.

from torch.optim.lr_scheduler import LambdaLR
import torch.nn as nn
import torch
from torch.optim import *


class net(nn.Module):
    def __init__(self):
        super(net,self).__init__()
        self.fc = nn.Linear(1,10)
    def forward(self,x):
        return self.fc(x)
model = net()

optimizer = Adam(model.parameters(),lr = 0.01)
max_update_num=10
lambda1 = lambda epoch: (1 - epoch/max_update_num)
optimizer.scheduler = lr_scheduler.LambdaLR(optimizer,lr_lambda = lambda1)

Then pass in the optimizer and policy will change lr every update automatically.

This way you get to not adding new APIs.

@Trinkle23897 Trinkle23897 merged commit 2c11b6e into thu-ml:master Mar 22, 2021
BFAnas pushed a commit to BFAnas/tianshou that referenced this pull request May 5, 2024
add lr_scheduler option in PGPolicy/A2CPolicy/PPOPolicy
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.

Plans of releasing mujoco benchmark of onpolicy algorithms(VPG, A2C, PPO)
2 participants