Repository navigation
[RLlib] Fix broken rllib.utils docstring examples and make them run - #67755
Merged
Merged
Conversation
dstrodtman
marked this pull request as ready for review
November 3, 2026 20:56
Contributor
There was a problem hiding this comment.
Code Review
This pull request focuses on updating, correcting, and standardizing docstring examples and doctests across various RLlib utility modules, including actor manager, filters, replay buffers, and space utilities. It replaces outdated test blocks with standard doctest formats, fixes incorrect class and decorator references, and updates expected outputs to match actual runtime behavior. No review comments were provided, so there is no additional feedback to address.
Fixes the rllib.utils docstring examples that were wrong or couldn't run, and converts the last `testcode` blocks in rllib/utils that needed a code, output, or prose change. Fixed examples that run now drop `+SKIP_EXAMPLE`, so the doctest target checks them. @rtd-build Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
Fixes issues gemini-code-assist found in the converted examples: unused or duplicated imports and variables, example code that mutates shared state or drops data, and a typo. @rtd-build Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
dstrodtman
force-pushed
the
doc-1926-rllib-utils-example-fixes
branch
from
November 4, 2026 16:26
4e40202 to
9af43eb
Compare
pseudo-rnd-thoughts
approved these changes
Nov 4, 2026
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
This is a correctness change for RLlib review. It fixes
rllib.utilsdocstring examples that were wrong or couldn't run, and it converts the lasttestcodeblocks inrllib/utils. Those blocks needed a change to code, output, or prose, so they stayed out of the syntax-only conversion in #67753. After this PR, notestcodeortestoutputremains inrllib/utils.Stacked on #67753. Review that PR first. This diff is against its branch.
Examples that were broken and now run
Before this PR, each of these was
:skipif: Trueand failed when run. Each now runs, and the+SKIP_EXAMPLEflag is gone, so the doctest target checks it.numpy.flatten_inputs_to_1d_tensor: the example imported the function fromtf_utils, not fromnumpy. It builtBox(shape=...)without thelowandhigharguments Gymnasium requires, passed a ragged list for"b", and passed plain lists where the function needs NumPy arrays. The outputs now show what the function returns. The values are the same as before.MeanStdFilter.apply_changesandMeanStdFilter.sync:running_stats.meanis a 0-d array, so the output readsarray(1.5), not1.5.a(1)returns the filtered value, which a doctest would echo, so the example now discards it._NotProvided: the example passedpreprocessor_prefto.training().AlgorithmConfig.env_runners()is the method that sets it. The printed default isdeepmind, without quotes.space_utils.get_base_struct_from_spaceandflatten_to_single_ndarray: the first example now imports the Gymnasium spaces and givesBoxbounds. Both outputs are the real reprs. Before, they were pseudo-reprs such asdict(a=Box(), ...).RemoteCallResults: the example usedactorswithout defining it. It now defines the same three-actor setup asFaultTolerantActorManager.testcodeblocks this PR convertsFaultTolerantActorManager: the async half slept for two seconds and printed whatever was ready, so its output depended on timing. It now callsfetch_ready_async_reqs(timeout_seconds=None), which waits for every in-flight request, so it printsTruethree times.foreach_actor_asyncreturns a count, which the example now discards.ReplayBuffer: the prose said theTrueoutput was a Sphinx artifact.print(buffer._eviction_started)prints it, so the output now sits under that line, and the prose is gone. Thebuffer.sample(1)calls discard their result.remove_last_ts_from_data, inpostprocessing/episodes.py: the directive was..testcode::without a space, so it rendered as an rST comment. The example calledPPOLearner._remove_last_ts_from_data, which doesn't exist. The function isremove_last_ts_from_datain the same module. The function returns a bare array when it gets one data item, not a tuple, so the first assertion now comparesunpadded, notunpadded[0].Returnsnow says so too.unpad_data_if_necessary, inpostprocessing/zero_padding.py: the directive had the same missing space. The example was correct and runs unchanged._find_offending_sub_space, inpre_checks/env.py: the example didn't parse. It's rebuilt from what was legible, aBox(-2.0, 1.5, (2,), np.int8)and the valuenp.array([-1.5, 3.0]), wrapped in aDictspace so there's a path to report. The function is private and isn't in the API reference.MultiAgentMixInReplayBuffer: the five blocks are pseudocode (buffer.add(<A>)) with descriptive outputs, so they becomepythonandtextcode blocks. The fourth block constructedMixInReplay, which doesn't exist. It now constructsMultiAgentMixInReplayBuffer.Fixed but still render-only
tf_utils.flatten_inputs_to_1d_tensor: the same input fixes as thenumpyversion. The calls ran intoTypeErrorbefore and run now. They stay+SKIP_EXAMPLE. Under RLlib's TensorFlow setup the tensors are graph-mode, soprint(out)shows a tensor name, not the values the example shows.annotations.py: two examples decorated with@overrides. The decorator isoverride.tf_utils.one_hot,make_action_immutable, and the otherannotations.pyexamples are unchanged and stay render-only.Review fixes
These address gemini-code-assist comments on #67753:
torch_utils.flatten_inputs_to_1d_tensor: the"c"key of the example dict is now indented like"a"and"b".MultiAgentEpisodeReplayBufferandMultiAgentPrioritizedEpisodeReplayBuffer: the examples appended"__all__"toenv.agents, which is the env's own list, so the env then listed"__all__"as an agent. They now build a new list.Related issues
Stacked on #67753. Related to #66753.
Additional information
Not a duplicate. I searched open PRs for RLlib
testcode, doctest, and docstring-example changes, and none touches these docstrings.Tests run
These ran in a Python 3.12 virtualenv with
ray[rllib]==2.59.0,torch, andtensorflow2.21:ci/ray_ci/doc/run_docstring_examples.pyon all 16 changed files: "18 docstring(s) run, 0 failed, 8 skipped, in 16 file(s)."doctestpass over the same docstrings withELLIPSIS. Unlike the runner above, it fails on unexpected output, the way the RLlibdoctest()target does. All 18 runnable docstrings pass, and the rest carry+SKIP_EXAMPLE. The seven runnable docstrings from [RLlib] Convert rllib.utils docstring examples to stock doctests #67753 pass this check too.tf_utilsexamples run with+SKIP_EXAMPLEremoved. Every call succeeds, and only the graph-mode output differs.ci/ray_ci/doc/check_docstring_only.py --base doc-1926-rllib-utils-doctests: "16 file(s), docstrings only."pre-commit run --fileson all 16 files: all hooks pass.The PR carries the
docstring-onlylabel. Its commit carries an@rtd-buildline for the Read the Docs preview.AI assistance (Claude Code) was used for this PR.
🤖 Generated with Claude Code