-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Inference] Update DygraphInferencePredictor #9491
Merged
ZHUI
merged 9 commits into
PaddlePaddle:develop
from
DrownFish19:dev_20241124_update_generator
Dec 2, 2024
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1c7502b
update DygraphInferencePredictor
DrownFish19 31d3d62
update batch_size
DrownFish19 aea6854
Merge branch 'PaddlePaddle:develop' into dev_20241124_update_generator
DrownFish19 33da8dd
fix int8 setup
DrownFish19 7b83fb1
revert fix by padding input_text
DrownFish19 5ee2e80
Merge branch 'PaddlePaddle:develop' into dev_20241124_update_generator
DrownFish19 bd90712
Merge branch 'PaddlePaddle:develop' into dev_20241124_update_generator
DrownFish19 ebe00c1
fix
DrownFish19 f4f26a2
Merge branch 'dev_20241124_update_generator' of github.com:DrownFish1…
DrownFish19 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 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 |
---|---|---|
|
@@ -719,10 +719,9 @@ def _infer(self, inputs: dict[str, paddle.Tensor]): | |
inputs[key] = paddle.to_tensor(inputs[key]) | ||
|
||
inputs["cache_kvs"] = self.cache_kvs | ||
self.model.generate( | ||
return self.model.generate( | ||
**inputs, | ||
) | ||
return None | ||
|
||
|
||
class BlockInferencePredictorMixin(BasePredictor): | ||
|
@@ -904,6 +903,8 @@ def _preprocess(self, input_text: list[str]): | |
input_text = [input_text] if isinstance(input_text, str) else input_text | ||
input_text = [self.tokenizer.apply_chat_template(sentence, tokenize=False) for sentence in input_text] | ||
|
||
input_text_batch_size = len(input_text) | ||
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. 修复输入数据不是完整batch_size的问题 |
||
|
||
input_ids = [] | ||
for text in input_text: | ||
tokens = self.tokenizer( | ||
|
@@ -923,28 +924,24 @@ def _preprocess(self, input_text: list[str]): | |
|
||
self.model_inputs["block_tables"][:][:] = -1 | ||
free_list = list(range(self.max_block_nums)) | ||
for i in range(self.config.batch_size): | ||
for i in range(input_text_batch_size): | ||
for j in range( | ||
(seq_lens[i] + self.config.max_length + self.config.block_size - 1) // self.config.block_size | ||
): | ||
used_block_id = free_list.pop() | ||
self.model_inputs["block_tables"][i, j] = used_block_id | ||
|
||
# fmt:off | ||
self.model_inputs["seq_lens_this_time"] = paddle.to_tensor(np.array(seq_lens).astype("int32").reshape(-1, 1)) | ||
self.model_inputs["seq_lens_encoder"] = paddle.to_tensor(np.array(seq_lens).astype("int32").reshape(-1, 1)) | ||
self.model_inputs["seq_lens_decoder"] = paddle.full( | ||
shape=[self.config.batch_size, 1], fill_value=0, dtype="int32" | ||
) | ||
self.model_inputs["step_idx"] = paddle.full(shape=[self.config.batch_size, 1], fill_value=0, dtype="int64") | ||
self.model_inputs["seq_lens_decoder"] = paddle.full(shape=[input_text_batch_size, 1], fill_value=0, dtype="int32") | ||
self.model_inputs["step_idx"] = paddle.full(shape=[input_text_batch_size, 1], fill_value=0, dtype="int64") | ||
self.model_inputs["not_need_stop"] = paddle.full(shape=[1], fill_value=True, dtype="bool") | ||
self.model_inputs["stop_flags"] = paddle.full( | ||
shape=[self.config.batch_size, 1], fill_value=False, dtype="bool" | ||
) | ||
self.model_inputs["stop_nums"] = paddle.full(shape=[1], fill_value=self.config.batch_size, dtype="int64") | ||
self.model_inputs["pre_ids"] = paddle.full( | ||
shape=[self.config.batch_size, self.config.max_length], fill_value=-1, dtype="int64" | ||
) | ||
self.model_inputs["next_tokens"] = paddle.full(shape=[self.config.batch_size, 1], fill_value=-1, dtype="int64") | ||
self.model_inputs["stop_flags"] = paddle.full(shape=[input_text_batch_size, 1], fill_value=False, dtype="bool") | ||
self.model_inputs["stop_nums"] = paddle.full(shape=[1], fill_value=input_text_batch_size, dtype="int64") | ||
self.model_inputs["pre_ids"] = paddle.full(shape=[input_text_batch_size, self.config.max_length], fill_value=-1, dtype="int64") | ||
self.model_inputs["next_tokens"] = paddle.full(shape=[input_text_batch_size, 1], fill_value=-1, dtype="int64") | ||
# fmt:on | ||
|
||
if self.config.mode == "static": | ||
for k, v in self.model_inputs.items(): | ||
|
@@ -1008,8 +1005,8 @@ def predict(self, input_texts: list[str], return_tokens=False): | |
if self.tensor_parallel_rank == 0: | ||
outputs = [] | ||
output_tokens = [] | ||
while len(outputs) < self.batch_size: | ||
result = result_queue.get(timeout=1) | ||
while len(outputs) < len(input_texts): | ||
result = result_queue.get(timeout=10) | ||
outputs.append(result[-1]) | ||
output_tokens.append(result[-2]) | ||
|
||
|
Oops, something went wrong.
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.
修复返回None的问题