Repository navigation
[RLlib] Fix broken rllib.models, execution, offline, and callbacks docstring examples - #67762
Merged
pseudo-rnd-thoughts merged 2 commits intoNov 4, 2026
Merged
Conversation
dstrodtman
marked this pull request as ready for review
November 3, 2026 20:59
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates, corrects, and standardizes docstring examples across several RLlib modules to ensure they are fully runnable doctests. It also resolves minor syntax errors, updates outdated API references, and aligns parameter names in the examples. The review feedback points out an opportunity to clean up the MixInMultiAgentReplayBuffer example by removing an unused variable C from a tuple assignment.
Comment on lines
+35
to
+36
| >>> A, B, C = (SampleBatch({"obs": [1]}), SampleBatch({"obs": [2]}), | ||
| ... SampleBatch({"obs": [3]})) |
Contributor
There was a problem hiding this comment.
The variable 'C' is defined in the tuple assignment but is never used or added to the buffer in the example. To keep the example clean and avoid confusing the reader, it is better to remove it.
Suggested change
| >>> A, B, C = (SampleBatch({"obs": [1]}), SampleBatch({"obs": [2]}), | |
| ... SampleBatch({"obs": [3]})) | |
| >>> A, B = SampleBatch({"obs": [1]}), SampleBatch({"obs": [2]}) |
Base automatically changed from
doc-1926-rllib-models-execution-doctests
to
master
November 4, 2026 15:18
…rllib.callbacks docstring examples and make them run Fix the examples that the stock-doctest conversion left as `testcode` or `code-block`, and the never-run examples that fail when run. Pseudocode in `ModelCatalog`, `OneHotPreprocessor`, and `RepeatedValues` becomes working code with real output, the mix-in replay buffer example checks deterministic output instead of a hidden `...`, and wrong API names in the `train_ops`, `InputReader`, and callback examples now match the source. @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]>
pseudo-rnd-thoughts
force-pushed
the
doc-1926-rllib-models-execution-example-fixes
branch
from
November 4, 2026 15:18
08b2986 to
004765e
Compare
pseudo-rnd-thoughts
approved these changes
Nov 4, 2026
pseudo-rnd-thoughts
deleted the
doc-1926-rllib-models-execution-example-fixes
branch
November 4, 2026 16:44
pseudo-rnd-thoughts
pushed a commit
that referenced
this pull request
Nov 6, 2026
…_recreated (#67770) ## Description `Algorithm._run_one_offline_evaluation` fires the `on_offline_eval_runners_recreated` callback after it restores offline evaluation runners. It passes `env_runner_group=` and `env_runner_indices=`. But `RLlibCallback.on_offline_eval_runners_recreated` declares `offline_eval_runner_group` and `offline_eval_runner_indices` as required keyword-only arguments. The `AlgorithmConfig.callbacks()` docs point callable callbacks to that signature too. So any callback that follows the documented signature raises `TypeError` when offline evaluation runners are restored: ```text TypeError: OfflineEvalRunnersRecreatedCallback.on_offline_eval_runners_recreated() missing 2 required keyword-only arguments: 'offline_eval_runner_group' and 'offline_eval_runner_indices' ``` This PR passes the documented argument names. This call site is the only place RLlib fires the callback, and the only other implementation, the `_MultiCallbacks` container in `callbacks/utils.py`, takes `**kwargs`. Ray 2.59.0 has the same bug. This PR also adds `test_on_offline_eval_runners_recreated_callback` to `callbacks/tests/test_callbacks_on_algorithm.py`. The test calls `_run_one_offline_evaluation` on a stand-in algorithm whose offline evaluation runners report two restored runners. It checks that both an `RLlibCallback` subclass and a callable, each written against the documented signature, receive the runner group and indices. It doesn't need offline data or crashing runners, so it runs in seconds. I found this while fixing the `on_offline_eval_runners_recreated` docstring example in #67762. ## Related issues Related to #67762. ## Additional information **Not a duplicate.** I searched open PRs for `on_offline_eval_runners_recreated` and found only #67762, which changes that hook's docstring example, not this call site. **Tests run** These ran in a Python 3.12 virtualenv with `ray[rllib]==2.59.0` and `torch`, with `ray/rllib` linked to this branch's source: - The new test, before the fix: it fails with the `TypeError` above. - `pytest python/ray/rllib/callbacks/tests/test_callbacks_on_algorithm.py`, after the fix: "3 passed in 68.47s." That includes the existing `test_on_env_runners_recreated_callback` and `test_on_init_and_checkpoint_loaded`. - `pre-commit run --files` on both changed files: all hooks pass. AI assistance (Claude Code) was used for this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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 docstring examples in
rllib/models,execution,offline, andcallbacksthat were wrong or couldn't run, and it converts the lasttestcodeblock in those subpackages. Where a fix is verified, the example now runs in the doctest target. After this PR, notestcodeortestoutputremains in these four subpackages.Stacked on #67761. Review that PR first. This diff is against its branch.
Examples that now run
models/catalog.py,ModelCatalog: the example used undefined placeholders, such asenvandraw_observation. It also readmodel.outputs, whichModelV2doesn't have. It's now a working CartPole example withframework="torch". It gets logits by calling the model and passes them to the distribution class.models/preprocessors.py,OneHotPreprocessor: the example calledself.transformon a random sample, and it wrote the output asnp.array(...). It now builds the preprocessor and transforms fixed values. The output is the realarray(..., dtype=float32), with the same one-hot values as before.models/repeated_values.py,unbatch_allandunbatch_repeat_dim: these were<Tensor shape=...>pseudocode, and the second one calledbatch.unbatch(), which doesn't exist. Both now use a small torch tensor and print lengths and shapes. Both docstrings gain aReturnsentry, which pydoclint requires once a docstring has anExamples:section. Each entry describes what the method body returns.execution/buffers/mixin_replay_buffer.py,MixInMultiAgentReplayBuffer: the hidden...output matched anything. The full output varies, becausereplay()appends randomly replayed samples after the newly added batches. The example now prints the first three entries,[1 2 2], which are always the newly added batches.offline/input_reader.py,InputReader.tf_input_ops: the example calledself._build_layers_v2, which doesn't exist in RLlib. It also readinput_ops["action"], but the column is"actions". It now callsself.forward(...), asexamples/_old_api_stack/models/custom_loss_model.pydoes. The prose pointed toexamples/custom_loss.py, which doesn't exist, and now points to that file.models/modelv2.py,get_initial_stateandforward: these class-definition sketches pass unchanged, so they drop+SKIP_EXAMPLE.callbacks/callbacks.py,on_offline_eval_runners_recreated: the example readis_evaluation, which isn't a parameter of this hook. It also passedremote_runner_ids=toforeach_runner, which takesremote_worker_ids. Both are fixed.callbacks/callbacks.py,on_env_runners_recreated: a comment namedlocal_worker=False, but the code passeslocal_env_runner=False.Examples that stay render-only
execution/train_ops.py,train_one_stepandmulti_gpu_train_one_step: these need a built old-API-stackAlgorithm. This PR removes the stray parenthesis and passesworker_set=tosynchronous_parallel_sample, whose arguments are keyword-only. It also prints the output as a Python dict. They stay code blocks, because anExamples:section makes pydoclint require type hints in the function signatures, and that's a code change.offline/mixed_input.py,MixedInput: this needs anIOContext, local JSON files, and an S3 path. It keeps+SKIP_EXAMPLE.Found, not fixed here
This is a code issue, not a docstring one, so it's out of scope.
Algorithm._run_one_offline_evaluationfires theon_offline_eval_runners_recreatedcallback withenv_runner_group=andenv_runner_indices=. The hook's signature incallbacks/callbacks.pydeclaresoffline_eval_runner_groupandoffline_eval_runner_indicesas keyword-only arguments with no defaults. So an override that follows the documented signature would raiseTypeErrorwhen the callback fires.Review fixes
MixInMultiAgentReplayBuffer: the example defined a batchCthat it never used, so it's gone. From a gemini-code-assist comment.Related issues
Stacked on #67761. Related to #66753.
Additional information
Not a duplicate. I searched open PRs for fixes to these docstring examples and found none.
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 the 8 changed files: "10 docstring(s) run, 0 failed, 0 skipped, in 8 file(s)."doctestpass over the same docstrings withELLIPSIS, which fails on unexpected output the way the RLlibdoctest()target does: all 10 pass.ci/ray_ci/doc/check_docstring_only.py --base doc-1926-rllib-models-execution-doctests: "8 file(s), docstrings only."pre-commit run --fileson all 8 files: all hooks pass, including pydoclint.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