-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Integrate FT into generation api #1154
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b449736
Add the first draft for integrating FT into generation api.
guoshengCS 8947ddc
Add try-catch in FT using of generation api.
guoshengCS 5b08d9f
Refine FasterTransformer integration into generation api.
guoshengCS 7ee7481
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleNLP i…
guoshengCS b5adde3
Update some checks in FT integration.
guoshengCS 0962713
Merge branch 'develop' into add-gen-ft
smallv0221 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -759,6 +759,34 @@ def get_encoder(self): | |
| def get_decoder(self): | ||
| return self.bart.get_decoder() | ||
|
|
||
| def prepare_faster_entry(self, kwargs): | ||
| from paddlenlp.ops import FasterBART | ||
| decoding_strategy = kwargs.get('decode_strategy') | ||
| model_kwargs = kwargs['model_kwargs'] | ||
| use_fp16_decoding = model_kwargs.get('use_fp16_decoding', False) | ||
| # TODO(guosheng): Currently, beam_search_v2 in FasterTransformer uses | ||
| # t2t beam search which has some difference with beam search in generation | ||
| # api on finish queue addition and early-stop criterion, and it seems | ||
| # lead to poor performance on bart cnn-sum model, thus we disable it temporarily. | ||
| if decoding_strategy == 'beam_search': | ||
| return False | ||
| # Some checks on kwargs. For example, FasterBART needs `mem_seq_lens` as | ||
| # one input while BART not, thus check whether `mem_seq_lens` in kwargs. | ||
| if model_kwargs.get('mem_seq_lens', None) is None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mem_seq_lens的获取可以移到FasterBart中,保证generate接受的参数统一 |
||
| return False | ||
| # Assume no args change among multi-turns run to convert parameters only | ||
| # once. Additionaly, use some converted args as default values instead of | ||
| # converting args to allow overriding. | ||
| # TODO(guosheng): maybe use weakref for the model in faster model | ||
| self._faster_entry = partial( | ||
| FasterBART( | ||
| self, | ||
| decoding_strategy=decoding_strategy, | ||
| use_fp16_decoding=use_fp16_decoding).generate, | ||
| alpha=kwargs.get('length_penalty'), | ||
| rel_len=False) | ||
| return self._faster_entry | ||
|
|
||
| def forward(self, | ||
| input_ids, | ||
| attention_mask=None, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
不是之后会把加速版的的beam_search改成hf的么,应该不用禁掉beam_search吧