Conversation
Summary of ChangesHello @hjh0119, 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 overhauls the distributed RL training infrastructure by shifting from a tightly coupled 'hybrid mode' to a more flexible 'standalone mode'. This fundamental change enables greater scalability and resource utilization by allowing training and inference components to run independently. The core of this enhancement is a new Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a major and well-executed refactoring to support standalone reinforcement learning, where the training model and inference sampler are decoupled. The new CheckpointEngine module provides a robust mechanism for weight synchronization using NCCL/HCCL, which is a significant improvement for distributed training setups. The cookbooks for both TransformersModel and MegatronModel are clear and effectively demonstrate the new architecture.
I've identified two main issues:
- A critical bug in the
GRPOLossimplementation where the label shifting was removed, which will likely lead to incorrect loss calculation. - A high-severity memory regression in the refactored
IPCWeightLoaderfor hybrid mode, which could cause out-of-memory errors with large models.
Apart from these points, the code quality is high, with good documentation and clean APIs. The bug fix for FSDP in TransformersModel and the robust handling of packed sequences in GRPOLoss are particularly noteworthy improvements. Once the identified issues are addressed, this will be an excellent contribution.
| loss_mask = (labels != self.ignore_index).bool() | ||
| masked_labels = labels.clone() | ||
| masked_labels[~loss_mask] = 0 | ||
| logps = selective_log_softmax(logits, masked_labels) |
There was a problem hiding this comment.
The logic for calculating logps seems to have a bug. For autoregressive models, the logits at a given position t are used to predict the token at position t+1. Therefore, to calculate the log probability of the sequence, you need to align logits[:, t, :] with labels[:, t+1]. The previous implementation used torch.roll(labels, shifts=-1, dims=1) to achieve this, but it has been removed.
Without this shift, the loss is calculated using logits[:, t, :] and labels[:, t], which is incorrect and will likely lead to poor training performance. Please reintroduce the label shifting.
| loss_mask = (labels != self.ignore_index).bool() | |
| masked_labels = labels.clone() | |
| masked_labels[~loss_mask] = 0 | |
| logps = selective_log_softmax(logits, masked_labels) | |
| labels = torch.roll(labels, shifts=-1, dims=1) | |
| loss_mask = (labels != self.ignore_index).bool() | |
| masked_labels = labels.clone() | |
| masked_labels[~loss_mask] = 0 | |
| logps = selective_log_softmax(logits, masked_labels) |
| weights = {} | ||
| for name, tensor in self._get_weights_iterator(adapter_name): | ||
| tensor = Torch.to_local_tensor(tensor) | ||
| weights[name] = tensor.to(self.dtype, non_blocking=True) |
There was a problem hiding this comment.
This implementation collects all model weights into a new weights dictionary in memory before passing them to the sampler engine. This can lead to an out-of-memory error for large models, as it effectively doubles the memory required to hold the model weights.
The previous implementation of IPCWeightLoader streamed weights in buckets to avoid this issue. This change appears to be a regression in terms of memory efficiency. Please consider re-implementing a streaming mechanism to avoid materializing the entire state dictionary in memory.
No description provided.