refactor(algorithms): extract advantage estimators - #27
Draft
leviking98z-rgb wants to merge 1 commit into
Draft
Conversation
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
Extracts reward-to-advantage policy from
Partand trainer-specific helpers into a reusable algorithm-layer component.AdvantageBatch,AdvantageEstimate, and structuralAdvantageEstimatorcontracts.advantage:Hydra component.Part.compute_advantages, the standalone normalizer module, and the old types-owned GAE module.This removes 421 lines of old helpers and trainer policy. The reusable implementation, typed contracts, compatibility wiring, docs, and persistent guard make the slice net +125 lines; its purpose is to stop GDPO, PPO/value-head, and future estimators from adding branches to every trainer.
Related Issue
N/A
Test Plan
SKIP=no-commit-to-branch pre-commit run --all-files --show-diff-on-failure— passed, including Ruff, recipe targets, experimental boundaries, architecture boundaries, and framework contracts.python -m compileall -q unirl lint/check_framework_contracts.py— passed.python lint/check_architecture_boundaries.py— passed: 473 files / 4,264 internal import edges satisfy 8 boundaries.python lint/check_framework_contracts.py— passed: 7 rollout engines, 6 weight syncs, 19 model pipelines, 2 train backends, 2 wire types, 5 advantage contracts, 4 loop programs, and 13 entrypoints conform.python lint/check_recipe_targets.py— passed: 2,311 recipe_target_paths resolve.Nonegroup id.Compatibility / Risk
adv_normalization_scope,normalize_adv_by_std, andadv_use_global_std. An explicitadvantage:block takes precedence.Sample/Partwire-field migration is required;Partstill carries rewards, component rewards, and resulting advantages.Part.compute_advantages,unirl.algorithms.normalizers, andunirl.types.advantages. Out-of-tree callers should useestimate_part_advantagesor anAdvantageEstimator.GeneralizedAdvantageEstimatoris the algorithm contract only; a value-based trainer must supply values and masks.Reviewer Notes
refactor/rollout-capability-interfaces) and should be reviewed as the next framework-kernel slice.Partand trainer conditionals. Upstream refactor(trainer): extract the sync-loop template into BaseTrainer Tencent-Hunyuan/UniRL#282 concerns the synchronous loop template and is orthogonal to estimator ownership.Checklist