Repository navigation
Conversation
This branch has not been deployed
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.
Stacked on #2186 (
stack/rl-ppo).Root cause
Routed-expert
ObjectRefs are shared: partial rollouts concatenate them, the trace store keeps them per session, sibling samples and trainable segments can point at the same object, and the actor reads each pack several times (old/ref/teacher/train). Several holders still callray.internal.freeon them:reset_rollout_response, trace-store release,_resolve_routed_expertsafter the first read, and the actor'sfree_rollout_routed_expert_refsat the end of fit. A force-free by one holder invalidates the object for every other holder.free_rollout_routed_experts_in_worker/_agent_loop_manager_uses_trace_storeonly switch off one of those paths.Fix
Use Ray reference counting instead of explicit frees. Each holder drops its own reference when its lifetime ends (reset/discard, session release, after the training batch), and Ray reclaims the object after the last one.
free_rollout_routed_experts_in_workeroption and the trace-store special case in the trainer.free_rollout_state_refsdetachesrouted_expertsbefore freeing the payloads the state owns exclusively.routed_expertsafter fit, together with releasing its trace sessions.ObjectRefreceived over HTTP is rejected, because an out-of-band ref cannot take part in reference counting.Test plan
tests/rl/test_routed_experts_lifetime.pyruns against a local Ray cluster. It covers reset/discard keeping sibling routes alive, partial-rollout concatenation keeping borrowed inputs, trace-store overwrite and batch release keeping other consumers, repeated batches leaving no object references in the owner, and the trained batch releasing its refs while an external borrower keeps the data.test_trace_store.pyandtest_rollout_logic.pyare updated for the new lifetime. With the trainer and PPO role suites (test_rl_colocate_trainer.py,test_rl_disaggregated_trainer.py,test_ppo_role_wiring.py,test_routed_experts_dtype.py,test_training_worker_rank.py): 156 passed on CPU.