Skip to content

[RLlib] Preparatory PR: Make EnvRunners use (enhanced) Connector API (#01: mostly cleanups and small fixes) - #41074

Merged
sven1977 merged 4 commits into
ray-project:masterfrom
sven1977:env_runner_support_connectors_01_minor_cleanups
Nov 17, 2023
Merged

sven1977 merged 4 commits into
ray-project:masterfrom
sven1977:env_runner_support_connectors_01_minor_cleanups

Conversation

@sven1977

@sven1977 sven1977 commented Nov 10, 2023 •

Copy link
Copy Markdown
Contributor

Preparatory PR: Make EnvRunners use (enhanced) Connector API (#1: mostly cleanups and small fixes)

Why are these changes needed?

Related issue number

Checks

Signed-off-by: sven1977 <[email protected]>
for agent_id, ob in observations.items():
worker = self.workers.local_worker()
preprocessed = worker.preprocessors[policy_id].transform(ob)
if worker.preprocessors.get(policy_id) is not None:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a bug fix.

# If not specified, we will try to auto-detect this.
self._is_atari = None

# TODO (sven): Rename this method into `AlgorithmConfig.sampling()`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now that we are aiming for a the EnvRunner API as the default, we should rename/clarify some of these config settings and methods.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please consider loading a checkpoint here? Are these renaming backward compatible?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there even a story around this? Like can people even move from rllib 2+ to 3?

Comment thread rllib/core/models/torch/encoder.py Outdated
bias=config.use_bias,
)

self.state_in_out_spec = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Simplified (repetitive) code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

make this private attribute?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

return self._getattr_by_index("observations", indices, global_ts)

def get_actions(
def get_infos(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reordered:

  1. obs, infos (<- env.reset data)
  2. action, reward, terminated/truncated (<- other env.step results)
  3. extra model outs

Comment thread rllib/env/single_agent_env_runner.py Outdated
gym.register(
"custom-env-v0",
partial(
if (

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bug fix.

if local_worker and self.local_worker() is not None:
local_result = [func(self.local_worker())]

if not self.__worker_manager.actor_ids():

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Shortcut for local-worker only case.

restart_failed_sub_environments: true

# Switch on evaluation workers being managed by AsyncRequestsManager object.
# Switch on asynchronous handling of evaluation workers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

AsyncRequestsManager doesn't exist anymore.

return input_


@DeveloperAPI

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Very useful new utility. Inverse of already existing unbatch utility.

# If not specified, we will try to auto-detect this.
self._is_atari = None

# TODO (sven): Rename this method into `AlgorithmConfig.sampling()`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please consider loading a checkpoint here? Are these renaming backward compatible?

# If not specified, we will try to auto-detect this.
self._is_atari = None

# TODO (sven): Rename this method into `AlgorithmConfig.sampling()`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there even a story around this? Like can people even move from rllib 2+ to 3?

Comment thread rllib/core/models/torch/encoder.py Outdated
bias=config.use_bias,
)

self.state_in_out_spec = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

make this private attribute?

Comment thread rllib/utils/spaces/space_utils.py Outdated


@DeveloperAPI
def batch(list_of_structs, individual_items_already_have_batch_1: bool = False):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

data types please (for input and output)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we have unittest of this ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done and done

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

also enhanced the docstring to make the example and explanations more clear.

flat = [[] for _ in range(len(flattened_item))]
for i, value in enumerate(flattened_item):
flat[i].append(value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

add:

    if item is None:
        raise ValueError("Input list_of_structs does not contain valid structs.")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

in this struct represents the batch for a single component
(in case struct is tuple/dict). Alternatively, a simple batch of
primitives (non tuple/dict) might be returned.
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

add

    if not list_of_structs:
        raise ValueError("Input list_of_structs is empty.")

Copy link
Copy Markdown
Contributor Author

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]>
@sven1977

Copy link
Copy Markdown
Contributor Author

Thanks for the review @kouroshHakha ! Waiting for tests to pass ...

@sven1977
sven1977 merged commit ca29fec into ray-project:master Nov 17, 2023
@sven1977
sven1977 deleted the env_runner_support_connectors_01_minor_cleanups branch November 17, 2023 11:29
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.

2 participants