Skip to content

Commit

Permalink
servve ci case
Browse files Browse the repository at this point in the history
  • Loading branch information
cyber-pioneer committed Jan 21, 2025
1 parent 0be8fe0 commit 3b4e708
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
18 changes: 8 additions & 10 deletions flagscale/runner/runner_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,14 @@ def _generate_run_script_serve(
f.write(f"\n")
f.write(f'cmd="{cmd}"\n')
f.write(f"\n")
if with_test:
f.write(f'bash -c "$cmd; sync" \n')
# TODO: need a option to control whether to append or overwrite the output file
# Now, it always appends to the output file
if background:
f.write(
f'nohup bash -c "$cmd; sync" >> {host_output_file} 2>&1 & echo $! > {host_pid_file}\n'
)
else:
# TODO: need a option to control whether to append or overwrite the output file
# Now, it always appends to the output file
if background:
f.write(
f'nohup bash -c "$cmd; sync" >> {host_output_file} 2>&1 & echo $! > {host_pid_file}\n'
)
else:
f.write(f'bash -c "$cmd; sync" >> {host_output_file} 2>&1\n')
f.write(f'bash -c "$cmd; sync" >> {host_output_file} 2>&1\n')
f.write("\n")
f.flush()
os.fsync(f.fileno())
Expand Down Expand Up @@ -139,6 +136,7 @@ def _generate_stop_script(config, host, node_rank):
after_stop = ""
with open(host_stop_script_file, "w") as f:
f.write("#!/bin/bash\n\n")
f.write("ray stop\n")
f.write("pkill -f 'python'\n")
f.write(f"{after_stop}\n")
f.flush()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ deploy:

service:
name: /generate
port: 8000
port: 6701
request:
names:
- prompt
Expand Down
19 changes: 19 additions & 0 deletions tests/functional_tests/test_cases/serve/build_dag/test_call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import unittest
import requests

class TestAPI(unittest.TestCase):
def test_generate_endpoint(self):
url = "http://127.0.0.1:6701/generate"
headers = {"Content-Type": "application/json", "accept": "application/json"}
test_data = {"prompt": "Introduce BAAI."}

response = requests.post(url, headers=headers, json=test_data)

self.assertEqual(response.status_code, 200,
f"Expected status code 200, got {response.status_code}. Response: {response.text}")

self.assertGreater(len(response.text), 0,
"Generated text should not be empty")

if __name__ == '__main__':
unittest.main()
2 changes: 2 additions & 0 deletions tests/scripts/functional_tests/test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ commands=(
"tests/scripts/functional_tests/test_model.sh --type hetero_train --model aquila"
# Add in the feature
# "tests/scripts/functional_tests/test_model.sh --type inference --model vllm"
# For serve
"tests/scripts/functional_tests/test_model.sh --type serve --model build_dag"
)

for cmd in "${commands[@]}"; do
Expand Down
23 changes: 13 additions & 10 deletions tests/scripts/functional_tests/test_model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ CONFIG_FILE="tests/scripts/functional_tests/config.yml"
test_model() {
local _type=$1
local _model=$2
echo "model====== ${_model}"
echo "test_model ------------- ${_type} ${_model}"
# Use parse_config.py to parse the YAML file with test type and test model
local _cases=$(python tests/scripts/functional_tests/parse_config.py --config $CONFIG_FILE --type $_type --model $_model)
echo "----_cases----- ${_cases}"
# Convert the parsed test cases to an array
IFS=' ' read -r -a _cases <<< "$_cases"

Expand All @@ -42,6 +39,10 @@ test_model() {

# Attempt to run the test 5 times
for attempt_i in {1..5}; do
if [ ${_type} = "serve" ] && [ ${attempt_i} -gt 1 ]; then
break
fi

wait_for_gpu

echo "---------"
Expand All @@ -55,22 +56,24 @@ test_model() {
fi

if [ ${_type} = "serve" ]; then
echo "serve in ===================== 1 "
# serve
echo "python run.py --config-path tests/functional_tests/test_cases/${_type}/${_model}/conf --config-name ${_case} action=test"
run_command "python run.py --config-path tests/functional_tests/test_cases/${_type}/${_model}/conf --config-name ${_case} action=test"
echo "python run.py --config-path tests/functional_tests/test_cases/${_type}/${_model}/conf --config-name ${_case} action=run"
run_command "python run.py --config-path tests/functional_tests/test_cases/${_type}/${_model}/conf --config-name ${_case} action=run"
if [ $? -ne 0 ]; then
echo "Test failed on attempt $attempt_i for case $_case."
exit 1
fi
echo "serve in ===================== 2 "
# call
run_command "python run.py --config-path tests/functional_tests/test_cases/${_type}/${_model}/conf --config-name ${_case} action=test"
sleep 2m
# call
echo "python tests/functional_tests/test_cases/${_type}/${_model}/test_call.py"
run_command "python tests/functional_tests/test_cases/${_type}/${_model}/test_call.py"
if [ $? -ne 0 ]; then
echo "Test failed on attempt $attempt_i for case $_case."
exit 1
fi

#clear
echo "python run.py --config-path tests/functional_tests/test_cases/${_type}/${_model}/conf --config-name ${_case} action=stop"
run_command "python run.py --config-path tests/functional_tests/test_cases/${_type}/${_model}/conf --config-name ${_case} action=stop"
else

run_command "python run.py --config-path tests/functional_tests/test_cases/${_type}/${_model}/conf --config-name ${_case} action=test"
Expand Down

0 comments on commit 3b4e708

Please sign in to comment.