-
Notifications
You must be signed in to change notification settings - Fork 69
[logging] clean up 1/n #606
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
Open
felipemello1
wants to merge
4
commits into
meta-pytorch:main
Choose a base branch
from
felipemello1:metric_cleanup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+44
−99
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,14 +179,19 @@ def simple_grpo_loss( | |
| loss = -(mean_policy_loss - beta * mean_kl) | ||
|
|
||
| # Log metrics | ||
| # TODO: Better design - have loss function return all metrics as a dict, | ||
| # then record them in rl_trainer so all training metrics are in one namespace | ||
| # and we avoid doing .item here, which is not compile friendly | ||
| record_metric("grpo_loss/kl_divergence_mean", mean_kl.item(), Reduce.MEAN) | ||
| record_metric( | ||
| "grpo_loss/kl_divergence_max", (kl * padding_mask).max().item(), Reduce.MAX | ||
| ) | ||
| record_metric("grpo_loss/policy_loss", mean_policy_loss.item(), Reduce.MEAN) | ||
| record_metric( | ||
| "grpo_loss/policy_gradient_loss", mean_policy_loss.item(), Reduce.MEAN | ||
| ) | ||
| record_metric("grpo_loss/total_loss", loss.item(), Reduce.MEAN) | ||
| record_metric("grpo_loss/advantage_mean", advantages.mean().item(), Reduce.MEAN) | ||
| record_metric("grpo_loss/advantage_std", advantages.std().item(), Reduce.MEAN) | ||
|
|
||
| return loss | ||
|
|
||
|
|
||
|
|
@@ -210,11 +215,6 @@ async def evaluate_response( | |
| ) | ||
| reward_breakdown[reward_fn_name] = reward | ||
| # per function reward | ||
| record_metric( | ||
| f"reward/evaluate_response/sum_{reward_fn_name}_reward", | ||
| reward, | ||
| Reduce.SUM, | ||
| ) | ||
| record_metric( | ||
| f"reward/evaluate_response/avg_{reward_fn_name}_reward", | ||
| reward, | ||
|
|
@@ -226,18 +226,13 @@ async def evaluate_response( | |
| Reduce.STD, | ||
| ) | ||
|
|
||
| # avg total reward | ||
|
Member
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. Remove. It's already called avg_total_reward |
||
| record_metric( | ||
| "reward/evaluate_response/avg_total_reward", | ||
| reward, | ||
| Reduce.MEAN, | ||
| ) | ||
|
|
||
| record_metric( | ||
| f"reward/evaluate_response/count_{reward_fn_name}_calls", | ||
| 1, | ||
| Reduce.SUM, | ||
| ) | ||
|
|
||
| avg_reward: float = total_rewards / len(self.reward_functions) | ||
| return reward_breakdown, avg_reward | ||
|
|
||
|
|
@@ -305,17 +300,6 @@ async def sample(self) -> dict[str, str] | None: | |
| try: | ||
| sample = next(self._iterator) | ||
|
|
||
| record_metric("dataset/sample/count_samples_generated", 1, Reduce.SUM) | ||
| record_metric( | ||
| "dataset/sample/avg_sample_len", | ||
| len(sample["request"]), | ||
| Reduce.MEAN, | ||
| ) | ||
| record_metric( | ||
| "dataset/sample/max_sample_len", | ||
| len(sample["request"]), | ||
| Reduce.MAX, | ||
| ) | ||
| record_metric("dataset/sample/current_epoch", self._epoch, Reduce.MAX) | ||
|
|
||
| return sample | ||
|
|
@@ -442,8 +426,6 @@ async def continuous_rollouts(): | |
| print("Dataloader is empty, exiting continuous rollout") | ||
| return | ||
|
|
||
| t.step("data_loading") | ||
|
|
||
| prompt, target = sample["request"], sample["target"] | ||
| responses: list[Completion] = await policy.generate.route(prompt) | ||
| t.step("policy_generation") | ||
|
|
@@ -477,6 +459,23 @@ async def continuous_rollouts(): | |
| input_ids[i, :max_req_tokens] = episode.request_tensor | ||
| input_ids[i, max_req_tokens:] = episode.response_tensor | ||
|
|
||
| # Track token-based metrics | ||
| prompt_tokens = episode.completion.prompt_ids.shape[0] | ||
| response_tokens = episode.completion.token_ids.shape[0] | ||
|
|
||
| record_metric("episode/avg_prompt_tokens", prompt_tokens, Reduce.MEAN) | ||
| record_metric("episode/max_prompt_tokens", prompt_tokens, Reduce.MAX) | ||
| record_metric("episode/min_prompt_tokens", prompt_tokens, Reduce.MIN) | ||
| record_metric( | ||
| "episode/avg_response_tokens", response_tokens, Reduce.MEAN | ||
| ) | ||
| record_metric( | ||
| "episode/max_response_tokens", response_tokens, Reduce.MAX | ||
| ) | ||
| record_metric( | ||
| "episode/min_response_tokens", response_tokens, Reduce.MIN | ||
| ) | ||
|
|
||
| # drop episodes if | ||
| # 1> reward std-dev is very small (including all 0s and all 1s) | ||
| # 2> response is potentially truncated (response_len >= max_res_tokens) | ||
|
|
@@ -485,7 +484,7 @@ async def continuous_rollouts(): | |
| max_response_len = max(e.completion.token_ids.shape[0] for e in episodes) | ||
| drop = rewards_std < 1e-3 or max_response_len >= max_res_tokens | ||
| record_metric( | ||
| "main/continuous_rollouts/dropped_episodes", | ||
| "main/continuous_rollouts/unfit_for_training_dropped_episodes", | ||
|
Member
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. This naming is a little confusing. Can you explain? |
||
| 1 if drop else 0, | ||
| Reduce.SUM, | ||
| ) | ||
|
|
||
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
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.
I want to get away from TODOs in code as a marker. Can you turn this into a small GI?