Skip to content

Conversation

@study8677
Copy link

Description

Fixed two issues in compute_grpo_outcome_advantage within ae_ray_trainer.py:

  1. Tensor Device Mismatch: Explicitly specified device=scores.device when creating new tensors (id2mean, id2std) to ensure compatibility with the input scores tensor (e.g., when running on GPU).
  2. Incorrect Std Calculation: Removed extra brackets [] in torch.std(torch.tensor(...)) which previously caused incorrect tensor dimensions during standard deviation calculation.

Checklist

Please check the following items before code is ready to be reviewed.

  • All tests are passing
  • [N/A] Docstrings are in Google style
  • [N/A] Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@gemini-code-assist
Copy link

Summary of Changes

Hello @study8677, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses two critical issues within the compute_grpo_outcome_advantage function in ae_ray_trainer.py. The changes ensure that tensor operations maintain device consistency, which is crucial for correct execution on accelerators like GPUs, and rectify an error in the standard deviation calculation that previously led to incorrect tensor dimensions. These fixes improve the robustness and accuracy of the tensor computations within the module.

Highlights

  • Tensor Device Consistency: Explicitly specified device=scores.device when creating new tensors (id2mean, id2std) to ensure they are allocated on the same device as the input scores tensor, preventing potential device mismatches, especially when running on GPUs.
  • Standard Deviation Calculation Fix: Corrected the torch.std calculation by removing an extraneous set of brackets [] from torch.tensor([id2score[idx]]). This resolves an issue where the tensor's dimensions were incorrectly interpreted, leading to an inaccurate standard deviation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request correctly addresses two important issues: ensuring tensor device consistency and fixing an incorrect standard deviation calculation due to extra brackets. The changes are clear and directly solve the described problems. I've added two suggestions. The first one addresses a potential logic bug in the advantage calculation for single-item groups, which I believe is a high-severity issue. The second suggestion is a minor refactoring to improve code clarity and efficiency when calculating group statistics. Overall, good fixes. Please consider the suggested improvements.

@study8677
Copy link
Author

@reviewers regarding the suggestion above to use torch.stack() for better efficiency: Should I adopt this refactoring?
If you agree, I am happy to apply this change to the current PR.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant