Skip to content

[BUG] MCAdvantage changes when adding a common offset to nearby float32 rewards #4807

Todo

Description

@wufei-png

Reproduction

MCAdvantage changes the advantages of two one-step trajectories when the same constant is added to both rewards. The two float32 rewards are exactly representable in either case. This affects per-step rewards and trajectory_return="sum" on main at 6ffc7a21.

import torch
from tensordict import TensorDict
from torchrl.objectives.llm.grpo import MCAdvantage

def advantages(offset, trajectory_return):
    transform = MCAdvantage(grpo_size=2, prompt_key="group_id", trajectory_return=trajectory_return)
    for value in (offset, offset + 2**-18):
        result = transform.inv(TensorDict({
            "group_id": torch.tensor([0]),
            ("next", "reward"): torch.tensor([[value]], dtype=torch.float32),
            ("next", "done"): torch.tensor([[True]]),
        }, batch_size=[1]))
    return result["advantage"].flatten().tolist()

for mode in (None, "sum"):
    print(mode, advantages(0.0, mode), advantages(32.0, mode))

Expected and observed

Both reward groups have a sample standard deviation above the clamp. At either origin, the expected advantages are approximately [-0.707107, +0.707107]. At offset 32 the lower-reward rollout receives 0.0 and the higher receives approximately 1.414214.

The shifted reduction introduced in #4610 handles uniform fractional rewards. For adjacent rewards, adding the origin back to the mean rounds the midpoint to an endpoint before the subtraction. Centering the shifted rewards first preserves the signal. A CPU regression reproduces this with PyTorch 2.15.0 and TensorDict 0.15.6.

Activity

  1. wufei-png commented on Dec 2, 2026

    @wufei-png
    Author

    /assign

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions