Skip to content

docs: add policy lifecycle guide for custom training loops - #2644

Open
lonexreb wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
lonexreb:docs/1141-policy-lifecycle-guide
Open

docs: add policy lifecycle guide for custom training loops#2644
lonexreb wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
lonexreb:docs/1141-policy-lifecycle-guide

Conversation

@lonexreb

Copy link
Copy Markdown
Contributor

Summary

Closes #1141.

The issue asked for either documentation or a more helpful error when a user writes a custom training loop and forgets to call `prepare_for_lp_inference()` / `prepare_for_training()` before a GPU-bound API call. The typical symptom — an opaque `RuntimeError: CUDA error: an illegal memory access` deep in a model forward pass — gives no hint that the cause is a missing `prepare_*` call.

This PR is the documentation half of that ask. The runtime-error half is covered by PRs #2392 / #2393 (offload guards) which raise an actionable `RuntimeError` naming the missing `prepare_*` call.

What changed

  • New doc: `docs/design-docs/policy-lifecycle.md` — explains the policy state machine (training ↔ logprob/inference ↔ offloaded), the contract for `prepare_for_training()` / `prepare_for_lp_inference()`, what happens if you skip the prepare step, and a minimal custom training-loop example that calls everything in the right order.
  • Docstrings: `nemo_rl/models/policy/interfaces.py` — filled in the previously-empty docstrings on `prepare_for_training` and `prepare_for_lp_inference` with a one-paragraph summary + pointer to the new doc, so `help(PolicyInterface)` is immediately useful when reading the source.
  • `docs/index.md` — added the new doc to the `Design Docs` toctree.

Test plan

  • `ruff check` on the interface change — clean
  • `python3 -m py_compile` on the interface change — clean
  • Markdown lint / Sphinx build in CI (purely additive doc + toctree entry, no broken cross-refs)

Cross-refs

@lonexreb
lonexreb requested review from a team as code owners May 30, 2026 07:19
@copy-pr-bot

copy-pr-bot Bot commented May 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added Documentation Improvements or additions to documentation community-request labels May 30, 2026
lonexreb added a commit to lonexreb/RL that referenced this pull request May 30, 2026
The state table and the two preparation-method sections previously
described the optimizer movement as unconditional ("frees optimizer
state", "moves optimizer back to GPU"). In practice the optimizer
follows the weights only when `offload_optimizer_for_logprob=true`
(or, for training, when `is_generation_colocated` is set as well),
per the implementations in dtensor_policy_worker.py and
megatron_policy_worker.py.

Reword the state-table column header, prepare_for_training and
prepare_for_lp_inference sections, and the matching interfaces.py
docstrings so the conditional behavior is explicit and config-driven.
Caught in self-review of NVIDIA-NeMo#2644.

Signed-off-by: Shubhankar Tripathy <reach2shubhankar@gmail.com>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Jun 1, 2026
Closes NVIDIA-NeMo#1141.

Adds `docs/design-docs/policy-lifecycle.md` documenting the policy
state machine (training / logprob-inference / offloaded), the contract
for `prepare_for_training()` and `prepare_for_lp_inference()`, the
opaque CUDA "illegal memory access" failure mode users hit when they
skip a `prepare_*` call in a custom training loop, and a minimal
reference loop that calls everything in the right order.

Also fills in the previously empty docstrings on the abstract methods
in `nemo_rl/models/policy/interfaces.py` with a one-paragraph
summary + a pointer to the new doc, so `help(PolicyInterface)` is
immediately useful when someone reads the source.

The doc is linked from the `Design Docs` toctree in `docs/index.md`.

This is the documentation half of the request in NVIDIA-NeMo#1141; the
"more helpful error" half is covered by PRs NVIDIA-NeMo#2392 / NVIDIA-NeMo#2393, which add
runtime guards that resolve to `prepare_for_lp_inference()` /
`prepare_for_training()` in the failure message.

Signed-off-by: Shubhankar Tripathy <reach2shubhankar@gmail.com>
The state table and the two preparation-method sections previously
described the optimizer movement as unconditional ("frees optimizer
state", "moves optimizer back to GPU"). In practice the optimizer
follows the weights only when `offload_optimizer_for_logprob=true`
(or, for training, when `is_generation_colocated` is set as well),
per the implementations in dtensor_policy_worker.py and
megatron_policy_worker.py.

Reword the state-table column header, prepare_for_training and
prepare_for_lp_inference sections, and the matching interfaces.py
docstrings so the conditional behavior is explicit and config-driven.
Caught in self-review of NVIDIA-NeMo#2644.

Signed-off-by: Shubhankar Tripathy <reach2shubhankar@gmail.com>
@lonexreb

Copy link
Copy Markdown
Contributor Author

/ok to test a51e67a

@lonexreb
lonexreb force-pushed the docs/1141-policy-lifecycle-guide branch from 8710921 to a51e67a Compare August 30, 2026 07:03
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More helpful error message if prepare_for_*() not called

2 participants