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

[RLLib] Episode media logging support #14767

Merged
merged 2 commits into from
Mar 19, 2021

Conversation

Bam4d
Copy link
Contributor

@Bam4d Bam4d commented Mar 18, 2021

Why are these changes needed?

There is currently no way of transporting episode data such as images or videos for custom environments such as multi-agent environments to logging callbacks such as WandbLoggerCallback.

This patch allows agent callbacks to add arbitrary serializable media data such as wandb.Video() to an episode.media object which is then collated and returned as part of the result (which is used in both training and evaluation)

result = trainer.train()
my_custom_media = result['episode_media']

The episode media can be customized in any of the episode callbacks, for example on episode end:

    def on_episode_end(self, *, worker: "RolloutWorker", base_env: BaseEnv, policies: Dict[PolicyID, Policy],
                       episode: MultiAgentEpisode, env_index: Optional[int] = None, **kwargs) -> None:

        if not worker.multiagent:
            info = episode.last_info_for()
            if 'video' in info:
                level = info['video']['level']
                path = info['video']['path']
                print(f'creating video with path: {path}')
                episode.media[f'level_{level}'] = Video(path)

In summary this provides generic support for logging any custom environment media including seperate videos per-agent in mutli-agent enviroments.

Related issue number

#13169
#8403

Checks

  • I've run scripts/format.sh to lint the changes in this PR.
  • [ ] I've included any doc changes needed for https://docs.ray.io/en/master/.
  • [ ] I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@sven1977 This is my first (of hopefully many) commits to rllib. It would be great to get some advice on whats expected other than these tick-boxes here. for example I could definitely include a documentation change here, but seems like it makes more sense to get the code reviewed first before writing docs for it.

…e custom metrics in the episode object. This data can then be rolled up as part of training results and used in loggers such as wandb
@jsuarez5341
Copy link
Contributor

Related issue: #12833. This is a big step in the right direction (though the callback api is still a bit limited)

Copy link
Contributor

@sven1977 sven1977 left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for providing this generic solution.
We should probably add an example script that demonstrates this with on a simple, custom (maybe multi-agent) env.

@sven1977 sven1977 merged commit cd89f0d into ray-project:master Mar 19, 2021
@Bam4d
Copy link
Contributor Author

Bam4d commented Mar 19, 2021

We should probably add an example script that demonstrates this with on a simple, custom (maybe multi-agent) env.

Where would the best place for this be? in the docs somewhere?

@rfali
Copy link
Contributor

rfali commented Jun 1, 2021

an example script for this would be great. waiting for it

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.

5 participants