Skip to content

[rllib] Move orphaned doc_code scripts out of the docs tree - #66965

Merged
elliot-barn merged 2 commits into
masterfrom
doc-1817-rllib-orphan-doc-code
Oct 15, 2026
Merged

elliot-barn merged 2 commits into
masterfrom
doc-1817-rllib-orphan-doc-code

Conversation

@dstrodtman

@dstrodtman dstrodtman commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Two scripts in doc/source/rllib/doc_code/ run under the rllib/doc_code test glob in doc/BUILD.bazel, but no docs page literalincludes either of them. This PR removes both from the docs tree.

custom_gym_env.py: deleted. It carries __rllib-custom-gym-env-begin__ markers but nothing includes it. rllib/env.md (two links), rllib/advanced-api.md, and rllib/examples.md all link to python/ray/rllib/examples/envs/custom_gym_env.py instead, which already has its own test target (examples/envs/custom_gym_env). The two files both define SimpleCorridor but have diverged (40 lines vs. 162), so readers saw the library version while CI tested the doc copy.

dreamerv3_inference.py: moved to python/ray/rllib/examples/inference/. It isn't docs content. The only reference is a GitHub URL in python/ray/rllib/algorithms/dreamerv3/README.md, so it's effectively a library example living in the docs tree. This PR:

  • Moves it with git mv next to the other inference examples.
  • Adds an examples/inference/dreamerv3_inference py_test in python/ray/rllib/BUILD.bazel, with the same examples, exclusive, team:rllib tags as its neighbors.
  • Repoints the README link.
  • Removes an unused numpy import, which ruff flags once the file is under python/ray/rllib/.
  • Wraps the script body in an if __name__ == "__main__": block, which the pytest_format lint requires for any py_test source. The other RLlib examples follow the same pattern.

After this, every script left in rllib/doc_code/ is included by a page: advanced_api.py, replay_buffer_demo.py, rllib_on_ray_readme.py, and sa_episode.py. doc/BUILD.bazel needs no change because the glob picks up whatever's left.

For RLlib maintainers: if you'd prefer a different home than examples/inference/ for the DreamerV3 script, I'll move it.

Related issues

None. Part of a docs-side cleanup of tested doc code that no page uses.

Additional information

Duplicate check: no open PRs match custom_gym_env, dreamerv3_inference, or rllib doc_code.

Testing:

  • pre-commit run on the changed files: all hooks pass, including buildifier, buildifier-lint, black, and the master-link resolver. Ruff's one auto-fix (the unused import) is included.
  • Ran the moved script from its new location against ray[rllib]==2.59.0, torch, dm_tree, and pillow on Python 3.12: it builds the DreamerV3 algorithm, runs one CartPole episode, and exits 0. I reran it after adding the __main__ block.
  • I didn't run the new Bazel target locally. CI exercises it through the rllib tag.

AI assistance (Claude Code) was used to prepare this change. I reviewed every changed line.

🤖 Generated with Claude Code

Delete doc/source/rllib/doc_code/custom_gym_env.py. No page includes
it, and every docs link points at the diverged library copy in
python/ray/rllib/examples/envs/custom_gym_env.py, which has its own test.

Move dreamerv3_inference.py to python/ray/rllib/examples/inference/,
give it a py_test target, and repoint the DreamerV3 README link. Drop
the unused numpy import that ruff flags at the new path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman requested review from a team as code owners October 13, 2026 18:25

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request moves the DreamerV3 inference script to the examples directory, cleans up its imports, adds a corresponding Bazel test target, and updates the documentation link. The review feedback suggests sorting the new Bazel test target alphabetically within its category and using a relative path instead of an absolute GitHub URL in the README.

Comment on lines +4597 to +4607
py_test(
name = "examples/inference/dreamerv3_inference",
size = "medium",
srcs = ["examples/inference/dreamerv3_inference.py"],
main = "examples/inference/dreamerv3_inference.py",
tags = [
"examples",
"exclusive",
"team:rllib",
],
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To adhere to the repository's guideline of keeping all tests sorted alphabetically within their category (as stated at the top of BUILD.bazel), the examples/inference/dreamerv3_inference target should be placed at the beginning of the inference/ subdirectory section (before examples/inference/policy_inference_after_training at line 4535), rather than at the end of the section.

References
  1. All new tests within their category should be added alphabetically in BUILD.bazel.


To run action inference on a DreamerV3 Algorithm object, you can use
[this simple environment loop script](https://github.com/ray-project/ray/tree/master/doc/source/rllib/doc_code/dreamerv3_inference.py).
[this simple environment loop script](https://github.com/ray-project/ray/blob/master/python/ray/rllib/examples/inference/dreamerv3_inference.py).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using absolute GitHub URLs for internal repository links is an anti-pattern because it always points to the master branch (which can break on older releases or forks) and is inconsistent with the rest of this README, which uses relative paths. Please use a relative path instead.

Suggested change
[this simple environment loop script](https://github.com/ray-project/ray/blob/master/python/ray/rllib/examples/inference/dreamerv3_inference.py).
[this simple environment loop script](../../examples/inference/dreamerv3_inference.py).

The pytest_format lint requires every py_test source to have an
`if __name__ == "__main__":` block. Every other RLlib example has one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Oct 13, 2026
@ray-gardener ray-gardener Bot added rllib RLlib related issues docs An issue or change related to documentation labels Oct 13, 2026
dstrodtman added a commit that referenced this pull request Oct 13, 2026
…ta-loading page's testcode (#66967)

## Why are these changes needed?

`doc/source/train/doc_code/data_ingest_torch_new.py` copies code that
`train/user-guides/data-loading-preprocessing.md` already shows inline
as `testcode`. No page `literalinclude`s the script, but the
`train/doc_code/*.py` glob in `doc/BUILD.bazel` still runs it. So the
same examples live in two places and get tested twice, and the two
copies have drifted. A fix to the page doesn't reach the script, and a
fix to the script doesn't reach the page.

This PR deletes the script. Before deleting it, I compared each of its
marked sections with the page:

- `__basic__`: The page's quickstart and the cache block cover reading
Iris, `normalize_length`, `map_batches`, and passing `datasets=` to
`TorchTrainer`. The script's other extras, a commented-out
`randomize_block_order` and `local_shuffle_buffer_size`, are covered by
the page's links to the Ray Data shuffling guide.
- `__custom_split__`: The page's "Split datasets" block is a superset.
It splits only `train` with `datasets_to_split` and calls `fit()`. The
script built the trainer but never ran it.
- `__materialized__`: The page's "Cache the preprocessed dataset" block
is a superset of this section.
- `__custom__`: Matches the page's "Advanced: Full customization" block
line for line, except that the page reads a different dataset.
- `__options__`: `DataConfig.default_ingest_options()` with an
`object_store_memory` override passed as `execution_options`. No page
shows this snippet. It only built a trainer and asserted nothing.
`DataConfig(execution_options=...)` is covered by the unit tests in
`python/ray/train/v2/tests/test_data_config.py`, and the Ray Data
performance tips page documents `resource_limits`. So I dropped it
rather than moving it onto the page.

The page needs no changes, and neither does `doc/BUILD.bazel`. The glob
picks the script up implicitly, so deleting the file removes its test
target. `git grep data_ingest_torch_new` returns nothing after this
change.

Reviewers: Is dropping the `__options__` snippet right, or should the
Train data-loading page document per-trainer ingest resource limits?

## Duplicate check

`gh pr list --state all --search data_ingest_torch_new` returns no PRs.
This is one in a series of PRs that remove doc code no page shows,
alongside #66966 (Core), #66965 (RLlib), and #66964 (Serve). None of
them touch Train.

## Testing

- `git grep data_ingest_torch_new` shows no remaining references in
`.buildkite`, BUILD files, CODEOWNERS, or docs.
- The pre-commit hooks pass on the commit.
- The page's own `doctest[train-gpu]` target still runs the blocks that
replace the script. This PR doesn't change them.

This PR was prepared with AI assistance (Claude Code). I reviewed every
changed line.

🤖 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]>
@pseudo-rnd-thoughts

Copy link
Copy Markdown
Member

None of the failures are related to the PR, suggestion is to force merge

@elliot-barn
elliot-barn merged commit 6508dc2 into master Oct 15, 2026
5 of 7 checks passed
@elliot-barn
elliot-barn deleted the doc-1817-rllib-orphan-doc-code branch October 15, 2026 18:38
dstrodtman added a commit that referenced this pull request Nov 3, 2026
#67012)

## Why are these changes needed?

Ray's docs are retiring notebooks and the `doc_code` scripts that no
page shows. This PR adds a guard so that debt can't grow back while it's
being burned down. It follows the shape of `doc/test_no_new_rst.py`.

`doc/test_doc_assets.py` checks the tracked tree, not the diff, and
fails in three cases:

1. **A new notebook.** Any `.ipynb` under `doc/source/` that isn't on
`doc/asset_allowlists/notebooks.txt`.
2. **A `doc_code` script that no page shows.** A `.py` under
`doc/source/**/doc_code/` counts as shown if any of these holds:
- A page pulls it in with `literalinclude` or `include`. RST and MyST
forms both count, as do relative and `/`-rooted paths.
   - A shown script imports it, transitively.
- It's a test wrapper. That means it imports an included script, or it
names an included file in a string literal. The second form covers the
`llm/doc_code/serve/**/*_yaml_config_example.py` scripts that load and
deploy an included YAML config, so they need no permanent exemption.

   Anything else has to be on `doc/asset_allowlists/doc_code.txt`.
3. **A stale allowlist entry.** A listed file that's gone, or that a
page now shows, also fails, so both lists only shrink. Each conversion
or cleanup PR deletes its own lines.

`python doc/test_doc_assets.py --update` rewrites both lists from the
tree. It's there for re-seeding after a rebase. The contributor docs say
not to use it to get a new file through.

### Seeded debt at this commit

- 52 notebooks.
- 10 unshown `doc_code` scripts. Two open PRs clear 7 of them: #66964
handles 5 Serve and LLM scripts, and #66965 handles the 2 RLlib scripts.
If either merges first, this PR re-seeds with `--update`. If either
merges after this one, it deletes its own allowlist lines. The scripts
with no open PR are `cluster/doc_code/simple-trainer.py` (run by the
included `slurm-basic.sh`, never shown),
`cluster/doc_code/yarn/dashboard.py`, and
`llm/doc_code/serve/custom_vllm/qwen3_reward_plugin/qwen3_rm.py` (linked
on GitHub, not included).

### Where it runs: a lint matrix entry, not a `py_test`

The check runs as `lint: doc_assets` in the `lint-small-prose` matrix
next to `doc_no_new_rst`. It doesn't run as a Bazel `py_test`, for two
reasons:

- A prose-only change can fail it. Deleting a page's last
`literalinclude` of a script orphans that script. That step keeps the
`always` tag, so it runs on every PR, including prose-only ones. A
`doc`-tagged test would miss them.
- It reads the whole `doc/source/` tree. As a `py_test`, it would need
all of `doc/source/` as `data` to get into the Bazel sandbox.

It runs postmerge as well, because non-PR builds run everything. **REEf:
please confirm this placement, the premerge gating, and the rule changes
below.**

### Routing

- `doc/test_doc_assets.py` joins `doc/test_no_new_rst.py` in the `doc`
build-infra rule in `test.rules.txt`. Without that, it falls to the
`doc/*.py` catch-all and emits `doc_example`.
- The allowlists route to nothing in `test.rules.txt`. Only the lint
step reads them, and that step runs on every PR. They get `always lint`
from the `always.rules.txt` catch-all.
- Expectations for both paths are added to `test.rules.test.txt` and
`always.rules.test.txt`.

### Limits

- The check doesn't apply Sphinx `exclude_patterns`, so a page excluded
from the build still counts as showing what it includes. At this commit,
honoring the excludes changes nothing.
- `doc/source/ray-contribute/docs.md` still describes authoring
notebooks. Rewriting it is separate work, which removes the notebook
template and replaces that guidance. Until then, the check's failure
message points to the new section in `ci.md`.

## Related issue number

None. Before opening this PR, I searched open PRs for notebook,
allowlist, `doc_code`, and orphan keywords and found no other ratchet.
#66964, #66965, #67008, and #66884 shrink or move the seeded debt, and
none of them adds a check. #64053 adds a new Serve example plus a test
that names the example script by filename. The test-wrapper rule passes
it, provided its page includes the example script.

## Checks

- [x] I've signed off every commit (DCO).
- [x] `./ci/lint/lint.sh doc_assets`: passes on this branch with the
seeded lists.
- [x] Each failure mode, exercised locally and then reverted: a new
`.ipynb` fails, a new unshown `doc_code` script fails, removing a page's
`literalinclude` fails along with the scripts that only it imported, a
stale allowlist line fails, and a test script that imports an included
script passes.
- [x] `--update` is idempotent on this tree.
- [x] `rayci test-rules`, built from `ray-project/rayci` master: all
rule tests pass, including the new expectations.
- [x] `pre-commit run` on the changed files: passed, including black and
ruff.
- [x] Cross-checked the seed against an independent scan of the same
tree. It lists the same 9 scripts, and also flags `test_service_pb2.py`,
which only an unshown script imports. #66964 deletes both of those `pb2`
scripts.

AI assistance (Claude Code) was used to prepare this PR. I reviewed
every changed line.

🤖 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs An issue or change related to documentation go add ONLY when ready to merge, run all tests rllib RLlib related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants