Skip to content

[RLlib] Advance weights version after unversioned module state updates - #67131

Open
lindicaphxag-tech wants to merge 5 commits into
ray-project:masterfrom
lindicaphxag-tech:fix/rllib-version-unversioned-set-state-20261018
Open

lindicaphxag-tech wants to merge 5 commits into
ray-project:masterfrom
lindicaphxag-tech:fix/rllib-version-unversioned-set-state-20261018

Conversation

@lindicaphxag-tech

@lindicaphxag-tech lindicaphxag-tech commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Related to #61960. This PR fixes the generic Learner/LearnerGroup state-version invariant; the self-play callback publication/order fix is in #67103.

An unversioned COMPONENT_RL_MODULE update changes Learner parameters without advancing WEIGHTS_SEQ_NO. EnvRunners using pull-if-newer synchronization can therefore retain stale weights and skip the update.

Scope is intentionally limited to the generic Learner/LearnerGroup state-version invariant:

  • Applying a module state without a positive version advances the Learner's sequence number, making the mutation visible to downstream synchronization.
  • An explicit version-zero checkpoint round-trip on a fresh Learner preserves version zero; a subsequent manual unversioned write advances it.
  • A stale positive version cannot downgrade the sequence number or overwrite newer module parameters.
  • The separate self-play callback publication/order fix is handled in [RLlib] Sync newly cloned self-play module weights immediately #67103 to avoid overlapping implementation here.

Regression coverage

  • Learner-level test mutates a NumPy-backed module parameter and verifies the unversioned update advances the version.
  • LearnerGroup-level test exercises the public module-only set_state path and verifies the version advances.
  • Stale-version test uses the observed initial sequence number, deliberately changes a copied parameter payload, and verifies that an older positive version neither changes the live parameter nor downgrades the sequence number.
  • Explicit-zero checkpoint test distinguishes restoring the initial state from an unversioned manual write.
  • New predicates follow the repository's 88-column formatting convention.

Validation (2026-10-23; current head)

  • Head: b845e62f77bc9fc6dc4e66f5093274e0c5933384.
  • DCO, Cursor Bugbot, and Buildkite Release #111963: passed.
  • ReadTheDocs #4618205: passed.
  • Buildkite Microcheck #56975: pending at last check. Earlier Microchecks failed; without failing-step logs, the cause is unverified. This PR is not yet fully CI-green.
  • Focused independent source-level and native Learner validations passed on the author's fork; these do not replace the upstream integration check.

@lindicaphxag-tech
lindicaphxag-tech requested a review from a team as a code owner October 17, 2026 17:49

@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 ensures that unversioned module-state updates (where weights_seq_no is 0) increment the learner's weights sequence number, preventing EnvRunners from skipping these weights during synchronization. A unit test was also added to verify this behavior. Feedback suggests addressing an existing inconsistency in set_state where the sequence number can be downgraded to an older value even when the module state update is skipped.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 89eec46. Configure here.

@ray-gardener ray-gardener Bot added rllib RLlib related issues community-contribution Contributed by the community labels Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

I narrowed this PR to the generic Learner/LearnerGroup state-version invariant and removed the SelfPlay callback sync hunk to avoid overlapping with #67103. The remaining scope is: (1) an unversioned COMPONENT_RL_MODULE mutation advances WEIGHTS_SEQ_NO; (2) stale versioned state cannot downgrade the current sequence; (3) regression tests exercise actual NumPy-backed module state and LearnerGroup propagation. The separate callback PR should own the ordering/installation guarantee for newly cloned opponent modules. I pushed the scope reduction to fork head 5881c971f91417606ab45f697c344fe8239ae4e2. I’ll treat this PR as not merge-ready until the exact-head Microcheck is green and the review concerns are resolved.

@lindicaphxag-tech
lindicaphxag-tech force-pushed the fix/rllib-version-unversioned-set-state-20261018 branch from 5881c97 to 3f9ab4b Compare October 18, 2026 12:14

Copy link
Copy Markdown
Contributor Author

Correction to my previous update: I replaced the unsigned scope-reduction commit with a signed-off equivalent to preserve the DCO requirement. Current head is 3f9ab4b196a6cf2a678d2b8f625f85a4784e2688 (same tree and parent as the scope-reduction commit; only the commit message adds the Signed-off-by trailer). The exact-head checks need to finish before I claim this is green.

@lindicaphxag-tech
lindicaphxag-tech force-pushed the fix/rllib-version-unversioned-set-state-20261018 branch from 3f9ab4b to 1901f0b Compare October 18, 2026 12:18

Copy link
Copy Markdown
Contributor Author

Follow-up: I consolidated the branch into one DCO-signed commit while preserving the exact three-file PR diff and based it directly on the current master base (95d3a43269d92ed2f255801399abc428d580600b). New head: 1901f0b215ba3d7a62cdf91620653a2924d93422. The DCO check now reports success (“All commits are signed off!”). The callback sync hunk remains removed so this PR only addresses generic Learner/LearnerGroup version semantics. Release passed; Microcheck #56516 is scheduled and ReadTheDocs is still running, so I am not claiming the PR is green until those finish.

Distinguish an explicit version-zero checkpoint restored on a fresh
Learner from a versionless manual weight mutation. Keep version monotonic
when an explicit zero state overwrites already newer parameters.

Actual Learner.set_state source AST: baseline red, revised green.
Ray 2.59.0 native Learner with development method: green.
Evidence: github.com/lindicaphxag-tech/ray/actions/runs/39955155935
          github.com/lindicaphxag-tech/ray/actions/runs/39955479007

Signed-off-by: Zhibo Zhang <[email protected]>
pseudo-rnd-thoughts pushed a commit that referenced this pull request Nov 4, 2026
…ts, bounded game-server startup (#67594)

Before this PR:
- The `learning_tests_appo_footsies_*` postmerge tests time out often.
Each Learner update takes `4096 * num_env_runners` = 81,920 env steps at
`lr=1e-4`, but the game server answers one env step per 60 FPS frame
(~57 steps/s per EnvRunner). The policy gets its first gradient update
after ~3 minutes, and the target network never updates. Against the
frozen copy the training win rate stays at 0.5, so the test passes only
when a 10-episode eval happens to exceed 0.8 (e.g. eval 0.81 at training
win rate 0.49).
- `MixManagerCallback` initializes each new frozen opponent with
`Algorithm.set_state()`. The EnvRunners skip those weights because the
weights version doesn't change (#67131 fixes that in the Learner). The
training EnvRunners therefore play the opponent's random init, while
evaluation uses the real copy.
- If a game server never gets ready,
`FootsiesBinary.start_game_server()` polls forever (no deadline, no
liveness check, no gRPC timeout), and setup hangs until the 900 s
timeout. In a stress test, 3 of 240 concurrent server starts never got
ready.

After this PR:
- 2048 env steps per Learner update, minibatches of 256, `lr=5e-4`,
`target_network_update_freq=0.5`.
- `MixManagerCallback` pushes the copied weights to all (eval)
EnvRunners. An eval round without a decisive episode no longer raises a
`KeyError`.
- The game server gets 120 s to get ready (5 s gRPC timeouts, process
liveness check); otherwise it's killed and relaunched, up to 3 times.

Validation on Anyscale (nightly image + this PR's three files, no
#67131), each seed the CI test's args in a fresh driver with a 900 s cap
including startup:

| CI target | hardware | passed | wall time |
|---|---|---|---|
| `learning_tests_appo_footsies_single_gpu` | 4×L4, 48 vCPU | 10/10 |
174–419 s |
| `learning_tests_appo_footsies_multi_gpu` | 4×L4, 48 vCPU | 10/10 |
239–422 s |
| `learning_tests_appo_footsies_single_gpu_no_aggregator_actors` | 4×L4,
48 vCPU | 10/10 | 174–418 s |
| `multi_gpu` args, 2 Learners on 2 nodes (1×L4 each) + CPU EnvRunner
nodes | 4 nodes | 10/10 | 217–357 s |

Stock master on a 1×L4 node passed 1 of 1 attempt by eval luck, and
`+#67131` alone failed in 1,500 s. A 4 h run on the 4-node cluster kept
Learner, aggregator, EnvRunner and Algorithm memory flat. The
game-server launcher fix started 360/360 servers in a stress test,
relaunching one server twice. `pre-commit run --files` passes on all
three files.

Not a duplicate: no open PR touches the footsies example. #67131 fixes
the weights-version root cause in `Learner.set_state`, and #67103 only
fixes the league-based self-play callback; this PR doesn't depend on
either.

AI assistance (Claude Code) was used for the investigation, the
experiments and the change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Nov 7, 2026
@lindicaphxag-tech
lindicaphxag-tech force-pushed the fix/rllib-version-unversioned-set-state-20261018 branch from 641454c to b845e62 Compare November 17, 2026 08:15
@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Nov 17, 2026
@lindicaphxag-tech

Copy link
Copy Markdown
Contributor Author

Converting to draft: the same Buildkite Microcheck gate that blocks #67103 applies here, its traceback is not readable from this account, and no maintainer has responded since the PR opened. The diff itself is green on DCO/Release.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community rllib RLlib related issues unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant