Normalize rollout rewards independently within each prompt group. For rollout i in group g, define
Ai=σg+ϵri−μg.Here, ri is the reward, μg is its group's mean, σg is the population standard deviation, and ϵ is the supplied positive stabilizer. A group with identical rewards has zero advantages and is inactive; groups with nonzero standard deviation are active. Preserve rollout order, and order group-level results by group ID. Empty inputs produce empty tensors and an active count of zero.
Return a Python dictionary with advantages, a tensor matching the rewards' shape, dtype and device; active_group_mask, a Boolean tensor of shape (number of groups,) on that device; and active_group_count, a Python integer.
Input: rewards = [1,3], group_ids = [0,0], epsilon = 0.00000001
Output: {"advantages":[-1,1],"active_group_mask":[true],"active_group_count":1}
Explanation: The group has mean 2 and population standard deviation 1.
Input: rewards = [1,3,4,4], group_ids = [0,0,1,1], epsilon = 0.00000001
Output: {"advantages":[-1,1,0,0],"active_group_mask":[true,false],"active_group_count":1}
Input: rewards = [4,4], group_ids = [0,0], epsilon = 0.00000001
Output: {"advantages":[0,0],"active_group_mask":[false],"active_group_count":0}
Boolean indexing selects the rollouts belonging to one group.
torch.var supports population variance without a sample correction.
torch.all checks whether every selected reward equals the first.
Accepts: array
Accepts: array
Accepts: number
Normalize rollout rewards independently within each prompt group. For rollout i in group g, define
Ai=σg+ϵri−μg.Here, ri is the reward, μg is its group's mean, σg is the population standard deviation, and ϵ is the supplied positive stabilizer. A group with identical rewards has zero advantages and is inactive; groups with nonzero standard deviation are active. Preserve rollout order, and order group-level results by group ID. Empty inputs produce empty tensors and an active count of zero.
Return a Python dictionary with advantages, a tensor matching the rewards' shape, dtype and device; active_group_mask, a Boolean tensor of shape (number of groups,) on that device; and active_group_count, a Python integer.
Input: rewards = [1,3], group_ids = [0,0], epsilon = 0.00000001
Output: {"advantages":[-1,1],"active_group_mask":[true],"active_group_count":1}
Explanation: The group has mean 2 and population standard deviation 1.
Input: rewards = [1,3,4,4], group_ids = [0,0,1,1], epsilon = 0.00000001
Output: {"advantages":[-1,1,0,0],"active_group_mask":[true,false],"active_group_count":1}
Input: rewards = [4,4], group_ids = [0,0], epsilon = 0.00000001
Output: {"advantages":[0,0],"active_group_mask":[false],"active_group_count":0}
Boolean indexing selects the rollouts belonging to one group.
torch.var supports population variance without a sample correction.
torch.all checks whether every selected reward equals the first.
Accepts: array
Accepts: array
Accepts: number