Skip to content

Add a raw generate API to the vLLM server #3227

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 18 additions & 2 deletions trl/scripts/vllm_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,23 @@ async def generate(request: GenerateRequest):
{"completion_ids": [[101, 102, 103], [201, 202, 203]]}
```
"""
all_outputs = await generate_raw(request)
completion_ids = [list(output.token_ids) for outputs in all_outputs for output in outputs.outputs]
return {"completion_ids": completion_ids}

@app.post("/generate_raw/")
async def generate_raw(request: GenerateRequest):
"""
Generates completions for the provided prompts and returns the raw list of RequestOutput objects.

Args:
request (`GenerateRequest`):
- `prompts` (list of `str`): A list of prompts (text strings) for the model to generate completions.

Returns:
`list[RequestOutput]`:
- `completion_ids` (list of list of `int`): A list of lists of token IDs for each generated completion.
"""

# Guided decoding, if enabled
if request.guided_decoding_regex is not None:
Expand All @@ -342,8 +359,7 @@ async def generate(request: GenerateRequest):
guided_decoding=guided_decoding,
)
all_outputs = llm.generate(request.prompts, sampling_params=sampling_params)
completion_ids = [list(output.token_ids) for outputs in all_outputs for output in outputs.outputs]
return {"completion_ids": completion_ids}
return all_outputs

class InitCommunicatorRequest(BaseModel):
host: str
Expand Down