Skip to content
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

[Feature] *_batch_generate* function, add the MultiTokenEOSCriteria #772

Merged
merged 3 commits into from
Jan 8, 2024

Conversation

jiangjin1999
Copy link
Contributor

@jiangjin1999 jiangjin1999 commented Jan 5, 2024

jiangjin1999: In _batch_generate function, add the MultiTokenEOSCriteria feature to speed up inference.

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

During the model generation phase, we sometimes need to set certain stop words to prompt the model to cease generation. The conventional Huggingface code supports token-based termination only, whereas OpenCompass has introduced support for multi-token termination through the MultiTokenEOSCriteria class. Notably, OpenCompass previously only permitted the use of MultiTokenEOSCriteria within the _single_generate context (with no-batch-padding implying _single_generate).

Modification

  • Modification 1: Our enhancements have enabled the use of MultiTokenEOSCriteria within the _batch_generate function.
  • Modification 2: Some open-source models, such as "qwen," have unique end-of-sequence (EOS) tokens. We have also implemented a simple filtering mechanism for these models.

Advantages:

  • Our modifications facilitate the use of multi-token termination during batch inference, which significantly boosts inference efficiency.
  • The continuation of text from the base model incurs additional resource consumption, and our changes have addressed this issue to a certain extent.
  • Comparison of Inference Efficiency: We conduct experiments to validate. Experimental setup: for llama2-13b-base & 2-shots. In the past: the DROP dataset took 1:33:01 to process; Currently: the DROP dataset takes 35:35 to process. And there is no difference between the evaluation results of the two.

Limitations:

  • The application of MultiTokenEOSCriteria during batch inference will halt generation based on the longest case within the current batch. This approach does not entirely eliminate the extra resource consumption caused by text continuation.

BC-breaking (Optional)

No

Use cases (Optional)

Previously, if stopping criteria were set in the config, it was necessary to append the --no-batch-padding flag when running the run.py script. Now, this step is no longer required, and you can execute the script directly without adding that flag.

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects.
  • CLA has been signed and all committers have signed the CLA in this PR.

@jiangjin1999 jiangjin1999 changed the title jiangjin1999: *_batch_generate* function, add the MultiTokenEOSCriteria *_batch_generate* function, add the MultiTokenEOSCriteria Jan 5, 2024
@jiangjin1999 jiangjin1999 changed the title *_batch_generate* function, add the MultiTokenEOSCriteria [Feature] *_batch_generate* function, add the MultiTokenEOSCriteria Jan 5, 2024
@jiangjin1999 jiangjin1999 reopened this Jan 5, 2024
Copy link
Collaborator

@Leymore Leymore left a comment

Choose a reason for hiding this comment

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

LGTM

@Leymore Leymore merged commit 8194199 into open-compass:main Jan 8, 2024
6 of 7 checks passed
Leymore pushed a commit that referenced this pull request Apr 23, 2024
* jiangjin1999: in the _batch_generate function, add the MultiTokenEOSCriteria feature to speed up inference.

* jiangjin1999: in the _batch_generate function, add the MultiTokenEOSCriteria feature to speed up inference.

---------

Co-authored-by: jiangjin08 <jiangjin08@MBP-2F32S5MD6P-0029.local>
Co-authored-by: jiangjin08 <jiangjin08@a.sh.vip.dianping.com>
liuyaox pushed a commit to liuyaox/opencompass that referenced this pull request Jun 26, 2024
…pen-compass#772)

* jiangjin1999: in the _batch_generate function, add the MultiTokenEOSCriteria feature to speed up inference.

* jiangjin1999: in the _batch_generate function, add the MultiTokenEOSCriteria feature to speed up inference.

---------

Co-authored-by: jiangjin08 <jiangjin08@MBP-2F32S5MD6P-0029.local>
Co-authored-by: jiangjin08 <jiangjin08@a.sh.vip.dianping.com>
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.

3 participants