-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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; Offline RL] RLUnplugged example on new API stack. #46792
[RLlib; Offline RL] RLUnplugged example on new API stack. #46792
Conversation
…class into separate files. Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
…gorithmConfig' and 'OfflineData' to make the data pipeline better configurable and tuneable. Tested single-and multi-learner sertups with BC. Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
Co-authored-by: Sven Mika <sven@anyscale.io> Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
…n class. Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
…of Atari Pong. Needs to be tuned. Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
…defined. Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
Signed-off-by: simonsays1980 <simon.zehnder@gmail.com>
**kwargs, | ||
) | ||
|
||
self._multi_agent = multi_agent |
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.
Do we need these options?
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.
No, we don't. It was not clear to me, yet, that this does not need to be set when in single-agent mode.
|
||
# Make the learner connector. | ||
def _make_learner_connector(observation_space, action_space): | ||
return DecodeObservations() |
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.
Let's get rid of this by doing in the config below:
config.training(
...
learner_connector: lambda obs_space, act_space: DecodeObservations(),
...
)
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.
I like this more! Thanks!
) | ||
) | ||
|
||
# TODO (simon): Change to use the `run_rllib_example` function as soon as tuned. |
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.
nit: TODO? Or still WIP?
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.
WIP :) It is still not running smoothly and for debugging I am not using tune.
|
||
# Make the temporary directory for the downloaded data. | ||
tmp_path = "/tmp/atari" | ||
Path(tmp_path).joinpath(game).mkdir(exist_ok=True, parents=True) |
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.
super nit: should we use the "/" op of pathlib.Path here?
tmp_path = Path("/tmp/atari") / game
tmp_path.mkdir(...)
destination_file_name = tmp_path / "run_...."
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, let's do it this is better to read.
# can be chosen by users. To use all data use a list of file paths (see | ||
# `num_shards`) and its usage further below. | ||
run_number = 1 | ||
# num_shards = 1 |
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.
Should the be commented out? # num_shards = 1
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.
This is actually a number that is now hard coded into the path. We have many runs and for each multiple shards in the bucket - each is a file. For the example I use only a single of these files.
def _env_creator(cfg): | ||
return wrap_atari_for_new_api_stack( | ||
gym.make("ALE/Pong-v5", **cfg), | ||
# Perform frame-stacking through ConnectorV2 API. |
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.
Wait, if we say: framestack=4 here then we do NOT perform frame-stacking through ConnectorV2 here.
-> Change comment by removing the ConnectorV2 statement.
Note: At this point, the gain in performance when using the connector is minimal, so can probably be neglected for simplicity (easier for user to do framestacking in env-wrapper).
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.
Thanks for the hint. WIll remove this comment.
|
||
|
||
class DecodeObservations(ConnectorV2): | ||
def __init__( |
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.
Add a (small) docstring here that explains what this connector does.
@@ -0,0 +1,257 @@ | |||
""" | |||
schema={ |
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.
Is this needed here? If this is an explanation of the schema, maybe move this down into the config section (where we explain the schema translation)?
@@ -2499,6 +2499,10 @@ def offline_data( | |||
self.input_read_method_kwargs = input_read_method_kwargs | |||
if input_read_schema is not NotProvided: | |||
self.input_read_schema = input_read_schema | |||
if map_batches_kwargs is not NotProvided: |
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.
Ah, yes, this was missing :)
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.
Looks great! Just some nits, mostly enhancing/adding comments and explanations.
@@ -0,0 +1,257 @@ | |||
""" |
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.
Should we call this file simply: pong_bc.py
?
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.
I think we should add a hint that it is pong data from rl_unplugged. What do you think?
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.
Looks good to me now! Thanks @simonsays1980
Why are these changes needed?
The new
Offline RL API
uses nativeray.data.Dataset
s to scale to massive datasets with different formats and encodings. To ensure that learning indeed scales to massive data and the API can be used with the most notable Offline RL datasets this PR applies the newOffline RL API
to theRLUnplugged
data. In the tuned example data from AtariPong
is used with a singleTfRecord
s file from the GCS bucket.The data is downloaded automatically into a temporary folder. To decode the PNG images this example defines a
ConnectorV2
that decodes the images in the learner connector pipeline and stacks frames.This example show specifically how to scale out on massive data and use the
AlgorithmConfig.offline_data
's arguments to fine-tune scaling withray.data
. See for more infosray.data
.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.