[feat] Add Vertex AI compatible prediction route for /generate (#3866)
This commit is contained in:
@@ -50,6 +50,7 @@ suites = {
|
||||
"test_hidden_states.py",
|
||||
"test_update_weights_from_disk.py",
|
||||
"test_update_weights_from_tensor.py",
|
||||
"test_vertex_endpoint.py",
|
||||
"test_vision_chunked_prefill.py",
|
||||
"test_vision_llm.py",
|
||||
"test_vision_openai_server.py",
|
||||
|
||||
52
test/srt/test_vertex_endpoint.py
Normal file
52
test/srt/test_vertex_endpoint.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
python3 -m unittest test_vertex_endpoint.TestVertexEndpoint.test_vertex_generate
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
import requests
|
||||
|
||||
from sglang.srt.utils import kill_process_tree
|
||||
from sglang.test.test_utils import (
|
||||
DEFAULT_SMALL_MODEL_NAME_FOR_TEST,
|
||||
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
||||
DEFAULT_URL_FOR_TEST,
|
||||
popen_launch_server,
|
||||
)
|
||||
|
||||
|
||||
class TestVertexEndpoint(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.model = DEFAULT_SMALL_MODEL_NAME_FOR_TEST
|
||||
cls.base_url = DEFAULT_URL_FOR_TEST
|
||||
cls.process = popen_launch_server(
|
||||
cls.model,
|
||||
cls.base_url,
|
||||
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
kill_process_tree(cls.process.pid)
|
||||
|
||||
def run_generate(self, parameters):
|
||||
data = {
|
||||
"instances": [
|
||||
{"text": "The capital of France is"},
|
||||
{"text": "The capital of China is"},
|
||||
],
|
||||
"parameters": parameters,
|
||||
}
|
||||
response = requests.post(self.base_url + "/vertex_generate", json=data)
|
||||
response_json = response.json()
|
||||
assert len(response_json["predictions"]) == len(data["instances"])
|
||||
return response_json
|
||||
|
||||
def test_vertex_generate(self):
|
||||
for parameters in [None, {"sampling_params": {"max_new_tokens": 4}}]:
|
||||
self.run_generate(parameters)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user