feat(orchestrator): EnvMixStrategy seam for env selection#2743
Open
hallerite wants to merge 1 commit into
Open
feat(orchestrator): EnvMixStrategy seam for env selection#2743hallerite wants to merge 1 commit into
hallerite wants to merge 1 commit into
Conversation
Extract TrainSource's weighted round-robin env pick into a swappable EnvMixStrategy (default WeightedRoundRobin). Example selection (the reshuffling cursor) stays in TrainSource. The strategy draws from TrainSource's RNG, so the example sequence is unchanged — pure extraction, no behavior delta. Separates 'which env' from 'which example' as the seam slice (c) builds on. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Extract
TrainSource's weighted round-robin env selection into a swappableEnvMixStrategyseam (defaultWeightedRoundRobin). Example selection — the per-env reshuffling cursor — stays inTrainSource.This is slice (b) of the composable algorithm abstraction: cleanly separate which env (global
EnvMixStrategy) from which example (per-env, slice c builds on this).Changes
orchestrator/sampling.py(new):EnvMixStrategyABC +WeightedRoundRobindefault.pick()returns the next env name via weighted random choice.TrainSourcedelegates the env pick toself.env_mix.pick(); it still owns dataset loading, the per-env cursor, reshuffle-on-exhaustion, andenv_costs.Behavior
Behavior-preserving.
WeightedRoundRobindraws fromTrainSource's existing RNG (injected), so env selection stays in the same stream as the dataset shuffles — the example sequence is identical to before. (Partitioning RNG per-env is a slice-(c) change, not here.) The public API (TrainSource(train_envs, seed)+next_example) is unchanged.Testing
ruff check+ruff format --checkclean.tests/unit/orchestrator/test_sampling.py(new):WeightedRoundRobindeterminism per seed, weight respecting (incl. zero-weight never picked), empty-envs guard.tests/unit/test_configs.py(106) pass; imports resolve.🤖 Generated with Claude Code
Note
Low Risk
Refactor with default implementation matching prior logic;
TrainSourceAPI and dispatcher wiring unchanged.Overview
Introduces a swappable env mix seam for training rollouts: global “which env next?” is no longer inlined in
TrainSource.New
orchestrator/sampling.pydefinesEnvMixStrategyand defaultWeightedRoundRobin, which picks an env name via weighted random choice (same weight rules as before: per-envratiowhen all set, else dataset size).TrainSourcenow callsself.env_mix.pick()instead ofrng.choicesdirectly; it still owns datasets, per-env cursors, reshuffle-on-exhaustion, permit costs, andnext_example’s public contract.Behavior-preserving:
WeightedRoundRobinusesTrainSource’s existingrandom.Randominstance so env picks stay in the same RNG stream as dataset shuffles.Tests:
tests/unit/orchestrator/test_sampling.pycovers determinism, weight behavior (including zero weight), and empty-env validation.Reviewed by Cursor Bugbot for commit 84370ab. Bugbot is set up for automated code reviews on this repo. Configure here.