-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Fix] ppo rollout engins for distribute #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2a70a47
[fix] fix ppo value_loss problem and add kl_coef to reward
lilei199908 e63c00b
[fix] fix ppo value_loss problem and add kl_coef to reward
lilei199908 0e9c14c
[fix] ppo update_weights form distribute
lilei199908 48d3292
[fix] ppo cp bugs
lilei199908 f1dc47c
[Fix] ppo pp bugs
lilei199908 5210d99
[Fix] ppo pp bugs
lilei199908 d4ad1e7
[Fix] ppo pp bugs
lilei199908 5ea89e9
[Fix] ppo pp bugs
lilei199908 0586d65
[Fix] ppo pp bugs
lilei199908 06f8a21
[Fix] ppo cp pp bugs
lilei199908 d54b1dc
[Fix] ppo update_from_distribute
lilei199908 52d6c86
[Fix] ppo update_from_distribute
lilei199908 b946ef7
[Fix] ppo update_from_distribute
lilei199908 ce6b693
[Fix] ppo update_from_distribute
lilei199908 10fd812
[Fix] ppo update_from_distribute
lilei199908 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,7 +137,7 @@ def compute_advantages_and_returns(args, rollout_data): | |
| if log_probs is None and values is None: | ||
| return | ||
|
|
||
| if args.kl_coef == 0: | ||
| if args.kl_coef == 0 or not log_probs: | ||
| # when kl_coef is 0, we won't compute ref_log_prob | ||
| xs = log_probs if log_probs is not None else values | ||
| kl = [torch.zeros_like(x, dtype=torch.float32, device=x.device) for x in xs] | ||
|
|
@@ -163,13 +163,17 @@ def compute_advantages_and_returns(args, rollout_data): | |
| rewards = [] | ||
| for reward, k in zip(old_rewards, kl): | ||
| k *= -args.kl_coef | ||
| k[-1] += reward | ||
| cp_rank = mpu.get_context_parallel_rank() | ||
| if cp_rank == 0: | ||
| k[-1] += reward | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when enabling cp, we need to add the reward only to the last position |
||
| rewards.append(k) | ||
| advantages, returns = list( | ||
| zip( | ||
| *[ | ||
| get_advantages_and_returns(value, reward, args.gamma, args.lambd) | ||
| for value, reward in zip(values, rewards) | ||
| get_advantages_and_returns(total_length, response_length, value, reward, args.gamma, args.lambd) | ||
| for total_length, response_length, value, reward in zip( | ||
| total_lengths, response_lengths, values, rewards | ||
| ) | ||
| ] | ||
| ) | ||
| ) | ||
|
|
@@ -363,7 +367,7 @@ def value_loss_function(args, batch, logits, sum_of_sample_mean): | |
| total_lengths=batch["total_lengths"], | ||
| response_lengths=batch["response_lengths"], | ||
| ) | ||
| values = torch.cat([value.squeeze(-1) for value in values["values"]], dim=0) | ||
| values = torch.cat([value.flatten() for value in values["values"]], dim=0) | ||
|
|
||
| returns = torch.cat(batch["returns"], dim=0) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can pass only one argument and use for example
if "values" in rollout_datato check whether this is critic or actor