You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
The advantage estimators in nemo_rl/algorithms/advantage_estimator.py share no base class or Protocol, so the contract is entirely informal and fragile:
Inconsistent return types.compute_advantage returns a bare tensor in GRPOAdvantageEstimator, GDPOAdvantageEstimator, ReinforcePlusPlusAdvantageEstimator, and OPDAdvantageEstimator, but a (advantages, returns) tuple in RawRewardAdvantageEstimator and GeneralizedAdvantageEstimator. Callers must "know" which is which.
Metrics via side-channel.OPDAdvantageEstimator emits logging metrics as a side effect into self.last_metrics (advantage_estimator.py:537,586) rather than returning them, and the caller peeks at the attribute out-of-band, guarded by hasattr only because the other estimators don't define it (grpo.py:3852-3856):
Nothing enforces the attribute or return shapes, so adding an estimator means matching undocumented conventions.
Describe the solution you'd like
A shared AdvantageEstimator base class / Protocol with an explicit metrics hook, e.g. get_metrics() -> dict[str, float] defaulting to {}. The call site becomes rollout_metrics.update(adv_estimator.get_metrics()).
A unified return type, e.g. an AdvantageResult(advantages, returns, metrics) dataclass (returns=None where unused), removing the bare-tensor-vs-tuple split.
Touches all estimators in advantage_estimator.py plus the compute_advantage call sites in grpo.py.
Opened #3512 with the proposed unified AdvantageResult and migrated the six estimators and their call sites. Metrics travel on the result instead of a separate hook; _compute_gae stays unchanged because it is private. @yfw, happy to adjust that shape during review.
Activity
tianyi-zhang-02 commentedon Aug 6, 2026
Opened #3512 with the proposed unified
AdvantageResultand migrated the six estimators and their call sites. Metrics travel on the result instead of a separate hook;_compute_gaestays unchanged because it is private. @yfw, happy to adjust that shape during review.refactor(algorithms): formalize the advantage-estimator contract
refactor(algorithms): formalize the advantage-estimator contract