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

Dian xt ms #29

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
code reformat
  • Loading branch information
AmiyaSX committed May 9, 2023
commit 8dd42cec140062c1b853e89476ae6626d9131832
1 change: 1 addition & 0 deletions examples/ant_ppo._ms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ model_para:


env_num: 1
speedup: False

benchmark:
log_interval_to_train: 5
Expand Down
1 change: 0 additions & 1 deletion examples/ant_ppo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ model_para:


env_num: 1
speedup: False

benchmark:
log_interval_to_train: 5
Expand Down
9 changes: 3 additions & 6 deletions xt/model/ppo/ppo_ms.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def __init__(self, model_info):
self.predict_net = self.PPOPredictPolicy(self.model, self.dist)
adam = Adam(params=self.predict_net.trainable_params(), learning_rate=0.0005)
loss_fn = WithLossCell(self.critic_loss_coef, self.clip_ratio, self.ent_coef, self.vf_clip)
forward_fn = NetWithLoss(
self.model, loss_fn, self.dist)
forward_fn = NetWithLoss(self.model, loss_fn, self.dist)
self.train_net = MyTrainOneStepCell(forward_fn, optimizer=adam, max_grad_norm=self._max_grad_norm)
self.train_net.set_train()

Expand Down Expand Up @@ -140,11 +139,9 @@ def construct(self, action_log_prob, ent, adv, old_log_p, target_v, out_v, old_v
actor_loss = -surr_loss - self.ent_coef * ent

vf_losses1 = self.square(out_v - target_v)
val_pred_clipped = old_v + \
clip_by_value(out_v - old_v, -self.val_clip, self.val_clip)
val_pred_clipped = old_v + clip_by_value(out_v - old_v, -self.val_clip, self.val_clip)
vf_losses2 = self.square(val_pred_clipped - target_v)

critic_loss = 0.5 * \
self.reduce_mean(self.maximum(vf_losses1, vf_losses2))
critic_loss = 0.5 * self.reduce_mean(self.maximum(vf_losses1, vf_losses2))
loss = actor_loss + self.critic_loss_coef * critic_loss
return loss