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

[shortfin][python] Skip tokenization in sd.server if request holds input_ids #842

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions shortfin/python/shortfin_apps/sd/components/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def from_batch(gen_req: GenerateReqInput, index: int) -> "InferenceExecRequest":
"steps",
"guidance_scale",
"seed",
"input_ids",
]
rec_inputs = {}
for item in gen_inputs:
Expand Down
15 changes: 9 additions & 6 deletions shortfin/python/shortfin_apps/sd/components/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,15 @@ async def _prepare(self, device, requests):
# Tokenize prompts and negative prompts. We tokenize in bs1 for now and join later.
input_ids_list = []
neg_ids_list = []
for tokenizer in self.service.tokenizers:
input_ids = tokenizer.encode(request.prompt)
input_ids_list.append(input_ids)
neg_ids = tokenizer.encode(request.neg_prompt)
neg_ids_list.append(neg_ids)
ids_list = [*input_ids_list, *neg_ids_list]
ids_list = request.input_ids
# Tokenize the prompts if the request does not hold input_ids.
if ids_list is None:
for tokenizer in self.service.tokenizers:
input_ids = tokenizer.encode(request.prompt)
input_ids_list.append(input_ids)
neg_ids = tokenizer.encode(request.neg_prompt)
neg_ids_list.append(neg_ids)
ids_list = [*input_ids_list, *neg_ids_list]

request.input_ids = ids_list

Expand Down
Loading