This repository was archived by the owner on Jun 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 192
[Pipeline Refactor] Split/Join Functionality for multiple prompts #1384
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from typing import List | ||
|
|
||
| import numpy | ||
|
|
||
| from deepsparse.transformers.utils.helpers import pad_to_fixed_length | ||
| from deepsparse.v2.operators import Operator | ||
| from deepsparse.v2.text_generation.compile_generations import CompileGenerationsOutput | ||
|
|
||
|
|
||
| __all__ = ["JoinOutput"] | ||
|
|
||
|
|
||
| class JoinOutput(Operator): | ||
| """ | ||
| Run this operator to combine the results from multiple prompts. | ||
| """ | ||
|
|
||
| def __init__(self, tokenizer): | ||
| self.tokenizer = tokenizer | ||
|
|
||
| def run(self, inp: List[CompileGenerationsOutput], **kwargs): | ||
| batch_outputs = [x for x in inp[0]] | ||
| generated_tokens = [x.generated_tokens for x in batch_outputs] | ||
| generated_logits = [x.generated_logits for x in batch_outputs] | ||
| finished_reason = [x.finished_reason for x in batch_outputs] | ||
|
|
||
| max_len = max(token.shape[1] for token in generated_tokens) | ||
|
|
||
| # pad all tokens to the same length | ||
| tokens = [ | ||
| pad_to_fixed_length( | ||
| array=prediction, | ||
| max_len=max_len, | ||
| value=self.tokenizer.pad_token_id, | ||
| axis=1, | ||
| ) | ||
| for prediction in generated_tokens | ||
| ] | ||
|
|
||
| # find the longest sequence in the batch of logits | ||
| max_len = max(logits.shape[1] for logits in generated_logits) | ||
|
|
||
| # pad all logits to the same length | ||
| logits = [ | ||
| pad_to_fixed_length(array=single_logits, max_len=max_len, axis=1) | ||
| for single_logits in generated_logits | ||
| ] | ||
|
|
||
| tokens = numpy.concatenate(tokens) | ||
| logits = numpy.concatenate(logits) | ||
|
|
||
| return { | ||
| "generated_tokens": tokens, | ||
| "generated_logits": logits, | ||
| "finished_reason": finished_reason, | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.