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

[RollingBatch] optimize rolling batch result #1372

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Changes from 1 commit
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
19 changes: 13 additions & 6 deletions engines/python/setup/djl_python/rolling_batch/rolling_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def __init__(self,
self.log_prob = log_prob
self.special_token = special_token

def __dict__(self):
output = {}
if self.id:
output["id"] = self.id
if self.text:
output["text"] = self.text
if self.log_prob:
output["log_prob"] = self.log_prob
if self.special_token:
output["special_token"] = self.special_token
return output


def _json_output_formatter(token: Token, first_token: bool, last_token: bool,
details: dict):
Expand Down Expand Up @@ -69,12 +81,7 @@ def _jsonlines_output_formatter(token: Token, first_token: bool,
:return: formatted output
"""
token_dict = token.__dict__
# backwards compatible to V5
final_dict = {
"token": token_dict,
"details": None,
"outputs": [token.text]
}
final_dict = {"token": token_dict}
if last_token and details:
final_dict["details"] = {
"finish_reason": details.get("finish_reason", None)
Expand Down