Conversation
5 tasks done
araffin
reviewed
Aug 15, 2026
| if self.replay_buffer_class is None: | ||
| if isinstance(self.observation_space, spaces.Dict): | ||
| self.replay_buffer_class = DictReplayBuffer | ||
| assert self.n_steps == 1, "N-step returns are not supported for Dict observation spaces yet." |
Member
There was a problem hiding this comment.
this should be reverted no? (well, anything not related to the warning)
And maybe add quick test to check that the warning is correct emitted.
Contributor
Author
There was a problem hiding this comment.
hey @araffin,
that was a fair call, my files drifted due to some merge conflicts, i changed them in my latest commit.
and for the quick test u can run this part of the test_n_step_replay.py
tests/test_n_step_replay.py::test_n_steps_warns_with_custom_replay_buffer_class -> this will raise the warning
tests/test_n_step_replay.py::test_custom_replay_buffer_class_without_n_steps -> should pass with no warning
araffin
approved these changes
Aug 16, 2026
n_steps is passed with custom replay buffer + doc update
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.
Description
Moves the n-step validation in
OffPolicyAlgorithm._setup_model()out of theif self.replay_buffer_class is None:branch, so it also applies when the user supplies thebuffer class. Previously, passing
replay_buffer_classexplicitly causedn_steps > 1to besilently ignored: the model kept
n_steps, but the buffer could not compute n-step returns, sosample()returneddiscounts=Noneand training fell back to 1-step returns with no error orwarning.
Now, when
n_steps > 1:NStepReplayBuffersubclass raises, naming the classNStepReplayBuffersubclass receivesn_steps/gamma, as the default path already doesThe subclass case uses
issubclassrather than an identity check, so user subclasses keepworking — today such a subclass silently receives the buffer's own defaults (
n_steps=3,gamma=0.99) instead of the values passed to the algorithm.Motivation and Context
Closes #2274.
This mostly affects HER users, since
HerReplayBufferis the class the docs recommend passingexplicitly —
SAC(..., replay_buffer_class=HerReplayBuffer, n_steps=3)silently trained with1-step returns. It also made the same configuration behave inconsistently: rejected with an
AssertionErroron the default path, accepted silently when the class was named.Types of changes
Marked as breaking because the Dict-obs rejection now raises
ValueErrorinstead ofAssertionError. This is the open question from the issue — I choseValueErrorso bothrejections share a type and survive
python -O, but I'm happy to keepassertif you preferthe smaller diff. Opening as a draft until you've had a chance to weigh in; no rush.
Checklist
docs/misc/changelog.md) (required).make format(required)make check-codestyleandmake lint(required)make pytestandmake typeboth pass. (required)make doc(required)Notes on verification
blackcould not run on my local Python 3.12.5 (it refuses with a CPython memory-safetywarning), so I ran it via
uvx --python 3.12.4 black— 95 files unchanged.ruffandmypypass locally.
make pytest:test_n_step_replay.py(28passed), plus
test_buffers.py,test_her.py,test_run.py,test_callbacks.py,test_save_load.py. A few failures intest_save_load.pyandtest_performance_herarepre-existing on Windows and reproduce without this change.
make pytestsuite (pytest -m "not expensive"): 877 passed, 7 failed,29 skipped. All 7 failures are pre-existing on Windows and unrelated to this change:
test_performance_her[10](a learning-performance threshold — confirmed it failsidentically with this patch reverted), two
test_monitor.pyand onetest_vec_monitor.pytests failing with
PermissionError: [WinError 32]on the monitor CSV file handle, andthree
test_save_load.pytests exercisingopen_path()where Windows raisesPermissionErrorinstead of the expectedIsADirectoryError. CI on Linux should coverall of these properly.
Disclosure per CONTRIBUTING.md: I used an AI code assistant (Claude) while investigating this
and drafting the patch. I have reviewed and tested the change and understand it.