deepspeedai / deepspeedai/DeepSpeedExamples

how to understand the code for calculating rewards

Open
#703 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
6.8k
Forks
1.1k
Avg merge
2d 16h
Merged PRs (30d)
1

Description

https://github.com/microsoft/DeepSpeedExamples/blob/master/applications/DeepSpeed-Chat/training/step3_rlhf_finetuning/ppo_trainer.py#L148

  def compute_rewards(self, prompts, log_probs, ref_log_probs, reward_score,
                      action_mask):
      kl_divergence_estimate = -self.kl_ctl * (log_probs - ref_log_probs)
      rewards = kl_divergence_estimate
      start = prompts.shape[1] - 1
      ends = start + action_mask[:, start:].sum(1) + 1
      reward_clip = torch.clamp(reward_score, -self.clip_reward_value,  self.clip_reward_value)
      batch_size = log_probs.shape[0]
      for j in range(batch_size):
          rewards[j, start:ends[j]][-1] += reward_clip[j]

      return rewards

why should we calculate rewards like this? is there a theory to back it up?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with applications/DeepSpeed-Chat/training/step3_rlhf_finetuning/ppo_trainer.py at compute_rewards and trace the inputs used in the cited calculation. Review the surrounding PPO/RLHF training flow and document why the KL term, clipped reward, and terminal reward placement are used; done means a clear explanation grounded in the code and relevant theory.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.