Skip to content

[RLlib][build_base] Introduce preprocessors to RLModules/Catalog - #33447

Merged
gjoliver merged 122 commits into
ray-project:masterfrom
ArturNiederfahrenhorst:preprocessors
Mar 25, 2023
Merged

gjoliver merged 122 commits into
ray-project:masterfrom
ArturNiederfahrenhorst:preprocessors

Conversation

@ArturNiederfahrenhorst

@ArturNiederfahrenhorst ArturNiederfahrenhorst commented Mar 20, 2023 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

This PR does the following:

Deprecation:

  • Fully Deprecate the "custom_preprocessor" model dict entry (soft deprecation has been going on for a while now).
  • Start soft-deprecation of the "options" kwarg of Preprocessors (as part of new Catalog)

Integration with RLModules/Catalog:

  • Introduce a new method Catalog.get_preprocessor() that users could use if they really wanted to hack our preprocessors. I'll annotate this as DeveloperAPI at first, since our policy so far has been to make users write wrapped environments instead of preprocessors.
  • Create and use preprocessors together with RLModules through Catalog.get_preprocessor() to support diverse observation spaces.

Prerequisite: #32940

kouroshHakha and others added 30 commits February 23, 2023 22:08
Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
Signed-off-by: Kourosh Hakhamaneshi <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
# deprecated the old model catalog.
cls = get_preprocessor(observation_space)
prep = cls(observation_space, options)
return prep

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.

I'm not adding a test to for this method itself in this PR, since it is very shallow and all underlying functionality is covered by the existing and added preprocessor tests themselves + integration tests.

Comment thread rllib/core/rl_module/rl_module.py Outdated
input_space: The input space space of the RLModule. This may differ from the
observation space of the environment. For example, a discrete observation
space of an environment, would usually correspond to a one-hot encoded
input space for the RLModule.

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.

I've repeatedly encountered users confused about the difference between policy observation space and environment observation space. I'd like to clear this up here with this remark.

merged_conf.model,
include_multi_binary=self.config.get(
"_enable_rl_module_api", False
),

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 our only entry point to ModelCatalog.get_preprocessor_for_space.
This extra argument is not a pretty solution, but by far the best one I could think of for now.
This PR includes comments on inlining the preprocessor method, which is when we'll be able to get rid of this method.

Comment thread rllib/models/catalog.py
)
)

if options.get("custom_preprocessor"):

@ArturNiederfahrenhorst ArturNiederfahrenhorst Mar 24, 2023 •

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.

As per discussion with @sven1977 , I'm fully deprecating custom_preprocessors in this PR.
This method is @DeveloperAPI, so we are able to move the actual deprecation error to algorithm config and simply deleting the warning here since it has been deprecated for a long time.

def observation_space(self) -> gym.Space:
obs_space = gym.spaces.Box(0.0, 1.0, self.shape, dtype=np.float32)
obs_space.original_space = self._obs_space
return obs_space

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.

Context for this change:

The new catalog will, by default, support two spaces: 1D and 3D image. Preprocessors cast other spaces we are compatible with into these two. Previously, we would simply cast incoming data to float inside the models. This is an implicit conversion between multi binary and float-box that we don't want to do anymore, so that the observation space of the RLModules fully matches the incoming observations.

This preprocessor has to be excluded from our ModelV2 code paths though in order to not change our old models.

Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
@kouroshHakha kouroshHakha changed the title [RLlib] Introduce preprocessors to RLModules/Catalog [RLlib][build_base] Introduce preprocessors to RLModules/Catalog Mar 24, 2023
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>

@kouroshHakha kouroshHakha left a comment

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.

nice pr man.

observation_space: The observation space of the RLModule. This may differ
from the observation space of the environment. For example, a discrete
observation space of an environment, would usually correspond to a
one-hot encoded observation space of the RLModule because of preprocessing.

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.

nice description. 💯

obs_space, merged_conf.model
obs_space,
merged_conf.model,
include_multi_binary=self.config.get(

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.

Do you want to include multi binary processor when rl_module is enabled? or the other way?

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.

nvm. Understood after reading the whole PR.

@gjoliver
gjoliver merged commit deba909 into ray-project:master Mar 25, 2023
elliottower pushed a commit to elliottower/ray that referenced this pull request Apr 22, 2023
ProjectsByJackHe pushed a commit to ProjectsByJackHe/ray that referenced this pull request May 4, 2023
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.

3 participants