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

[Text Generation][Fix] Assert that tokens have the same shape on output #1143

Merged
merged 15 commits into from
Jul 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/deepsparse/transformers/pipelines/text_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,8 @@ def has_cache(self) -> bool:
"""
return self.multitoken_engine.kv_cache_enabled

@staticmethod
def join_engine_outputs(
batch_outputs: List[List[numpy.ndarray]], orig_batch_size: int
self, batch_outputs: List[List[numpy.ndarray]], orig_batch_size: int
) -> List[numpy.ndarray]:
"""
Takes a list of outputs (batches) from the engine
Expand All @@ -483,7 +482,22 @@ def join_engine_outputs(
:return: A list of joined outputs
"""
tokens, logits = zip(*batch_outputs)

# find the longest sequence in the batch of tokens
max_len = max([token.shape[1] for token in 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 tokens
]
tokens = numpy.concatenate(tokens, axis=0)

# find the longest sequence in the batch of logits
max_len = max([logits.shape[1] for logits in logits])
# pad all logits to the same length
Expand Down
Loading