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

setuptools-based plugin for StatsWriters #4788

Merged
merged 15 commits into from Feb 5, 2021

Conversation

chriselion
Copy link
Contributor

@chriselion chriselion commented Dec 21, 2020

Proposed change(s)

Adds a setuptools-based plugin system, and an interface for registering custom StatsWriters. Also refactored some of the output directory settings so that TensorBoardWriter just needs the RunOptions.

For more background, see this video and example code.

Example output:

$ mlagents-learn --force
...
2020-12-21 15:06:51 INFO [learn.py:274] run_seed set to 249
registering default
registering example
Creating a new stats writer! This is so exciting!

...

ExampleStatsWriter category: 3DBall values: {'Policy/Entropy': StatsSummary(mean=1.4183114, std=0.00084836915, num=50172), ...}

Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)

https://github.com/anthonywritescode/explains/tree/master/sample_code/ep128
https://www.youtube.com/watch?v=fY3Y_xPKWNA

Types of change(s)

  • New feature

Checklist

  • Added tests that prove my fix is effective or that my feature works
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable)

@@ -0,0 +1,11 @@
from setuptools import setup
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No plans to publish this package, but we could use it to set up tests, e.g. for bad imports.

],
python_requires=">=3.6.1",
entry_points={
"console_scripts": [
"mlagents-learn=mlagents.trainers.learn:main",
"mlagents-run-experiment=mlagents.trainers.run_experiment:main",
]
],
"mlagents.stats_writer": [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We would need to add a new key for each type of plugin interface we want, e.g. mlagents.demonstration_provider: [...]

version="0.0.1",
entry_points={
"mlagents.stats_writer": [
"example=mlagents_plugin_examples.example_stats_writer:get_example_stats_writer"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The form of this is {entry point name}={plugin module}:{plugin_function}

@chriselion chriselion changed the title [WIP] proof-of-concept - setuptools-based plugin for StatsWriters setuptools-based plugin for StatsWriters Feb 1, 2021
@chriselion chriselion marked this pull request as ready for review February 1, 2021 22:19
"example=mlagents_plugin_examples.example_stats_writer:get_example_stats_writer"
]
```
* `mlagents.stats_writer` is the name of the plugin interface. This must be one of the provided interfaces (see below).
Copy link
Contributor

Choose a reason for hiding this comment

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

Make the see below a link to line 41

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

docs/Training-Plugins.md Show resolved Hide resolved
ml-agents/mlagents/plugins/stats_writer.py Outdated Show resolved Hide resolved
ml-agents/mlagents/plugins/stats_writer.py Show resolved Hide resolved
Comment on lines +192 to +194
argparser.add_argument(
"--results-dir", default="results", help="Results base directory"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this relevant to this PR? Why are we adding this flag ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was previously hardcoded in learn.py
https://github.com/Unity-Technologies/ml-agents/pull/4788/files#diff-4e0d7b8aef419254e6fc3c63f5baa53f222afda7c908705e857a22f7d4792c47L68

and is now used in CheckpointSettings.maybe_init_path()
https://github.com/Unity-Technologies/ml-agents/pull/4788/files#diff-546e90789e914f8707fd97391f78c4bba39ae69a965858bbb69c2d324db1ec51R719

I can keep it hardcoded if you prefer, but I do think moving all the path logic to part of RunOptions is a win (and basically a pre-req to make TensorBoardWriter act like a plugin)

Copy link
Contributor

@ervteng ervteng Feb 5, 2021

Choose a reason for hiding this comment

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

If a user changes this from the default results will it mess with how they're saved/synced in cloud? cc: @hvpeteet

Copy link
Contributor

@hvpeteet hvpeteet Feb 5, 2021

Choose a reason for hiding this comment

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

If a user can set it in the run_options then yes this could mess with cloud since we don't already take it into account. I don't think it is a reason not to make the change though. We can add logic to overwrite this field since we already modify run_options.

Just a couple of questions to confirm my understanding:

  1. Would this be set under checkpoint_settings --> write_path?
  2. Could we (cloud) blindly set this for every experiment and it would be ignored by older mlagents versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. It would be checkpoint_settings -> results_dir (at the top level)
  2. This would trigger an error here
    def check_and_structure(key: str, value: Any, class_type: type) -> Any:

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, we can check for it and only overwrite it if already set then. When you check this in can you file a ticket against me to make sure we get this added at some point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

@chriselion chriselion merged commit ef03bf6 into master Feb 5, 2021
@delete-merged-branch delete-merged-branch bot deleted the plugin-setuptools-statswriter branch February 5, 2021 23:06
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants