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

[fix][lmi] validate token exists in streaming output formatters to ha… #2393

Merged
merged 1 commit into from
Sep 18, 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
12 changes: 12 additions & 0 deletions engines/python/setup/djl_python/output_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ def _jsonlines_output_formatter(request_output: TextGenerationOutput):
best_sequence = request_output.sequences[
request_output.best_sequence_index]
next_token, _, last_token = best_sequence.get_next_token()
# with chunked prefill, we don't generate any tokens until the full prompt has been processed.
# that means we sometimes don't have a token to return
if next_token is None:
return ""
token_dict = next_token.as_tgi_dict(
) if tgi_compat else next_token.as_dict()
final_dict = {"token": token_dict}
Expand All @@ -239,6 +243,10 @@ def _jsonlines_3p_output_formatter(request_output: TextGenerationOutput):
best_sequence = request_output.sequences[
request_output.best_sequence_index]
next_token, first_token, last_token = best_sequence.get_next_token()
# with chunked prefill, we don't generate any tokens until the full prompt has been processed.
# that means we sometimes don't have a token to return
if next_token is None:
return ""
token_details = next_token.as_dict()
body = {"generation": token_details["text"]}
num_prompt_tokens = len(
Expand Down Expand Up @@ -336,6 +344,10 @@ def _jsonlines_chat_output_formatter(request_output: TextGenerationOutput):
best_sequence = request_output.sequences[
request_output.best_sequence_index]
next_token, first_token, last_token = best_sequence.get_next_token()
# with chunked prefill, we don't generate any tokens until the full prompt has been processed.
# that means we sometimes don't have a token to return
if next_token is None:
return ""

created = int(time.time())
delta = {"content": next_token.text}
Expand Down
Loading