Skip to content

Formalize the advantage-estimator interface (shared Protocol + explicit metrics, unified return type) #2909

Open

Description

@yfw

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:

  1. 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.
  2. 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):
    if hasattr(adv_estimator, "last_metrics") and adv_estimator.last_metrics:
        rollout_metrics.update(adv_estimator.last_metrics)

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.

Additional context

Follow-up from the MOPD PR #2780 review.

Activity

  1. added
    enhancement
    on Jun 24, 2026
  2. tianyi-zhang-02 commented on Aug 6, 2026

    @tianyi-zhang-02
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Featureenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions