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

Add optional argument original_output to vLLM's generate function #1212

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions outlines/models/vllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def generate(
*,
sampling_params: Optional["SamplingParams"] = None,
use_tqdm: bool = True,
original_output: bool = False,
):
"""Generate text using vLLM.

Expand All @@ -74,6 +75,9 @@ def generate(
vLLM documentation for more details: https://docs.vllm.ai/en/latest/dev/sampling_params.html.
use_tqdm
A boolean in order to display progress bar while inferencing
original_output
A boolean, if True then returns the original (full) output of the
vLLM model

Returns
-------
Expand All @@ -82,6 +86,8 @@ def generate(
this is a batch with several sequences but only one sample the list is
of shape `(n_batch)`. If there is only one sequence and one sample, a
string is returned.
If original_output is True, then this function returns the original
(full) output of the vLLM model.

"""
from vllm.sampling_params import SamplingParams
Expand Down Expand Up @@ -134,6 +140,10 @@ def generate(
lora_request=self.lora_request,
use_tqdm=use_tqdm,
)

if original_output:
return results
Comment on lines +144 to +145
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part won't pass coverage checks because it isn't tested. Could you add a test here: https://github.com/dottxt-ai/outlines/blob/main/tests/generate/test_integration_vllm.py

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay just pushed the integration tests


results = [[sample.text for sample in batch.outputs] for batch in results]

batch_size = len(results)
Expand Down
17 changes: 17 additions & 0 deletions tests/generate/test_integration_vllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import torch
from pydantic import BaseModel, constr
from vllm.outputs import RequestOutput
from vllm.sampling_params import SamplingParams

import outlines.generate as generate
Expand Down Expand Up @@ -42,15 +43,31 @@ def test_vllm_generation_api(model, generator_type, params):
res = generator("test", stop_at=[".", "ab"])
assert isinstance(res, str)

res = generator("test", original_output=True)
assert isinstance(res, list)
assert len(res) == 1
assert isinstance(res[0], RequestOutput)

res1 = generator("test", seed=1)
res2 = generator("test", seed=1)
assert isinstance(res1, str)
assert isinstance(res2, str)
assert res1 == res2

res1 = generator("test", seed=1, original_output=True)
res2 = generator("test", seed=1)
assert isinstance(res1[0], RequestOutput)
assert isinstance(res2, str)
text1 = [sample.text for sample in res1[0].outputs]
assert len(text1) == 1
assert text1[0] == res2

res = generator(["test", "test1"])
assert len(res) == 2

res = generator(["test", "test1"], original_output=True)
assert len(res) == 2


def test_vllm_sampling_params(model):
generator = generate.text(model)
Expand Down