Repository navigation
chore(orchestrator): fold GenerationSource into TrainEnv - #3838
Merged
Merged
Conversation
This was referenced Oct 4, 2026
faresobeid
marked this pull request as ready for review
October 4, 2026 12:28
samsja
pushed a commit
that referenced
this pull request
Oct 4, 2026
…alize_group (#3845) Two small cleanups in `orchestrator/algo/`. Item 4 of the orchestrator review. - `action_loss_type` is now declared once, on the algorithm config classes. Before, it was declared on the config classes and again on the runtime classes (`algo/base.py`, `sft.py`, `opd.py`, `opsd.py`), and `build_algorithm` asserted that the two agreed. Now `Algorithm.__init__` copies it from the config, so `train_sink`'s `env.algorithm.action_loss_type` is unchanged. - `Algorithm.finalize_group` is removed. It only called `score_group`, and `train_sink` now calls `score_group` directly. `finalize_episode` is kept: its "has sampled tokens" guard matters for `echo`, whose `score_episode` does not filter on the mask. - `docs/algorithms.md` is updated to match. Behavior change: none. Every algorithm type gets the same loss routing as before, because the old assert guaranteed that the config and runtime values were equal. ## Checks - `pytest tests/unit/orchestrator tests/unit/test_configs* -m "not gpu"`: 291 passed (`test_algorithms` covers the per-type `action_loss_type`). - `ruff check`, `ruff format --check`: clean. GPU checks: none needed. ## Conflicts `algo/base.py` and `algo/__init__.py`: #3802, #3803 (small). #3838 (fold `GenerationSource`) also edits `algo/base.py` and `algo/__init__.py` (`connect_frozen_client`), which needs a trivial rebase. `train_sink.py:245`: #3652 rewrites `train_sink.py` (a one-line change there). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Refactor-only: loss routing and group scoring call paths are unchanged in effect; no auth, data, or trainer hot-path logic changes. > > **Overview** > **Single source of truth for loss routing:** runtime `Algorithm` instances now take `action_loss_type` from the algorithm config in `__init__` instead of duplicating it on each subclass and asserting agreement in `build_algorithm`. Per-algorithm class variables on `OPD`, `OPSD`, and `SFT` are removed; `train_sink` still reads `env.algorithm.action_loss_type` when stamping samples. > > **Thinner scoring API:** `Algorithm.finalize_group` is dropped and the train sink calls `score_group` directly when a group has trainable survivors. `finalize_episode` remains as the guarded entry point for rollout-local `score_episode` (skips episodes with no trainable sampled tokens). > > **Docs:** `algorithms.md` is updated to describe this pipeline wiring and config-owned `action_loss_type`. > > No intended training behavior change—loss routing values are the same as before when config and runtime matched. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1ebee7f. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
faresobeid
force-pushed
the
chore/fold-generation-source
branch
from
October 7, 2026 18:58
2693eb4 to
e89ca1a
Compare
mikasenghaas
approved these changes
Oct 7, 2026
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.
Summary
Fold
GenerationSourceintoTrainEnv, its only owner. Moveconnect_frozen_clientfromalgo/base.pytoclients.py, soalgono longer importsclientslazily. GiveTrainEnvsetup()/aclose()so orchestrator setup and teardown no longer reach into its parts.What changed
orchestrator/generation_source.pyis deleted.TrainEnv(envs.py) now holdsclients,renderer_config,connected(the frozen source clients it connected) anduses_live_policy. Droppinglogprobsfor frozen sources happens inTrainEnv.__init__.TrainEnv.setup()connects the frozen generation source and runsalgorithm.setup()concurrently.TrainEnv.aclose()closesconnectedandalgorithm.connected, never the shared policy clients.connect_frozen_clientis a plain function inclients.py, next tocheck_inference_ready.algo/base.pyimports it at module level. It is no longer re-exported fromprime_rl.orchestrator.algo.dispatcher.pyreads theTrainEnvdirectly at the four formergeneration_sourcecall sites.orchestrator.pycallsenv.setup()andenv.aclose().docs/algorithms.mdand thealgo/__init__.pydocstrings refer toTrainEnv.Behavior change
None.
Checks run
pytest tests/unit/orchestrator tests/unit/test_configs* -m "not gpu": 297 passed.ruff check,ruff format --check: clean.GenerationSource(origin/main) vs newTrainEnv, on 4 configs: policy, policy withtop_p=0.9, sft with a frozensampling.source, opd with a frozen teacher. Identicalsampling_args,requires_sampling_masksanduses_live_policy. Aftersetup(), the same generation clients (policy object, or the frozen endpoint with the same train client config) and the same algorithm clients. Teardown closes the same clients.sampling.source(5 steps), opd with a frozen teacher (5 steps). All three ran to "Training finished" and exited 0.Note
Low Risk
Internal orchestrator refactor with stated behavioral equivalence and no changes to training algorithms or dispatch semantics beyond indirection.
Overview
Refactors train rollout sourcing by deleting
GenerationSourceand moving its responsibilities ontoTrainEnv: inferenceclients, live-vs-frozen policy detection (uses_live_policy), sampling-arg tweaks (e.g. droppinglogprobsfor frozen endpoints), and frozen-pool connection insetup().TrainEnv.setup()now connects frozensampling.sourceendpoints and runsalgorithm.setup()together;TrainEnv.aclose()closes only env-owned clients (connected+ algorithm pools), not the shared policy pool. The orchestrator and dispatcher call these surfaces instead of reaching into a nestedgeneration_source.connect_frozen_clientmoves fromalgo/base.pytoclients.py(next tocheck_inference_ready); it is no longer re-exported fromprime_rl.orchestrator.algo. Docs and package docstrings now describeTrainEnvas owning the sampling half of the algorithm config.Reviewed by Cursor Bugbot for commit e89ca1a. Bugbot is set up for automated code reviews on this repo. Configure here.