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

Fixing stream stopping at wrong location #898

Merged
merged 2 commits into from
May 17, 2024
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
28 changes: 19 additions & 9 deletions outlines/generate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,6 @@ def token_generator() -> Iterator[Union[List[str], str, List[List[str]]]]:
return
generated_token_ids = sequence.token_ids[:, -num_generated:]
generated_sequences = self.tokenizer.decode(generated_token_ids)
next_tokens = [
token[len(sequence) :] if not stop else ""
for token, sequence, stop in zip(
generated_sequences,
previously_generated_sequences,
is_stop_at_reached,
)
]
previously_generated_sequences = generated_sequences
if stop_sequences:
is_stop_at_reached = [
stop
Expand All @@ -360,6 +351,25 @@ def token_generator() -> Iterator[Union[List[str], str, List[List[str]]]]:
)
]

generated_sequences = [
self.format_sequence(
self.strip_stop_sequences(sequence, stop_sequences)
)
if stop
else sequence
for sequence, stop in zip(
generated_sequences, is_stop_at_reached
)
]
next_tokens = [
token[len(sequence) :]
for token, sequence, stop in zip(
generated_sequences,
previously_generated_sequences,
is_stop_at_reached,
)
]
previously_generated_sequences = generated_sequences
# We reshape the output to (batch_size, sample_size)
output: List[List[str]] = list()
for i in range(batch_size):
Expand Down
Loading