-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[RLlib] Cleanup examples folder vol. 23: Add example script for custom metrics on EnvRunners
(using MetricsLogger
API).
#47969
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: sven1977 <[email protected]>
…nup_examples_folder_23_custom_metrics_and_callbacks
Signed-off-by: sven1977 <[email protected]>
Signed-off-by: sven1977 <[email protected]>
…nup_examples_folder_23_custom_metrics_and_callbacks
Signed-off-by: sven1977 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Awesome example. Documenting the MetricsLogger´ and showing users how to use it correctly is so important. I think still that this is one of the complexest parts of
RLlib` and gave some suggestions for further cases.
- the mean distance travelled by MsPacman per episode (over an infinite window). | ||
- the number of lifes of MsPacman EMA-smoothed over time. | ||
|
||
This callback can be setup to only log stats on certain EnvRunner indices through |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if an EnvRunner
crashes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. The index first goes out of commission (other EnvRunners will NOT change their indices b/c of another EnvRunner's crash), but only until the actor is automatically restarted. The latter only happens if config.recreate_failed_env_runners=True
, of course.
custom `Algorithm.training_step()` methods, custom loss functions, custom callbacks, | ||
and custom EnvRunners. | ||
|
||
This example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome example!! This shows a lot how to use the MetricsLogger
.
To increase complexity, we could:
- Run this only in evaluation and run evaluation each
n
th training step. - Reset some metrics in between.
- Log two group of metrics (for two groups of env-runners).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! There are two more PRs in flight: MetricsLogger on algorithm.training_step and MetricsLogger inside loss function. A third one could be: MetricsLogger only on eval env runners 🙌
How to run this script | ||
---------------------- | ||
`python [script file name].py --enable-new-api-stack --wandb-key [your WandB key] | ||
--wandb-projecy [some project name]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"--wandb-projecy" -> "--wandb-project"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same options occur below in "For logging ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's ok. The statement below is the generic enable-logging statement, the one above are the recommended args for this particular script.
episode.get_infos(-1)["lives"], | ||
reduce="mean", # <- default (must be "mean" for EMA smothing) | ||
ema_coeff=0.01, # <- default EMA coefficient (`window` must be None) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment in regard to metrics_logger.reduce
when to use it and why not here.
self.stats = tree.map_structure_with_path(_reduce, stats_to_return) | ||
# Provide proper error message if reduction fails due to bad data. | ||
except Exception as e: | ||
raise ValueError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I wonder what happens when a user resets in between two training steps a key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question. Users should - ideally - never use this API and let RLlib determine, when to call .reduce()
on a MetricsLogger object. They should only call .peek()
to see individual reduced stats at the moment w/o actually altering/reducing the underlying stats object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I need to make this more clear in the docstring ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Signed-off-by: sven1977 <[email protected]>
Signed-off-by: sven1977 <[email protected]>
…and_callbacks Signed-off-by: Sven Mika <[email protected]>
…nup_examples_folder_23_custom_metrics_and_callbacks Signed-off-by: sven1977 <[email protected]> # Conflicts: # rllib/BUILD
…m_metrics_and_callbacks' into cleanup_examples_folder_23_custom_metrics_and_callbacks
Cleanup examples folder vol. 23: Add example script for custom metrics on
EnvRunners
(usingMetricsLogger
API).Why are these changes needed?
Related issue number
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.