Support Multi turn SFT with tools#245
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @pan-x-c, 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 significantly enhances the training capabilities for conversational AI models by introducing robust support for multi-turn Supervised Fine-Tuning (SFT) that can also incorporate tool usage. The changes allow for more accurate and efficient training on complex dialogue flows, including those where the model interacts with external tools. This improvement is crucial for developing more sophisticated and context-aware conversational agents.
Highlights
- Multi-turn SFT Support: Introduced support for concatenated multi-turn Supervised Fine-Tuning (SFT), allowing models to be trained on longer, more complex conversational sequences.
- Tool Integration: Enabled the use of tools within the concatenated multi-turn SFT process, enhancing the model's ability to handle function calling and tool-augmented conversations during training.
- Flexible Chat Template Configuration: Added new configuration options to specify whether multi-turn SFT is enabled and to provide a custom chat template, offering greater control over how messages are formatted for training.
- Improved Token Masking Logic: Refactored the token masking mechanism to dynamically select the appropriate method (Hugging Face's
return_assistant_tokens_maskor a default implementation) based on the chat template, ensuring correct action mask generation for various conversational formats, including those with tool calls. - Enhanced Testing: Expanded test coverage for the SFT formatter and action mask generation to validate the new multi-turn and tool integration functionalities.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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
-
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. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces support for multi-turn Supervised Fine-Tuning (SFT) with tools. The changes primarily involve correctly handling action_mask for multi-turn conversations and ensuring that tools and chat_template configurations are propagated and used consistently throughout the data formatting and model interaction logic. The implementation looks solid, with new utility functions to determine the correct masking method and refactoring to centralize this logic. I've identified one potential bug regarding inconsistent chat_template usage and a suggestion to refactor duplicated test code for better maintainability.
|
/unittest-all |
Summary
Tests
Github Test Reporter by CTRF 💚 |
|
/unittest-module-trainer |
There was a problem hiding this comment.
Pull Request Overview
This PR implements support for multi-turn supervised fine-tuning (SFT) with tools functionality. The main purpose is to enhance the system's ability to handle concatenated multi-turn conversations that include tool usage.
- Added concatenated multi-turn SFT support through new configuration options and processing logic
- Integrated tools support across the tokenization and formatting pipeline
- Refactored action mask method selection into a centralized utility function
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| trinity/common/models/vllm_model.py | Updated to use centralized action mask method and added tools parameter support |
| trinity/common/models/utils.py | Added tools parameter to tokenization functions and created get_action_mask_method utility |
| trinity/common/config.py | Added multi-turn and chat template configuration options to FormatConfig |
| trinity/buffer/schema/formatter.py | Enhanced SFT formatter with multi-turn support and tools integration |
| trinity/buffer/reader/file_reader.py | Removed unused RawDataReader class |
| tests/tools.py | Updated test configuration to enable concatenated multi-turn |
| tests/common/vllm_test.py | Added comprehensive tests for action masking with tools and updated chat template |
| tests/buffer/formatter_test.py | Enhanced formatter tests to cover multi-turn scenarios |
| docs/sphinx_doc/source/tutorial/trinity_configs.md | Updated documentation with new configuration options |
| docs/sphinx_doc/source/tutorial/example_dpo.md | Enhanced DPO tutorial with clearer examples and configuration explanations |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
/unittest-module-trainer |
Summary
Tests
Github Test Reporter by CTRF 💚 |
|
/unittest-module-common |
Summary
Tests
Github Test Reporter by CTRF 💚 |
Description
Checklist
Please check the following items before code is ready to be reviewed.