-
Notifications
You must be signed in to change notification settings - Fork 31
feat: Support sending additional outputs from vLLM inference #70
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
10a5b94
Add additional outputs and their input switches to auto complete
kthui 892f0d0
chore: Refactor generate function
kthui 58ee481
Add additional outputs to response
kthui 5e605ca
Add test for additional outputs
kthui f35e9c4
Add docs for additonal outputs
kthui e6e6404
chore: Unify vLLM test names
kthui 44edd6e
Switch to pytest
kthui 1773dea
pytest to dump additional outputs
kthui 29099df
Rename output_* to return_*
kthui 457eeaa
Return token ids instead of number of token ids
kthui 5e9b09f
Revert "Return token ids instead of number of token ids"
kthui dae3c13
Rename num_token_ids to num_output_tokens
kthui 2b531dd
Merge branch 'main' of github.com:triton-inference-server/vllm_backen…
kthui ccb3323
[chore] Fix pre-commit on utils/metrics.py
kthui 00aa413
[docs] Update targeted release version
kthui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 198 additions & 0 deletions
198
ci/L0_additional_outputs_vllm/additional_outputs_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
import json | ||
import unittest | ||
|
||
import numpy as np | ||
import tritonclient.grpc as grpcclient | ||
|
||
|
||
class InferTest(unittest.TestCase): | ||
_grpc_url = "localhost:8001" | ||
_model_name = "vllm_opt" | ||
_sampling_parameters = {"temperature": "0", "top_p": "1"} | ||
_prompt = "In this example," | ||
|
||
def _get_inputs( | ||
self, | ||
prompt, | ||
stream=True, | ||
sampling_parameters=None, | ||
output_finish_reason=None, | ||
output_cumulative_logprob=None, | ||
output_num_token_ids=None, | ||
): | ||
inputs = [] | ||
|
||
inputs.append(grpcclient.InferInput("text_input", [1], "BYTES")) | ||
inputs[-1].set_data_from_numpy( | ||
np.array([prompt.encode("utf-8")], dtype=np.object_) | ||
) | ||
|
||
inputs.append(grpcclient.InferInput("stream", [1], "BOOL")) | ||
inputs[-1].set_data_from_numpy(np.array([stream], dtype=bool)) | ||
|
||
if sampling_parameters is not None: | ||
inputs.append(grpcclient.InferInput("sampling_parameters", [1], "BYTES")) | ||
inputs[-1].set_data_from_numpy( | ||
np.array( | ||
[json.dumps(sampling_parameters).encode("utf-8")], dtype=np.object_ | ||
) | ||
) | ||
|
||
if output_finish_reason is not None: | ||
inputs.append(grpcclient.InferInput("output_finish_reason", [1], "BOOL")) | ||
inputs[-1].set_data_from_numpy(np.array([output_finish_reason], dtype=bool)) | ||
|
||
if output_cumulative_logprob is not None: | ||
inputs.append( | ||
grpcclient.InferInput("output_cumulative_logprob", [1], "BOOL") | ||
) | ||
inputs[-1].set_data_from_numpy( | ||
np.array([output_cumulative_logprob], dtype=bool) | ||
) | ||
|
||
if output_num_token_ids is not None: | ||
inputs.append(grpcclient.InferInput("output_num_token_ids", [1], "BOOL")) | ||
inputs[-1].set_data_from_numpy(np.array([output_num_token_ids], dtype=bool)) | ||
|
||
return inputs | ||
|
||
def _callback(self, result, error): | ||
self._responses.append({"result": result, "error": error}) | ||
|
||
def _llm_infer(self, inputs): | ||
self._responses = [] | ||
with grpcclient.InferenceServerClient(self._grpc_url) as client: | ||
client.start_stream(self._callback) | ||
client.async_stream_infer( | ||
self._model_name, inputs=inputs, parameters=self._sampling_parameters | ||
) | ||
client.stop_stream() | ||
self.assertGreater(len(self._responses), 0) | ||
|
||
def _assert_text_output_valid(self): | ||
text_output = "" | ||
for response in self._responses: | ||
result, error = response["result"], response["error"] | ||
self.assertIsNone(error) | ||
text_output += result.as_numpy(name="text_output")[0].decode("utf-8") | ||
self.assertGreater(len(text_output), 0, "output is empty") | ||
self.assertGreater(text_output.count(" "), 4, "output is not a sentence") | ||
|
||
def _assert_finish_reason(self, output_finish_reason): | ||
for i in range(len(self._responses)): | ||
result, error = self._responses[i]["result"], self._responses[i]["error"] | ||
self.assertIsNone(error) | ||
finish_reason_np = result.as_numpy(name="finish_reason") | ||
if output_finish_reason is None or output_finish_reason == False: | ||
self.assertIsNone(finish_reason_np) | ||
continue | ||
finish_reason = finish_reason_np[0].decode("utf-8") | ||
if i < len(self._responses) - 1: | ||
self.assertEqual(finish_reason, "None") | ||
else: | ||
self.assertEqual(finish_reason, "length") | ||
|
||
def _assert_cumulative_logprob(self, output_cumulative_logprob): | ||
prev_cumulative_logprob = 0.0 | ||
for response in self._responses: | ||
result, error = response["result"], response["error"] | ||
self.assertIsNone(error) | ||
cumulative_logprob_np = result.as_numpy(name="cumulative_logprob") | ||
if output_cumulative_logprob is None or output_cumulative_logprob == False: | ||
self.assertIsNone(cumulative_logprob_np) | ||
continue | ||
cumulative_logprob = cumulative_logprob_np[0].astype(float) | ||
self.assertNotEqual(cumulative_logprob, prev_cumulative_logprob) | ||
prev_cumulative_logprob = cumulative_logprob | ||
|
||
def _assert_num_token_ids(self, output_num_token_ids): | ||
for response in self._responses: | ||
result, error = response["result"], response["error"] | ||
self.assertIsNone(error) | ||
num_token_ids_np = result.as_numpy(name="num_token_ids") | ||
if output_num_token_ids is None or output_num_token_ids == False: | ||
self.assertIsNone(num_token_ids_np) | ||
continue | ||
num_token_ids = num_token_ids_np[0].astype(int) | ||
# TODO: vLLM may return token ids identical to the previous one when | ||
# streaming, for example: | ||
# | ||
# prev: None | ||
# curr: text=' the', token_ids=array('l', [5]) | ||
# | ||
# prev: text=' the', token_ids=array('l', [5, 1385]) | ||
# curr: text=' the term', token_ids=array('l', [5, 1385]) | ||
# | ||
# prev: text=' the term', token_ids=array('l', [5, 1385, 44]) | ||
# curr: text=' the term', token_ids=array('l', [5, 1385, 44]) | ||
# | ||
# prev: text=' the term', token_ids=array('l', [5, 1385, 44, 48]) | ||
# curr: text=' the term “', token_ids=array('l', [5, 1385, 44, 48]) | ||
# | ||
# If this is no longer the case in a future release, change the assert | ||
# to assertGreater(). | ||
self.assertGreaterEqual(num_token_ids, 0) | ||
|
||
def _assert_additional_outputs_valid( | ||
self, | ||
stream, | ||
output_finish_reason, | ||
output_cumulative_logprob, | ||
output_num_token_ids, | ||
): | ||
inputs = self._get_inputs( | ||
self._prompt, | ||
stream=stream, | ||
sampling_parameters=self._sampling_parameters, | ||
output_finish_reason=output_finish_reason, | ||
output_cumulative_logprob=output_cumulative_logprob, | ||
output_num_token_ids=output_num_token_ids, | ||
) | ||
self._llm_infer(inputs) | ||
self._assert_text_output_valid() | ||
self._assert_finish_reason(output_finish_reason) | ||
self._assert_cumulative_logprob(output_cumulative_logprob) | ||
self._assert_num_token_ids(output_num_token_ids) | ||
|
||
def test_additional_outputs(self): | ||
for stream in [True, False]: | ||
choices = [None, False, True] | ||
for output_finish_reason in choices: | ||
for output_cumulative_logprob in choices: | ||
for output_num_token_ids in choices: | ||
self._assert_additional_outputs_valid( | ||
stream, | ||
output_finish_reason, | ||
output_cumulative_logprob, | ||
output_num_token_ids, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/bash | ||
# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
export CUDA_VISIBLE_DEVICES=0 | ||
source ../common/util.sh | ||
|
||
pip3 install tritonclient[grpc] | ||
|
||
# Prepare Model | ||
rm -rf models vllm_baseline_output.pkl && mkdir -p models | ||
SAMPLE_MODELS_REPO="../../samples/model_repository" | ||
cp -r $SAMPLE_MODELS_REPO/vllm_model models/vllm_opt | ||
sed -i 's/"gpu_memory_utilization": 0.5/"gpu_memory_utilization": 0.3/' models/vllm_opt/1/model.json | ||
|
||
RET=0 | ||
|
||
# Infer Test | ||
CLIENT_LOG="vllm_opt.log" | ||
SERVER_LOG="vllm_opt.server.log" | ||
SERVER_ARGS="--model-repository=models" | ||
run_server | ||
if [ "$SERVER_PID" == "0" ]; then | ||
echo -e "\n***\n*** Failed to start $SERVER\n***" | ||
cat $SERVER_LOG | ||
exit 1 | ||
fi | ||
set +e | ||
python3 additional_outputs_test.py > $CLIENT_LOG 2>&1 | ||
if [ $? -ne 0 ]; then | ||
cat $CLIENT_LOG | ||
echo -e "\n***\n*** additional_outputs_test FAILED. \n***" | ||
RET=1 | ||
fi | ||
set -e | ||
kill $SERVER_PID | ||
wait $SERVER_PID | ||
|
||
if [ $RET -eq 0 ]; then | ||
echo -e "\n***\n*** Test Passed\n***" | ||
else | ||
echo -e "\n***\n*** Test FAILED\n***" | ||
fi | ||
exit $RET |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.