-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[draft] Add foundation for llm rest endpoint tests #6369
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3d715f9
PoC of parsing request prompt and converting to Triton infer request
rmccorm4 d2a7fe1
Remove extra trace
rmccorm4 477a7f1
Add foundation for llm rest endpoint tests
rmccorm4 f01f02e
Start vllm proxy model
rmccorm4 6e733a9
Fix non decoupled case
rmccorm4 6ac24aa
Add generate endpoint
GuanLuo 76f7980
Enable streaming version
GuanLuo 6510570
Merge branch 'gluo-llm' of github.com:triton-inference-server/server …
rmccorm4 aa81059
Baisc test case
GuanLuo 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 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
__pycache__ | ||
tmp | ||
*.log | ||
test_results*.txt |
This file contains 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,91 @@ | ||
# Copyright 2022-2023, 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 triton_python_backend_utils as pb_utils | ||
import numpy as np | ||
|
||
|
||
class TritonPythonModel: | ||
def initialize(self, args): | ||
self.model_config = json.loads(args["model_config"]) | ||
self.decoupled = self.model_config.get("model_transaction_policy", {}).get( | ||
"decoupled" | ||
) | ||
print(f"{self.decoupled=}") | ||
|
||
def execute(self, requests): | ||
if self.decoupled: | ||
return self.exec_decoupled(requests) | ||
else: | ||
return self.exec(requests) | ||
|
||
def exec(self, requests): | ||
responses = [] | ||
for request in requests: | ||
params = json.loads(request.parameters()) | ||
rep_count = params["REPETITION"] if "REPETITION" in params else 1 | ||
|
||
input_np = pb_utils.get_input_tensor_by_name(request, "PROMPT").as_numpy() | ||
stream_np = pb_utils.get_input_tensor_by_name(request, "STREAM").as_numpy() | ||
stream = stream_np.flatten()[0] | ||
if stream: | ||
responses.append( | ||
pb_utils.InferenceResponse( | ||
error=pb_utils.TritonError( | ||
"STREAM only supported in decoupled mode" | ||
) | ||
) | ||
) | ||
else: | ||
out_tensor = pb_utils.Tensor("TEXT", np.repeat(input_np, rep_count, axis=1)) | ||
responses.append(pb_utils.InferenceResponse([out_tensor])) | ||
return responses | ||
|
||
def exec_decoupled(self, requests): | ||
for request in requests: | ||
params = json.loads(request.parameters()) | ||
rep_count = params["REPETITION"] if "REPETITION" in params else 1 | ||
|
||
sender = request.get_response_sender() | ||
input_np = pb_utils.get_input_tensor_by_name(request, "PROMPT").as_numpy() | ||
stream_np = pb_utils.get_input_tensor_by_name(request, "STREAM").as_numpy() | ||
out_tensor = pb_utils.Tensor("TEXT", input_np) | ||
response = pb_utils.InferenceResponse([out_tensor]) | ||
# If stream enabled, just send multiple copies of response | ||
# FIXME: Could split up response string into tokens, but this is simpler for now. | ||
stream = stream_np.flatten()[0] | ||
if stream: | ||
for _ in range(rep_count): | ||
sender.send(response) | ||
sender.send(None, flags=pb_utils.TRITONSERVER_RESPONSE_COMPLETE_FINAL) | ||
# If stream disabled, just send one response | ||
else: | ||
sender.send( | ||
response, flags=pb_utils.TRITONSERVER_RESPONSE_COMPLETE_FINAL | ||
) | ||
return None |
This file contains 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,62 @@ | ||
# Copyright 2023, 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. | ||
backend: "python" | ||
|
||
# Disabling batching in Triton, let vLLM handle the batching on its own. | ||
max_batch_size: 0 | ||
|
||
model_transaction_policy { | ||
decoupled: True | ||
} | ||
|
||
input [ | ||
{ | ||
name: "PROMPT" | ||
data_type: TYPE_STRING | ||
dims: [ 1, 1 ] | ||
}, | ||
{ | ||
name: "STREAM" | ||
data_type: TYPE_BOOL | ||
dims: [ 1, 1 ] | ||
} | ||
] | ||
|
||
output [ | ||
{ | ||
name: "TEXT" | ||
data_type: TYPE_STRING | ||
dims: [ 1, -1 ] | ||
} | ||
] | ||
|
||
# The usage of device is deferred to the vLLM engine | ||
instance_group [ | ||
{ | ||
count: 1 | ||
kind: KIND_MODEL | ||
} | ||
] |
This file contains 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,165 @@ | ||
#!/usr/bin/python3 | ||
# Copyright 2023, 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 sys | ||
|
||
sys.path.append("../common") | ||
|
||
import json | ||
import unittest | ||
|
||
import requests | ||
import test_util as tu | ||
|
||
|
||
class HttpTest(tu.TestResultCollector): | ||
def _get_infer_url(self, model_name, route): | ||
return f"http://localhost:8000/v2/models/{model_name}/{route}" | ||
|
||
# def _simple_infer(self, model_name, inputs, expected_outputs): | ||
# headers = {"Content-Type": "application/json"} | ||
# url = self._get_infer_url(model_name, "infer") | ||
# r = requests.post(url, data=json.dumps(inputs), headers=headers) | ||
# r.raise_for_status() | ||
|
||
# content = r.json() | ||
# print(content) | ||
|
||
# self.assertEqual(content["model_name"], model_name) | ||
# self.assertIn("outputs", content) | ||
# self.assertEqual(content["outputs"], expected_outputs) | ||
|
||
# def _simple_generate_stream(self, model_name, inputs, expected_outputs): | ||
# import sseclient | ||
|
||
# headers = {"Accept": "text/event-stream"} | ||
# url = self._get_infer_url(model_name, "generate_stream") | ||
# # stream=True used to indicate response can be iterated over | ||
# r = requests.post(url, data=json.dumps(inputs), headers=headers, stream=True) | ||
|
||
# # Validate SSE format | ||
# print(r.headers) | ||
# self.assertIn("Content-Type", r.headers) | ||
# # FIXME: Clarify correct header here. | ||
# # self.assertEqual(r.headers['Content-Type'], 'text/event-stream') | ||
# self.assertEqual(r.headers["Content-Type"], "text/event-stream; charset=utf-8") | ||
|
||
# # SSE format (data: []) is hard to parse, use helper library for simplicity | ||
# client = sseclient.SSEClient(r) | ||
# tokens = [] | ||
# for i, event in enumerate(client.events()): | ||
# # End of event stream | ||
# if event.data == "[DONE]": | ||
# continue | ||
|
||
# # Parse event data, join events into a single response | ||
# data = json.loads(event.data) | ||
# print(f"Event {i}:", data) | ||
# if "TEXT" not in data: | ||
# print("FIXME: EXPECTED OUTPUT FIELD NOT FOUND") | ||
# else: | ||
# tokens.append(data["TEXT"]) | ||
# print("TOKENS:", tokens) | ||
|
||
# def test_infer(self): | ||
# model_name = "onnx_zero_1_object" | ||
# parameters = {} | ||
|
||
# # Setup text-based input | ||
# input0_data = ["hello"] | ||
# input0 = { | ||
# "name": "INPUT0", | ||
# "datatype": "BYTES", | ||
# "shape": [1, 1], | ||
# "data": input0_data, | ||
# } | ||
# inputs = {"inputs": [input0], "parameters": parameters} | ||
# # Identity model, output should match input | ||
# expected_outputs = [ | ||
# { | ||
# "name": "OUTPUT0", | ||
# "datatype": "BYTES", | ||
# "shape": [1, 1], | ||
# "data": input0_data, | ||
# } | ||
# ] | ||
# self._simple_infer(model_name, inputs, expected_outputs) | ||
|
||
def test_generate(self): | ||
model_name = "vllm_proxy" | ||
# Setup text-based input | ||
text = "hello world" | ||
inputs = {"PROMPT": [text], "STREAM": False} | ||
|
||
url = self._get_infer_url(model_name, "generate") | ||
# stream=True used to indicate response can be iterated over | ||
r = requests.post(url, data=json.dumps(inputs)) | ||
|
||
r.raise_for_status() | ||
|
||
self.assertIn("Content-Type", r.headers) | ||
self.assertIn("application/json", r.headers["Content-Type"]) | ||
|
||
data = r.json() | ||
self.assertTrue("TEXT" in data) | ||
Check notice Code scanning / CodeQL Imprecise assert
assertTrue(a in b) cannot provide an informative message. Using assertIn(a, b) instead will give more informative messages.
|
||
self.assertEqual(text, data["TEXT"]) | ||
|
||
def test_generate_stream(self): | ||
model_name = "vllm_proxy" | ||
# Setup text-based input | ||
text = "hello world" | ||
rep_count = 3 | ||
inputs = {"PROMPT": [text], "STREAM": True, "REPETITION": rep_count} | ||
|
||
import sseclient | ||
|
||
headers = {"Accept": "text/event-stream"} | ||
url = self._get_infer_url(model_name, "generate_stream") | ||
# stream=True used to indicate response can be iterated over | ||
r = requests.post(url, data=json.dumps(inputs), headers=headers, stream=True) | ||
|
||
r.raise_for_status() | ||
|
||
# Validate SSE format | ||
self.assertIn("Content-Type", r.headers) | ||
self.assertIn("text/event-stream", r.headers["Content-Type"]) | ||
|
||
# SSE format (data: []) is hard to parse, use helper library for simplicity | ||
client = sseclient.SSEClient(r) | ||
res_count = 0 | ||
for i, event in enumerate(client.events()): | ||
# Parse event data, join events into a single response | ||
data = json.loads(event.data) | ||
print(f"Event {i}:", data) | ||
self.assertTrue("TEXT" in data) | ||
Check notice Code scanning / CodeQL Imprecise assert
assertTrue(a in b) cannot provide an informative message. Using assertIn(a, b) instead will give more informative messages.
|
||
self.assertEqual(text, data["TEXT"]) | ||
res_count += 1 | ||
self.assertTrue(rep_count, res_count) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains 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
This file contains 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.
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.
Check notice
Code scanning / CodeQL
Commented-out code