Skip to content

Commit

Permalink
chore: simply ppo gae code (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
vwxyzjn authored Dec 28, 2022
1 parent ad19f23 commit d67ae0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions cleanrl/ppo_atari_envpool_xla_jax_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,10 @@ def compute_gae(
_, advantages = jax.lax.scan(
compute_gae_once, advantages, (dones[1:], values[1:], values[:-1], storage.rewards), reverse=True
)
storage = storage.replace(advantages=advantages)
storage = storage.replace(returns=storage.advantages + storage.values)
storage = storage.replace(
advantages=advantages,
returns=storage.advantages + storage.values,
)
return storage

def ppo_loss(params, x, a, logp, mb_advantages, mb_returns):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_jax_compute_gae.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ def compute_gae_scan(
_, advantages = jax.lax.scan(
compute_gae_once_fn, advantages, (dones[1:], values[1:], values[:-1], storage.rewards), reverse=True
)
storage = storage.replace(advantages=advantages)
storage = storage.replace(returns=storage.advantages + storage.values)
storage = storage.replace(
advantages=advantages,
returns=storage.advantages + storage.values,
)
return storage

def compute_gae_python_loop(
Expand Down

1 comment on commit d67ae0c

@vercel
Copy link

@vercel vercel bot commented on d67ae0c Dec 28, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

cleanrl – ./

cleanrl.vercel.app
docs.cleanrl.dev
cleanrl-vwxyzjn.vercel.app
cleanrl-git-master-vwxyzjn.vercel.app

Please sign in to comment.