Skip to content

Conversation

@Jintao-Huang
Copy link
Collaborator

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Jintao-Huang, 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 introduces foundational test cases to validate the integration and functionality of embedding and reranker models within the Megatron framework. It provides concrete examples of how to configure and execute fine-tuning tasks for these specialized models, ensuring their proper operation and demonstrating the necessary arguments for megatron_sft_main.

Highlights

  • New Test File Added: A new test file, test_embedding.py, has been introduced under the tests/megatron/ directory. This file is dedicated to testing Megatron's capabilities for embedding and reranker models.
  • Embedding Model Testing: The test_embedding function demonstrates how to configure and run an embedding task using megatron_sft_main. It utilizes the Qwen/Qwen3-Embedding-0.6B model, infonce loss, and LoRA for fine-tuning on a sentence-transformers/stsb:positive dataset.
  • Reranker Model Testing: The test_reranker function showcases the setup for a generative reranker task. It uses the Qwen/Qwen3-Reranker-4B model with pointwise_reranker loss and LoRA, fine-tuning on the MTEB/scidocs-reranking#10000 dataset.
  • Megatron Configuration: Both test cases configure Megatron with tensor_model_parallel_size=2, recompute_granularity='full', sequence_parallel=True, and finetune=True, providing examples of common distributed training settings.

🧠 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.

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
Contributor

@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

This pull request introduces tests for Megatron-based embedding and reranker models. The tests are a good starting point for verifying the new functionalities. However, there are a few issues in the test file that need to be addressed:

  1. A critical configuration mismatch between CUDA_VISIBLE_DEVICES and tensor_model_parallel_size will cause the tests to fail.
  2. The test_reranker function is not executed when the script is run directly.
  3. There's a minor code duplication with imports that can be cleaned up.

Additionally, based on the provided code context, the implementation for handling embedding and generative_reranker task types in MegatronTrainer seems to be missing. This makes it difficult to fully assess the correctness of the tests and the feature itself. Please ensure the full implementation is included in the pull request for a complete review.

@@ -0,0 +1,54 @@
import os

os.environ['CUDA_VISIBLE_DEVICES'] = '0'
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The CUDA_VISIBLE_DEVICES is set to '0', which makes only one GPU visible to the test. However, both test_embedding and test_reranker are configured with tensor_model_parallel_size=2, which requires at least two GPUs. This configuration mismatch will cause the test to fail. To fix this, you should make at least two GPUs visible.

Suggested change
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ['CUDA_VISIBLE_DEVICES'] = '0,1'



def test_embedding():
from swift.megatron import megatron_sft_main, MegatronSftArguments
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The import statement from swift.megatron import megatron_sft_main, MegatronSftArguments is repeated in both test_embedding (line 7) and test_reranker (line 31). To follow the DRY (Don't Repeat Yourself) principle and improve code clarity, it's recommended to move this import to the top of the file, outside of the test functions.

Comment on lines +53 to +54
if __name__ == '__main__':
test_embedding()
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The test_reranker function is defined but not called when the script is executed directly. To ensure both tests are run, you should add a call to test_reranker().

Suggested change
if __name__ == '__main__':
test_embedding()
if __name__ == '__main__':
test_embedding()
test_reranker()

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