-
Notifications
You must be signed in to change notification settings - Fork 1k
[train] support embeding/reranker packing & support reranker/embedding cache_dataset #6987
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
base: main
Are you sure you want to change the base?
[train] support embeding/reranker packing & support reranker/embedding cache_dataset #6987
Conversation
Summary of ChangesHello @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 enhances the data packing mechanism within the training pipeline, specifically targeting improved support for embedding and reranker models. The changes introduce more flexible handling of sequence lengths, allowing for both single and list-based length representations to be correctly processed and aggregated during data packing. This ensures that complex multi-sequence inputs are properly prepared for model training, while also updating the template version to maintain compatibility. Highlights
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.
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 support for packing in embedding and reranker tasks. The changes are well-implemented and consistent. The core idea is to allow the length of a sample to be a list of integers, which is handled correctly during data processing and packing. I have one suggestion to improve the robustness of data validation by replacing an assert statement with a ValueError. Also, there is a small typo in the pull request title ('embeding' should be 'embedding').
swift/llm/template/base.py
Outdated
| encoded['length'] = lengths | ||
| else: | ||
| encoded['length'] = sum(lengths) | ||
| assert len(lengths) != 0, f'batched: {batched}' |
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.
Using assert for data validation is not recommended, as assertions can be disabled with the -O (optimize) flag in Python, which might lead to unexpected behavior in production. It's better to use an explicit if check and raise a ValueError for robustness.
| assert len(lengths) != 0, f'batched: {batched}' | |
| if not lengths: | |
| raise ValueError(f'lengths should not be empty. batched: {batched}') |
|
/gemini review |
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.
Code Review
This pull request adds support for packing and cached datasets for embedding, reranker, and sequence classification tasks. The changes include updates to documentation, new example scripts, and modifications to data processing logic to handle list-based lengths for samples, which is necessary for tasks like reranking. The code has also been refactored to move padding_side and padding_free arguments to a more appropriate location. Overall, the changes are well-implemented and improve the framework's capabilities.
swift/llm/template/base.py
Outdated
| if len(anchor.messages) == 1: | ||
| # Ensure that load_data_args true runs through inference successfully | ||
| assistant_messages = (inputs.positive + inputs.negative)[0].messages | ||
| assert anchor.messages[0]['role'] == 'user' and assistant_messages[0]['role'] == 'assistant' | ||
| anchor.messages = anchor.messages + assistant_messages |
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.
The code assumes that inputs.positive or inputs.negative will contain at least one document, and accesses (inputs.positive + inputs.negative)[0] without checking if the list is empty. This could lead to an IndexError if a reranker inference is attempted with a query but no documents. It would be more robust to add a check to ensure the list of documents is not empty before accessing its first element.
| if len(anchor.messages) == 1: | |
| # Ensure that load_data_args true runs through inference successfully | |
| assistant_messages = (inputs.positive + inputs.negative)[0].messages | |
| assert anchor.messages[0]['role'] == 'user' and assistant_messages[0]['role'] == 'assistant' | |
| anchor.messages = anchor.messages + assistant_messages | |
| if len(anchor.messages) == 1: | |
| # Ensure that load_data_args true runs through inference successfully | |
| docs = inputs.positive + inputs.negative | |
| if docs: | |
| assistant_messages = docs[0].messages | |
| assert anchor.messages[0]['role'] == 'user' and assistant_messages[0]['role'] == 'assistant' | |
| anchor.messages = anchor.messages + assistant_messages |
No description provided.