Skip to content

Conversation

@Jintao-Huang
Copy link
Collaborator

@Jintao-Huang Jintao-Huang commented Nov 16, 2025

FIX: 避免 grpo训练,被截断的数据包含eos_token

@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 enhances the template encoding mechanism by providing a new configuration option to explicitly manage the addition of end-of-sequence (EOS) tokens. This change allows users to precisely control when EOS tokens are appended, offering greater flexibility in various generation scenarios, such as fine-tuning or specific inference tasks where default EOS behavior might need to be overridden.

Highlights

  • Explicit EOS Control: Introduced an add_eos parameter within inputs.extra_kwargs to explicitly control whether an end-of-sequence (EOS) token should be added during template encoding.
  • Template Encoding Logic Update: Modified the _swift_encode method in base.py to respect the new add_eos parameter, allowing it to override the default conditional logic for appending EOS tokens.
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 support for an add_eos flag in extra_kwargs to control the addition of the end-of-sequence token. The implementation is functionally correct, but I've suggested a small refactoring to improve code clarity by limiting the scope of the new variable. This will make the code more maintainable.

Comment on lines +1143 to 1148
if add_eos is None:
add_eos = (self.is_training
or self.task_type != 'causal_lm') and not sep_token and not endswith_stop_words
if add_eos:
extra_context_list = template_meta.suffix
extra_context_type = ContextType.SUFFIX
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve readability and limit variable scope, it's better to declare and use the add_eos logic entirely within this block, as it's the only place it's used. Using a local variable like add_eos_flag makes it clear that its scope is confined here.

With this change, you can remove the declaration add_eos = inputs.extra_kwargs.get('add_eos') from line 1102.

Suggested change
if add_eos is None:
add_eos = (self.is_training
or self.task_type != 'causal_lm') and not sep_token and not endswith_stop_words
if add_eos:
extra_context_list = template_meta.suffix
extra_context_type = ContextType.SUFFIX
add_eos_flag = inputs.extra_kwargs.get('add_eos')
if add_eos_flag is None:
add_eos_flag = (self.is_training
or self.task_type != 'causal_lm') and not sep_token and not endswith_stop_words
if add_eos_flag:
extra_context_list = template_meta.suffix
extra_context_type = ContextType.SUFFIX

@Jintao-Huang Jintao-Huang merged commit d370250 into modelscope:main Nov 16, 2025
1 of 2 checks passed
vx120 pushed a commit to vx120/ms-swift that referenced this pull request Nov 19, 2025
Jintao-Huang added a commit that referenced this pull request Nov 20, 2025
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.

2 participants