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

[Test Framework] Add test scripts for serve.py #92

Merged
merged 18 commits into from
Mar 18, 2024
1 change: 0 additions & 1 deletion .github/workflows/workflow_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
ci_type:
type: string
default: 'pr'

xwu99 marked this conversation as resolved.
Show resolved Hide resolved
jobs:
bare-test:

Expand Down
139 changes: 139 additions & 0 deletions tests/inference/test_serve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import subprocess
import pytest

# Config matrix
# config_file_array = ["inference/models/gpt2.yaml", None]
# model_id_or_path_array = ["gpt2", None]
# models_array = ["gpt2", "gpt2 gpt-j-6b", "gpt2 bloom-560m falcon-7b"]
# port_array = [8000, None]
# route_prefix_array = [None]
# cpus_per_worker_array = [24, None]
# gpus_per_worker_array = [0, None]
# hpus_per_worker_array = [0, None]
# deepspeed_array = [True, False]
# workers_per_group_array = [2, None]
# ipex_array = [True, False]
# device_array = ["cpu", None]
# serve_local_only_array = [True, False]
# simple_array = [True, False]
# keep_serve_termimal_array = [True, False]

# Temp Config matrix
config_file_array = ["inference/models/gpt2.yaml"]
model_id_or_path_array = ["gpt2"]
models_array = ["gpt2"]
port_array = [8000]
route_prefix_array = [None]
cpus_per_worker_array = [24]
gpus_per_worker_array = [0]
hpus_per_worker_array = [0]
deepspeed_array = [False]
workers_per_group_array = [None]
ipex_array = [False]
device_array = ["cpu"]
serve_local_only_array = [False]
simple_array = [False]
keep_serve_termimal_array = [False]


# Parametrize the test function with different combinations of parameters
@pytest.mark.parametrize(
"config_file, model_id_or_path, models, port, route_prefix, cpus_per_worker, gpus_per_worker, hpus_per_worker, deepspeed, workers_per_group, ipex, device, serve_local_only, simple, keep_serve_termimal",
[
(
config_file,
model_id_or_path,
models,
port,
route_prefix,
cpus_per_worker,
gpus_per_worker,
hpus_per_worker,
deepspeed,
workers_per_group,
ipex,
device,
serve_local_only,
simple,
keep_serve_termimal,
)
for config_file in config_file_array
for model_id_or_path in model_id_or_path_array
for models in models_array
for port in port_array
for route_prefix in route_prefix_array
for cpus_per_worker in cpus_per_worker_array
for gpus_per_worker in gpus_per_worker_array
for hpus_per_worker in hpus_per_worker_array
for deepspeed in deepspeed_array
for workers_per_group in workers_per_group_array
for ipex in ipex_array
for device in device_array
for serve_local_only in serve_local_only_array
for simple in simple_array
for keep_serve_termimal in keep_serve_termimal_array
],
)
def test_script(
config_file,
model_id_or_path,
models,
port,
route_prefix,
cpus_per_worker,
gpus_per_worker,
hpus_per_worker,
deepspeed,
workers_per_group,
ipex,
device,
serve_local_only,
simple,
keep_serve_termimal,
):
cmd_serve = ["python", "../inference/serve.py"]
if config_file is not None:
cmd_serve.append("--config_file")
cmd_serve.append(str(config_file))
if model_id_or_path is not None:
cmd_serve.append("--model_id_or_path")
cmd_serve.append(str(model_id_or_path))
if models is not None:
cmd_serve.append("--models")
cmd_serve.append(str(models))
if port is not None:
cmd_serve.append("--port")
cmd_serve.append(str(port))
if route_prefix is not None:
cmd_serve.append("--route_prefix")
cmd_serve.append(str(route_prefix))
if cpus_per_worker is not None:
cmd_serve.append("--cpus_per_worker")
cmd_serve.append(str(cpus_per_worker))
if gpus_per_worker is not None:
cmd_serve.append("--gpus_per_worker")
cmd_serve.append(str(gpus_per_worker))
if hpus_per_worker is not None:
cmd_serve.append("--hpus_per_worker")
cmd_serve.append(str(hpus_per_worker))
if deepspeed:
cmd_serve.append("--deepspeed")
if workers_per_group is not None:
cmd_serve.append("--workers_per_group")
cmd_serve.append(str(workers_per_group))
if ipex:
cmd_serve.append("--ipex")
if device is not None:
cmd_serve.append("--device")
cmd_serve.append(str(device))
if serve_local_only:
cmd_serve.append("--serve_local_only")
if simple:
cmd_serve.append("--simple")
if keep_serve_termimal:
cmd_serve.append("--keep_serve_termimal")

result_serve = subprocess.run(cmd_serve, capture_output=True, text=True)

# TODO: Find a better way to assert the result, like checking processes etc.
xwu99 marked this conversation as resolved.
Show resolved Hide resolved
xwu99 marked this conversation as resolved.
Show resolved Hide resolved
assert "Error" not in result_serve.stderr
Loading