Repository navigation
Conversation
Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A wrapper that keeps a context window of past observations and actions is what the feature request for brax asks for, and the patch for it is attached for you to look over.
Fixes #514
Thanks to erikfrey for marking this as a good first issue; it made it easy to pick up. This adds
HistoryWrapper(env, context_length)tobrax/envs/wrappers/training.py.The wrapped observation is the flattened last
context_lengthpairs of (observation, action just taken), oldest first. The pair returned byresethas a zero action, and steps before the start of the episode are zero padded.observation_sizebecomescontext_length * (observation_size + action_size).I kept the history inside
state.obsrather than instate.info. That wayAutoResetWrapper, which swapsstate.obsfor the stored reset observation when an episode ends, also resets the history, and nothing from the previous episode leaks into the next one. The consequence is that the wrapper goes on the base env, beforetraining.wrap(orVmapWrapper), and it only supports a flat observation: a dict observation raises aValueError. It works on batched states too, since it only indexes the last two axes.Tests added in
training_test.py: the unbatched case (shapes, zero padding, ordering of the stored actions, dropping the oldest frame), a batched run throughtraining.wrapwith a short episode that checks the history is reset after auto reset, and thecontext_length < 1error. They pass (4 passed intraining_test.py, ant env, macOS, CPU jax).Not verified: the rest of the test suite, GPU/TPU, and training an agent on top of the wrapped env. I have not exported it from
brax.envsor wired it intoenvs.create; happy to do that if you would prefer.