Skip to content

Commit

Permalink
add details info for streaming generation (#330)
Browse files Browse the repository at this point in the history
Co-authored-by: baishihao <[email protected]>
Co-authored-by: hiworldwzj <[email protected]>
  • Loading branch information
3 people authored Feb 18, 2024
1 parent b4541bd commit 7d48473
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lightllm/server/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ async def stream_results() -> AsyncGenerator[bytes, None]:
"id": metadata.get("id", None),
"text": request_output,
"logprob": metadata.get("logprob", None),
"special": False
"special": metadata.get("special", False),
"count_output_tokens": metadata.get("count_output_tokens", 0),
},
"generated_text": None,
"finished": finish_status.is_finished(),
Expand Down
3 changes: 3 additions & 0 deletions lightllm/server/detokenization/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(
self.send_to_httpserver.connect(f"tcp://127.0.0.1:{httpserver_port}")

self.tokenizer = get_tokenizer(model_weightdir, tokenizor_mode, trust_remote_code=trust_remote_code)
self.all_special_ids = set(self.tokenizer.all_special_ids)
self.req_id_to_out = {}

self.skip_special_tokens = skip_special_tokens
Expand All @@ -58,6 +59,8 @@ async def handle_loop(self):
continue
req_out:ReqDetokenizationState = self.req_id_to_out[req_id]
req_out.output_ids.append(new_token_id)
new_gen_metadata["special"] = new_token_id in self.all_special_ids
new_gen_metadata["count_output_tokens"] = len(req_out.output_ids)
req_out.gen_metadata.update(new_gen_metadata)

out_text = decode_token(
Expand Down

0 comments on commit 7d48473

Please sign in to comment.