vwxyzjn / cleanrl

High-quality single file implementation of Deep Reinforcement Learning algorithms with research-friendly features (PPO, DQN, C51, DDPG, TD3, SAC, PPG)
http://docs.cleanrl.dev
Other
5.54k stars 631 forks source link

added gamma to reward normalization wrappers #209

Closed Howuhh closed 2 years ago

Howuhh commented 2 years ago

Description

Fixes incorrect gamma in reward normalization wrapper for non-default gamma's. See https://github.com/vwxyzjn/cleanrl/issues/203.

Types of changes

Checklist:

If you are adding new algorithms or your change could result in performance difference, you may need to (re-)run tracked experiments. See https://github.com/vwxyzjn/cleanrl/pull/137 as an example PR.

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
cleanrl ✅ Ready (Inspect) Visit Preview Jul 6, 2022 at 7:59PM (UTC)
vwxyzjn commented 2 years ago

So here is the tricky part - the original implementation actually uses 0.999 for gamma, but 0.99 for the normalization wrapper. See https://github.com/openai/train-procgen/blob/1a2ae2194a61f76a733a39339530401c024c3ad8/train_procgen/train.py#L43

This would cause a performance change unfortunately. There are two ways to go forward

  1. re-run the procgen benchmark experiments with gym.wrappers.NormalizeReward(envs, gamma=args.gamma). https://github.com/vwxyzjn/cleanrl/blob/6387191dbee74927b2872b2eb1759c72361d806f/benchmark/ppo.sh#L39-L44 https://github.com/vwxyzjn/cleanrl/blob/6387191dbee74927b2872b2eb1759c72361d806f/benchmark/ppg.sh#L3-L8
  2. keep the procgen scripts untouched.

@Howuhh what do you think we should do?

Howuhh commented 2 years ago

@vwxyzjn To be honest, I think this is a bug in original code, not a feature, so it will be more accurate to rerun for correct results. However, procgen is image based env and for now I don't have resources to train on images.

vwxyzjn commented 2 years ago

Ok, no worries. I will take care from here. @Dipamc77 I don't have the GPU memory to run the PPG experiments. Would you mind running them with this PR? I can take care of the ppo procgen experiments.

https://github.com/vwxyzjn/cleanrl/blob/6387191dbee74927b2872b2eb1759c72361d806f/benchmark/ppg.sh#L3-L8

vwxyzjn commented 2 years ago

Running the PPO experiments now. Also tried a fun thing by adding a wandb tag like

WANDB_TAGS=$(git describe --tags)  xvfb-run -a python -m cleanrl_utils.benchmark \
    --env-ids starpilot bossfight bigfish \
    --command "poetry run python cleanrl/ppo_procgen.py --track --capture-video" \
    --num-seeds 3 \
    --workers 1

which produces runs like

image

@dosssman I think this tagging system could somehow help us phase out past openrlbenchmark experiments without deleting them. I will have to think about the workflow a bit more.

vwxyzjn commented 2 years ago

Following up here

image image image
vwxyzjn commented 2 years ago

The bigfish performance degradation could easily be due to a random seed.

vwxyzjn commented 2 years ago
image image image

No major performance regression. Going to document this change and merge.

vwxyzjn commented 2 years ago

I have just updated all of the experiments and documentation. @Howuhh @dosssman could you give it a pass, please? Thank you!

Howuhh commented 2 years ago

@vwxyzjn Seems okay to me. Thanks for redoing the experiments btw.