Repository navigation
[RLlib] Fix broken rllib.evaluation and rllib.policy docstring examples and make them run - #67768
Merged
pseudo-rnd-thoughts merged 1 commit intoNov 4, 2026
Conversation
dstrodtman
marked this pull request as ready for review
November 3, 2026 21:00
Contributor
There was a problem hiding this comment.
Code Review
This pull request systematically updates and corrects docstring examples across several RLlib modules, including sample collectors, metrics, postprocessing, rollout workers, RNN sequencing, sample batches, and view requirements. The changes ensure that these examples are valid, executable doctests by importing necessary dependencies, using up-to-date configurations (such as PPOConfig), correcting API signatures, and aligning the expected outputs with actual runtime representations. I have no feedback to provide as there are no review comments to assess.
Base automatically changed from
doc-1926-rllib-evaluation-policy-doctests
to
master
November 4, 2026 15:20
pseudo-rnd-thoughts
approved these changes
Nov 4, 2026
…es and make them run Fix rllib/evaluation and rllib/policy docstring examples that were wrong or couldn't run, and drop `+SKIP_EXAMPLE` from the ones that now run, so the RLlib doctest target checks them. The fixes cover undefined names, removed `dones` writes, plain dicts where `MultiAgentBatch` needs `SampleBatch` values, wrong function names, a missing `PPOConfig` for `RolloutWorker`, call signatures, and pseudo-reprs that didn't match real output. Examples that need placeholder objects stay render-only. @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-evaluation-policy-example-fixes
branch
from
November 4, 2026 16:22
14a40e2 to
0065b54
Compare
pseudo-rnd-thoughts
approved these changes
Nov 4, 2026
pseudo-rnd-thoughts
deleted the
doc-1926-rllib-evaluation-policy-example-fixes
branch
November 4, 2026 16:43
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.evaluationandrllib.policydocstring examples that were wrong or couldn't run. It also turns the two code-block fallbacks from #67767 back into doctests. After this PR, 17 of these docstrings run in the doctest target, and notestcodeortestoutputremains in either subpackage.Stacked on #67767. 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.get_learner_stats: the example calledget_stats, which doesn't exist, on the result ofworker.learn_on_batch(samples), whereworkerandsampleswere undefined. It now passes literalgrad_infodicts in the shape the old comment showed, covering both the single-agent and the multi-agent case.discount_cumsum: the output was a symbolic formula. It's now the realarray([4.707, 5.23 , 4.7 , 3. ]), and the formula is a comment.RolloutWorker.sample,sample_with_count,learn_on_batch,compute_gradients, andapply_gradients:PPOTF1Policyfails to build with the default config, so each example now passes aPPOConfigwith the old API stack enabled andframework("tf").sample_with_countusedPPOTFPolicyinstead ofPPOTF1Policy.sampleusedAlgorithmConfigwithout importing it.learn_on_batchandcompute_gradientspassed an undefinedsamplesinstead ofbatch.sample()returns aMultiAgentBatch, not aSampleBatch, so the outputs now show that.chop_into_sequences: the outputs now show the list of arrays and the array that the function returns. The values are the same as before.ViewRequirement:ModelV2(...)raisedTypeError. The example now builds aModelV2with real spaces. It shows that the model's only default view requirement isobs, withshift=0.SampleBatch.concat,rows,columns,shuffle,split_by_episode, andright_zero_pad:print(batch)shows a summary such asSampleBatch(5: ['a']). The examples now print columns, and the outputs are real.split_by_episodeset a"dones"column, whichSampleBatchrejects withKeyError. It now sets"terminateds", which the splitter reads.shufflenow seeds NumPy, so its output is fixed.concat_samplesandconcat_samples_into_ma_batch:MultiAgentBatch, which asserts onSampleBatchvalues.concat_samplescall concatenatedb1andb2instead ofc1andc2.concat_samples_into_ma_batchexample calledconcat_samples.MultiAgentBatchrepr and the concatenated columns.The five
RolloutWorkerexamples build old-API-stack TF1 PPO policies. They take about 9 seconds together on CPU. Their outputs show 2,000 sampled steps, which comes from PPO's default config. I ran them locally, but not under Bazel. If RLlib would rather not run old-API-stack TF code in the doctest target, re-adding# doctest: +SKIP_EXAMPLEkeeps the corrected examples render-only.Fixed but still render-only
RolloutWorkerclass docstring: the single-agent half gets the same config fix and runs. The multi-agent half uses placeholders andPGTFPolicy, which RLlib no longer has, so the docstring stays skipped.RolloutWorker.set_global_vars: the stray...is gone, and so is the assignment of the method'sNonereturn value. It's a doctest again.SampleCollector.add_init_obs,add_action_reward_next_obs, andget_inference_input_dict:add_action_reward_next_obscalls now passenv_id.add_init_obsis called with keywords, since its arguments are keyword-only.get_inference_input_dictgets a policy ID, notpolicy.model, and its dict syntax error is fixed.envandcollectorobjects.ObservationFunction.__call__,Policy.learn_on_batch,Policy.export_checkpoint,TFPolicy, andRolloutWorker.get_weights,set_weights, andget_global_varsuse placeholder objects. They're unchanged and stay render-only.Found, not fixed here
These need RLlib's call, so this PR leaves them alone:
SampleCollector.add_init_obshas noenv_idparameter, butSimpleListCollector.add_init_obs, its only implementation, requires one. The example follows the abstract signature.get_global_varsoutput,{"timestep": 424242}, leaves outnum_grad_updates_per_policy, which the real dict contains.Related issues
Stacked on #67767. 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 7 changed files: "17 docstring(s) run, 0 failed, 8 skipped, in 7 file(s)."doctestpass over the same docstrings withELLIPSIS. Unlike the runner above, it fails on unexpected output, the way the RLlibdoctest()target does. All 17 runnable docstrings pass, and the rest carry+SKIP_EXAMPLE.ci/ray_ci/doc/check_docstring_only.py --base doc-1926-rllib-evaluation-policy-doctests: "7 file(s), docstrings only."pre-commit run --fileson all 7 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