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] Minor fix on json encoding during worker sampling #20134

Merged

Conversation

sungho-joo
Copy link
Contributor

@sungho-joo sungho-joo commented Nov 7, 2021

Why are these changes needed?

This PR fixes a minor bug on json encoding during worker sampling (specifically when output_writer write batch).
Currently, when output_writer write batch, it first transforms data into json file.
If data contains type that is not json serializable, error occurs while dumping.
In rllib, this usually happens in custom env with custom infos.
Luckly, similar issues have been reported before (#2243) and SafeFallbackEncoder has been implemented.

This PR contributes in two way

  1. Import and pass SafeFallbackEncoder to json.dumps
  2. Improving SafeFallbackEncoder

Regarding the improvement of SafeFallbackEncoder, order of nan checking and np.ndarray type check has been changed.
This is because return of np.isnan(ndarray object) is not boolean but array of boolean.
if np.isnan(np.array([1,1])): -> throws error
Therefore, ndarray type check has to be checked before checking nan
Also, type check of np.bool_ is added.

Using implemented SafeFallbackEncoder,

Related issue number

"Resolves #5785 "

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 :(

Copy link
Contributor

@amogkam amogkam left a comment

Choose a reason for hiding this comment

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

LGTM, thanks a lot for the patch :)

@amogkam amogkam merged commit dc51af7 into ray-project:master Nov 10, 2021
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.

[rllib] JSONWriter doesn't work with some types of custom info
2 participants